-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadc_server.py
More file actions
69 lines (62 loc) · 2.17 KB
/
adc_server.py
File metadata and controls
69 lines (62 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Cherrypy Web server for WebGL data display
# Copyright (c) Jeremy P Bentham 2021. See http://iosoft.blog for details
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# v0.01 JPB 11/1/21 First release
import os, os.path, random, string, math, cherrypy
portnum = 8080
fifo_name = "/tmp/adc.fifo"
ymax = 2.0
npoints = 10000
nchans = 2
nresults = 0
directory = os.getcwd()
# Oscilloscope-type ADC data display
class Grapher(object):
# Index: show oscilloscope display
@cherrypy.expose
def index(self):
return cherrypy.lib.static.serve_file(directory + "/webgl_graph.html")
# Simulated data source
@cherrypy.expose
def sim(self):
global nresults
cherrypy.response.headers['Content-Type'] = 'text/plain'
data = npoints * [0]
for c in range(0, npoints, nchans):
data[c] = (math.sin((nresults*2 + c) / 20.0) + 1.2) * ymax / 4.0
if nchans > 1:
data[c+1] = (math.cos((nresults*2 + c) / 200.0) + 0.8) * data[c]
data[c+1] += random.random() / 4.0
nresults += 1
rsp = ",".join([("%1.3f" % d) for d in data])
return rsp
# FIFO data source
@cherrypy.expose
def fifo(self):
cherrypy.response.headers['Content-Type'] = 'text/plain'
try:
f = open(fifo_name, "r")
rsp = f.readline()
f.close()
except:
rsp = "No data"
return rsp
if __name__ == '__main__':
cherrypy.config.update({"server.socket_port": portnum, "server.socket_host": "0.0.0.0"})
conf = {
'/': {
'tools.staticdir.root': os.path.abspath(directory)
}
}
cherrypy.quickstart(Grapher(), '/', conf)