diff --git a/logger/FlythisLogger.py b/logger/FlythisLogger.py index c51e3c9..fc43d83 100644 --- a/logger/FlythisLogger.py +++ b/logger/FlythisLogger.py @@ -14,21 +14,26 @@ redSrv0 = redis.Redis( port=REDIS_PORT, db=0) -#se non c'è un valore nei campi di redis, gli do 1 +#se non c'è un valore nei campi di redis, gli do 0 if redSrv0.get('SETTINGS:LOG:STATUS') is None: redSrv0.set('SETTINGS:LOG:STATUS',1) -if redSrv0.get('SETTINGS:CH:SCALE:MIN1') is None: - redSrv0.set('SETTINGS:CH:SCALE:MIN1',1) +if redSrv0.get('SETTINGS:SELECTED_CH') is None: + redSrv0.set('SETTINGS:SELECTED_CH',0) -if redSrv0.get('SETTINGS:CH:SCALE:MAX1') is None: - redSrv0.set('SETTINGS:CH:SCALE:MAX1',1) + for numCh in range(0,8,+1): -if redSrv0.get('SETTINGS:CH:REAL:MIN1') is None: - redSrv0.set('SETTINGS:CH:REAL:MIN1',1) + if redSrv0.get('SETTINGS:IN:MAX:'+str(numCh)) is None: + redSrv0.set('SETTINGS:IN:MAX:'+str(numCh),100) -if redSrv0.get('SETTINGS:CH:REAL:MAX1') is None: - redSrv0.set('SETTINGS:CH:REAL:MAX1',1) + if redSrv0.get('SETTINGS:IN:MIN:'+str(numCh)) is None: + redSrv0.set('SETTINGS:IN:MIN:'+str(numCh),0) + + if redSrv0.get('SETTINGS:OUT:MAX:'+str(numCh)) is None: + redSrv0.set('SETTINGS:OUT:MAX:'+str(numCh),100) + + if redSrv0.get('SETTINGS:OUT:MIN:'+str(numCh)) is None: + redSrv0.set('SETTINGS:OUT:MIN:'+str(numCh),0) #intervallo in millisecondi fra un campionamento e il successivo redSampleFreq = 'SETTINGS:LOG:FREQ' @@ -41,8 +46,8 @@ try: #funzione stampa otto valori letti su terminale def videoPrint(CHvalue): - for CHcount in range(0,8,+1): - print("CH "+str(CHcount)+"= %lf"%(CHvalue[CHcount]*5.0/0x7fffff)) + for chIndex in range(0,8,+1): + print("CH "+str(chIndex)+"= %lf"%(CHvalue[chIndex]*5.0/0x7fffff)) #funzione salva time+data e otto valori letti su file def fileSave(CHvalue): @@ -52,18 +57,52 @@ try: print("Creating new PyLog.txt") logFile = open("PyLog.txt", "w+") logFile.write("\nTime: "+str(now)) - for CHcount in range(0,8,+1): - logFile.write(" | CH "+str(CHcount)+" = %lf"%(CHvalue[CHcount]*5.0/0x7fffff)) + for chIndex in range(0,8,+1): + logFile.write(" | CH "+str(chIndex)+" = %lf"%(CHvalue[chIndex]*5.0/0x7fffff)) #funzione salva time+data di log e otto valori su redis def redisSave(CHvalue): redLastLog = 'RTDATA:TIME:LOG' lastLog = datetime.datetime.now() redSrv0.set(redLastLog,str(lastLog)) - for CHcount in range(0,8,+1): - redArea = 'RTDATA:CH:'+str(CHcount) - strVal = "%lf" % (CHvalue[CHcount]*5.0/0x7fffff) - redSrv0.set(redArea,strVal) + for chIndex in range(0,8,+1): + redAreaIn = 'RTDATA:CH:'+str(chIndex) + redAreaOut = 'RTDATA:OUT:'+str(chIndex) + strValIn = "%.4f" % (CHvalue[chIndex]*5.0/0x7fffff) + redSrv0.set(redAreaIn,strValIn) + # salvo i valori scalati in OUT + strValOut = "%.4f" % scaleVal(CHvalue[chIndex]*5.0/0x7fffff, chIndex) + redSrv0.set(redAreaOut,strValOut) + + #funzione di refresh valori scalati + def scaleVal(inValue, chIndex): + #rileggo da redis i valori min/max secondo chIndex + chInMin = float(0) + if (redSrv0.get('SETTINGS:IN:MIN:'+str(chIndex)) != 0): + chInMin = float(redSrv0.get('SETTINGS:IN:MIN:'+str(chIndex))) + + chInMax = float(3.3) + if (redSrv0.get('SETTINGS:IN:MAX:'+str(chIndex)) != 100): + chInMax = float(redSrv0.get('SETTINGS:IN:MAX:'+str(chIndex))) + + chOutMin = float(0) + if (redSrv0.get('SETTINGS:OUT:MIN:'+str(chIndex)) != 0): + chOutMin = float(redSrv0.get('SETTINGS:OUT:MIN:'+str(chIndex))) + + chOutMax = float(1000) + if (redSrv0.get('SETTINGS:OUT:MAX:'+str(chIndex)) != 100): + chOutMax = float(redSrv0.get('SETTINGS:OUT:MAX:'+str(chIndex))) + + # check denom zero + deltaOut = (chOutMax - chOutMin) + deltaIn = (chInMax - chInMin) + if(deltaIn==0): + deltaIn = 1 + + # calcolo scalato + outVal = chOutMin + ((inValue-chInMin) * (deltaOut / deltaIn)) + + return outVal #ciclo principale, salva time attuale e se LOG:STATUS è 1 fa il ciclo principale while(1): diff --git a/server/FlythisServer.py b/server/FlythisServer.py index 3927a3f..cb4c0ba 100644 --- a/server/FlythisServer.py +++ b/server/FlythisServer.py @@ -7,6 +7,8 @@ import redis import socket from werkzeug.utils import redirect + + #create a socket object s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -80,6 +82,7 @@ def about(): # definisco una NUOVA route a cui rispondere su chiamta in metodo GET x restituire dati aggiornati @flaskApp.route("/api/v1/channels/all", methods=['GET']) def api_channels_all(): + numCh = redSrv0.get('SETTINGS:SELECTED_CH').decode('utf-8') #funzione api_channels_all: legge direttamente da redis, ritorna jsonify channelsData = { 'timeSrv' : redSrv0.get('RTDATA:TIME:SRV').decode('utf-8'), @@ -93,10 +96,10 @@ def api_channels_all(): 'Ch5' : redSrv0.get('RTDATA:CH:5').decode('utf-8'), 'Ch6' : redSrv0.get('RTDATA:CH:6').decode('utf-8'), 'Ch7' : redSrv0.get('RTDATA:CH:7').decode('utf-8'), - 'ChScaleMax1' : redSrv0.get('SETTINGS:CH:SCALE:MAX1').decode('utf-8'), - 'ChScaleMin1' : redSrv0.get('SETTINGS:CH:SCALE:MIN1').decode('utf-8'), - 'ChRealMax1' : redSrv0.get('SETTINGS:CH:REAL:MAX1').decode('utf-8'), - 'ChRealMin1' : redSrv0.get('SETTINGS:CH:REAL:MIN1').decode('utf-8') + 'ChScaleMax' : redSrv0.get('SETTINGS:IN:MAX:'+str(numCh)).decode('utf-8'), + 'ChScaleMin' : redSrv0.get('SETTINGS:IN:MIN:'+str(numCh)).decode('utf-8'), + 'ChRealMax' : redSrv0.get('SETTINGS:OUT:MAX:'+str(numCh)).decode('utf-8'), + 'ChRealMin' : redSrv0.get('SETTINGS:OUT:MIN:'+str(numCh)).decode('utf-8') } # restituisce in formato json i dati letti da redis return jsonify(channelsData) @@ -114,6 +117,31 @@ def stop_log(): redSrv0.set('SETTINGS:LOG:STATUS', 0) return "OK" +@flaskApp.route("/api/v1/setup/saveInMin", methods=['PUT']) +def setupInMin(): + # devo leggere il channel attualmente selezionato + indCh = redSrv0.get('SETTINGS:SELECTED_CH').decode('utf-8') + currChVal = redSrv0.get('RTDATA:CH:'+ str(indCh)) + redSrv0.set('SETTINGS:IN:MIN:'+ str(indCh), currChVal) + return redirect("/settings") + +@flaskApp.route("/api/v1/setup/saveInMax", methods=['PUT']) +def setupInMax(): + # devo leggere il channel attualmente selezionato + indCh = redSrv0.get('SETTINGS:SELECTED_CH').decode('utf-8') + currChVal = redSrv0.get('RTDATA:CH:'+ str(indCh)) + redSrv0.set('SETTINGS:IN:MAX:'+ str(indCh), currChVal) + return redirect("/settings") + +@flaskApp.route("/api/v1/setup/selectChannel/", methods=['PUT']) +def selectChannel(numCh): + print(numCh) + # request_data = request.get_json() + # # devo leggere il channel attualmente selezionato, x ora cablo a 0... + # numCh = request_data['channel'] + redSrv0.set('SETTINGS:SELECTED_CH', numCh) + return "OK" + @flaskApp.route("/api/v1/sessions", methods=['POST']) def sessionCreate(): #funzione creazione sessione: scrive su redis SESSION:NAME prendendolo dall'input in pagina html con nome NewSessionName @@ -130,31 +158,13 @@ def setFrequency(): # rimando in settings return redirect("/settings") -@flaskApp.route("/api/v1/smin1", methods=['POST']) -def setScaleMin1(): - scaleMin1 = request.form['ScaleMin1'] - redSrv0.set('SETTINGS:CH:SCALE:MIN1', scaleMin1) - # rimando in settings - return redirect("/settings") - -@flaskApp.route("/api/v1/smax1", methods=['POST']) -def setScaleMax1(): - scaleMax1 = request.form['ScaleMax1'] - redSrv0.set('SETTINGS:CH:SCALE:MAX1', scaleMax1) - # rimando in settings - return redirect("/settings") - -@flaskApp.route("/api/v1/rmin1", methods=['POST']) -def setRealMin1(): - realMin1 = redSrv0.get('RTDATA:CH:0') - redSrv0.set('SETTINGS:CH:REAL:MIN1', realMin1) - # rimando in settings - return redirect("/settings") - -@flaskApp.route("/api/v1/rmax1", methods=['POST']) -def setRealMax1(): - realMax1 = redSrv0.get('RTDATA:CH:0') - redSrv0.set('SETTINGS:CH:REAL:MAX1', realMax1) +@flaskApp.route("/api/v1/scaleout", methods=['POST']) +def setScale(): + indexCh = redSrv0.get('SETTINGS:SELECTED_CH').decode('utf-8') + scaleMin = request.form['ScaleMin'] + redSrv0.set('SETTINGS:OUT:MIN:'+ str(indexCh), scaleMin) + scaleMax = request.form['ScaleMax'] + redSrv0.set('SETTINGS:OUT:MAX:'+ str(indexCh), scaleMax) # rimando in settings return redirect("/settings") diff --git a/server/static/css/DsegSeven.woff b/server/static/css/DsegSeven.woff deleted file mode 100644 index 89f8653..0000000 Binary files a/server/static/css/DsegSeven.woff and /dev/null differ diff --git a/server/static/css/fonts.css b/server/static/css/fonts.css deleted file mode 100644 index bd1a289..0000000 --- a/server/static/css/fonts.css +++ /dev/null @@ -1,4 +0,0 @@ -@font-face { - font-family: DsegSeven; - src: url('DsegSeven.woff') format('woff'); - } \ No newline at end of file diff --git a/server/templates/layout.html b/server/templates/layout.html index 2feb3a2..ea26f17 100644 --- a/server/templates/layout.html +++ b/server/templates/layout.html @@ -8,7 +8,6 @@ {{ title }} - diff --git a/server/templates/settings.html b/server/templates/settings.html index 5686853..9a6eda7 100644 --- a/server/templates/settings.html +++ b/server/templates/settings.html @@ -4,6 +4,29 @@
@@ -25,13 +48,84 @@ var intTime=1000;
- - Channel 1 Settings -
-
+
+ + Channel Setup +
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
IN
+
+
+
+
Current
+
+
+
+
+
+ +
+
OUT
+
+
+ +
+
Scaled OUT
+
+ +
+
+ +
+
+
+ + + +
-
{% endblock %} \ No newline at end of file