salva valori min/max IN
This commit is contained in:
+56
-17
@@ -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):
|
||||
|
||||
+39
-29
@@ -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/<numCh>", 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")
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
@font-face {
|
||||
font-family: DsegSeven;
|
||||
src: url('DsegSeven.woff') format('woff');
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
<meta name="author" content="MarcoLoca" />
|
||||
<title>{{ title }}</title>
|
||||
<link rel="shortcut icon" href="../static/img/steam.ico">
|
||||
<link rel="stylesheet" href="../static/css/fonts.css">
|
||||
<link rel="stylesheet" href="../static/css/bootstrap.min.css">
|
||||
<script src="../static/js/jquery-3.6.0.min.js"></script>
|
||||
<script src="../static/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
+105
-17
@@ -4,6 +4,29 @@
|
||||
<main>
|
||||
<script>
|
||||
var intTime=1000;
|
||||
|
||||
function saveMin(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/saveInMin"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Min Set');
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
function saveMax(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/saveInMax"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Max Set');
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
</script>
|
||||
<div class="container-fluid py-2">
|
||||
<div class="card mb-4">
|
||||
@@ -25,13 +48,84 @@ var intTime=1000;
|
||||
</div>
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-table mr-1"></i>
|
||||
Channel 1 Settings
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<i class="fas fa-table mr-1"></i>
|
||||
Channel Setup
|
||||
</div>
|
||||
<div class="col-4 text-right">
|
||||
<label for="sel1">n°</label>
|
||||
</div>
|
||||
<div class="col-4 text-right">
|
||||
<div class="form-group">
|
||||
<select class="form-control" id="ddlChannels" onchange="setChannel(this)">
|
||||
<option>0</option>
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function setChannel(ddlChannels) {
|
||||
// fare vera funzione x salvare QUALE sia il canale attivo ins etup 8all'apertura va impostato 1...)
|
||||
var selectedText = ddlChannels.options[ddlChannels.selectedIndex].innerHTML;
|
||||
var selectedValue = ddlChannels.value;
|
||||
// alert("Selected Text: " + selectedText + " Value: " + selectedValue);
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/selectChannel/" + ddlChannels.value
|
||||
,data: ""
|
||||
// ,success: function(){
|
||||
// alert('Log Stopped');
|
||||
// }
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body text-center">
|
||||
<div class="row text-center">
|
||||
<div class="col-3"></div>
|
||||
<div class="col-6">
|
||||
<div class="row">
|
||||
<div class="col-4"><span id="ChanRealMin1"></span></div>
|
||||
<div class="col-4"><span id="Chan0"></span></div>
|
||||
<div class="col-4"><span id="ChanRealMax1"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3"></div>
|
||||
</div>
|
||||
<div class="row text-center">
|
||||
<div class="col-2">IN</div>
|
||||
<div class="col-8">
|
||||
<div class="row">
|
||||
<div class="col-4"><button type="button" class="btn btn-dark btn-block" onclick="saveMin()">Save Min</button></div>
|
||||
<div class="col-4">Current</div>
|
||||
<div class="col-4"><button type="button" class="btn btn-info btn-block" onclick="saveMax()">Save Max</button></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2"></div>
|
||||
</div>
|
||||
|
||||
<div class="row text-center mt-2">
|
||||
<div class="col-2">OUT</div>
|
||||
<form method="POST" action="/api/v1/scaleout">
|
||||
<div class="col-4">
|
||||
<input type="number" class="form-control" id="ScaleMin" name="ScaleMin"></input>
|
||||
</div>
|
||||
<div class="col-4">Scaled OUT</div>
|
||||
<div class="col-4">
|
||||
<input type="number" class="form-control" id="ScaleMax" name="ScaleMax"></input>
|
||||
</div>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="Invio" class="btn btn-success"></input>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- <div class="row">
|
||||
<div class="col-2 input-group mb-3 input-group-text">
|
||||
<strong>Valori reali (current: <span id="Chan0"></span> ) </strong>
|
||||
<strong>Save OUT</strong>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<form method="POST" action="/api/v1/rmin1">
|
||||
@@ -53,13 +147,13 @@ var intTime=1000;
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
</div> -->
|
||||
|
||||
<!-- <div class="row">
|
||||
<div class="col-2 input-group mb-3 input-group-text">
|
||||
<strong>Fattori di scala</strong>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<form method="POST" action="/api/v1/smin1">
|
||||
<form method="POST" action="/api/v1/scaleout">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Min: <span id="ChanScaleMin1"></span></span>
|
||||
<input type="number" class="form-control" id="ScaleMin1" name="ScaleMin1"></input>
|
||||
@@ -67,23 +161,17 @@ var intTime=1000;
|
||||
<input type="submit" value="SET" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<form method="POST" action="/api/v1/smax1">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Max: <span id="ChanScaleMax1"></span></span>
|
||||
<input type="number" class="form-control" id="caleMax1" name="ScaleMax1"></input>
|
||||
<input type="number" class="form-control" id="ScaleMax1" name="ScaleMax1"></input>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="SET" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user