nightserver.py more work on cyberware
This commit is contained in:
parent
f579dd4c16
commit
573351760d
|
@ -24,7 +24,7 @@ def setVitalsHeartrate():
|
||||||
vitalsHeartrate = json['heartrate']
|
vitalsHeartrate = json['heartrate']
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { heartrate: INT, uuid: STRING }\n', 400
|
return 'Incorrect usage.\nUsage: { heartrate: INT, uuid: STRING }\n', 400
|
||||||
return 'Information set successfully', 204
|
return '', 204
|
||||||
|
|
||||||
@app.route('/api/vitals/oxygen')
|
@app.route('/api/vitals/oxygen')
|
||||||
def getVitalsOxygen():
|
def getVitalsOxygen():
|
||||||
|
@ -42,7 +42,7 @@ def setVitalsOxygen():
|
||||||
vitalsOxygen = json['oxygen']
|
vitalsOxygen = json['oxygen']
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { oxygen: INT }\n', 400
|
return 'Incorrect usage.\nUsage: { oxygen: INT }\n', 400
|
||||||
return 'Information set successfully', 204
|
return '', 204
|
||||||
|
|
||||||
@app.route('/api/vitals/bodytemp')
|
@app.route('/api/vitals/bodytemp')
|
||||||
def getVitalsBodytemp():
|
def getVitalsBodytemp():
|
||||||
|
@ -60,7 +60,7 @@ def setVitalsBodytemp():
|
||||||
vitalsBodytemp = json['bodytemp']
|
vitalsBodytemp = json['bodytemp']
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { bodytemp: FLOAT }\n', 400
|
return 'Incorrect usage.\nUsage: { bodytemp: FLOAT }\n', 400
|
||||||
return 'Information set successfully', 204
|
return '', 204
|
||||||
|
|
||||||
@app.route('/api/vitals')
|
@app.route('/api/vitals')
|
||||||
def getVitals():
|
def getVitals():
|
||||||
|
@ -78,7 +78,7 @@ def setVitals():
|
||||||
if not authenticate(json['uuid'], '/api/vitals'):
|
if not authenticate(json['uuid'], '/api/vitals'):
|
||||||
return 'Forbidden.', 403
|
return 'Forbidden.', 403
|
||||||
# This is a bit ugly but its just how I'm checking that everything is there without setting variables if the json is incorrect
|
# This is a bit ugly but its just how I'm checking that everything is there without setting variables if the json is incorrect
|
||||||
tempH = json['heartrate']
|
tempH = json['heartrate']
|
||||||
tempO = json['oxygen']
|
tempO = json['oxygen']
|
||||||
tempB = json['bodytemp']
|
tempB = json['bodytemp']
|
||||||
vitalsHeartrate = tempH
|
vitalsHeartrate = tempH
|
||||||
|
@ -86,7 +86,7 @@ def setVitals():
|
||||||
vitalsBodytemp = tempB
|
vitalsBodytemp = tempB
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { heartrate: INT, oxygen: INT, bodytemp: FLOAT }\n', 400
|
return 'Incorrect usage.\nUsage: { heartrate: INT, oxygen: INT, bodytemp: FLOAT }\n', 400
|
||||||
return 'Information set successfully', 204
|
return '', 204
|
||||||
|
|
||||||
# Fitness
|
# Fitness
|
||||||
fitnessSteps = None
|
fitnessSteps = None
|
||||||
|
@ -106,7 +106,7 @@ def setFitnessSteps():
|
||||||
vitalsBodytemp = json['steps']
|
vitalsBodytemp = json['steps']
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
||||||
return 'Information set successfully', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/fitness')
|
@app.route('/api/fitness')
|
||||||
|
@ -125,12 +125,12 @@ def setFitness():
|
||||||
fitnessSteps = json['steps']
|
fitnessSteps = json['steps']
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
||||||
return 'Information set successfully', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
# Cyberware management
|
# Cyberware management
|
||||||
cyberware = []
|
cyberware = []
|
||||||
newCyberwareTemplate = { "uuid": -1, "name": "", "hotpluggable": False, "lastMalfunction": "", "frontendAwknowledge": False, "canSet": [] }
|
newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "frontendAwknowledge": False, "canSet": [], "battery": None }
|
||||||
|
|
||||||
|
|
||||||
# This makes the system aware of a new piece of hardware.
|
# This makes the system aware of a new piece of hardware.
|
||||||
|
@ -161,7 +161,7 @@ def addCyberware():
|
||||||
cyberware.append(tempNewCyberware)
|
cyberware.append(tempNewCyberware)
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { name: STRING, hotpluggable: BOOL, canSet: ARRAY }\n', 400
|
return 'Incorrect usage.\nUsage: { name: STRING, hotpluggable: BOOL, canSet: ARRAY }\n', 400
|
||||||
return jsonify([ { "uuid": tempNewCyberware['uuid'] } ]), 204
|
return jsonify([ { "uuid": tempNewCyberware['uuid'] } ]), 200
|
||||||
|
|
||||||
# Arguments: { uuid: INT }
|
# Arguments: { uuid: INT }
|
||||||
@app.route('/api/cyberware/remove', methods=['POST'])
|
@app.route('/api/cyberware/remove', methods=['POST'])
|
||||||
|
@ -175,7 +175,7 @@ def removeCyberware():
|
||||||
for c in cyberware:
|
for c in cyberware:
|
||||||
if c['uuid'] == desiredId:
|
if c['uuid'] == desiredId:
|
||||||
del cyberware[i]
|
del cyberware[i]
|
||||||
return 'Cyberware removed', 204
|
return '', 204
|
||||||
i = i + 1
|
i = i + 1
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||||
|
@ -194,30 +194,81 @@ def getCyberware():
|
||||||
|
|
||||||
#if not authenticate(json['uuid'], '/api/cyberware'):
|
#if not authenticate(json['uuid'], '/api/cyberware'):
|
||||||
# return 'Forbidden.', 403
|
# return 'Forbidden.', 403
|
||||||
r#eturn jsonify(cyberware)
|
#return jsonify(cyberware)
|
||||||
|
|
||||||
@app.route('/api/cyberware/get')
|
@app.route('/api/cyberware/get', methods=['POST'])
|
||||||
def getCyberwareSpecific():
|
def getCyberwareSpecific():
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
desiredId = json['uuid']
|
desiredId = json['uuid']
|
||||||
i = 0
|
|
||||||
for c in cyberware:
|
requestedCyberware = getCyberwareHelper(desiredId)
|
||||||
if c['uuid'] == desiredId:
|
|
||||||
return jsonify(c), 204
|
if (requestedCyberware != None):
|
||||||
break;
|
return jsonify(requestedCyberware), 200
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||||
return 'UUID Invalid\n', 400
|
return 'UUID Invalid\n', 400
|
||||||
|
|
||||||
# Arguments { uuid: INT }
|
# Arguments { uuid: INT }
|
||||||
@app.route('/api/cyberware/reset', methods=['POST'])
|
@app.route('/api/cyberware/battery')
|
||||||
def resetCyberwareMalfunction():
|
def getCyberwareBattery():
|
||||||
#if not authenticate(json['uuid'], '/api/cyberware/reset'):
|
json = request.get_json()
|
||||||
# return 'Forbidden.', 403
|
|
||||||
|
|
||||||
return 'Not Implemented', 501
|
try:
|
||||||
|
desiredId = json['uuid']
|
||||||
|
|
||||||
|
requestedCyberware = getCyberwareHelper(desiredId)
|
||||||
|
|
||||||
|
if (requestedCyberware != None):
|
||||||
|
return jsonify([ { "battery": requestedCyberware['battery'] } ]), 200
|
||||||
|
except:
|
||||||
|
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||||
|
return 'UUID Invalid\n', 400
|
||||||
|
|
||||||
|
# Arguments { uuid: STRING, battery: INT }
|
||||||
|
@app.route('/api/cyberware/battery', methods=['POST'])
|
||||||
|
def setCyberwareBattery():
|
||||||
|
json = request.get_json()
|
||||||
|
|
||||||
|
try:
|
||||||
|
desiredId = json['uuid']
|
||||||
|
battery = json['battery']
|
||||||
|
|
||||||
|
requestedCyberware = getCyberwareHelper(desiredId)
|
||||||
|
|
||||||
|
if (requestedCyberware != None):
|
||||||
|
requestedCyberware['battery'] = battery
|
||||||
|
return '', 204
|
||||||
|
except:
|
||||||
|
return 'Incorrect usage.\nUsage: { battery: INT, uuid: STRING }\n', 400
|
||||||
|
return 'UUID Invalid\n', 400
|
||||||
|
|
||||||
|
# Arguments { uuid: STRING }
|
||||||
|
@app.route('/api/cyberware/reset_malfunction', methods=['POST'])
|
||||||
|
def resetCyberwareMalfunction():
|
||||||
|
json = request.get_json()
|
||||||
|
|
||||||
|
try:
|
||||||
|
desiredId = json['uuid']
|
||||||
|
|
||||||
|
requestedCyberware = getCyberwareHelper(desiredId)
|
||||||
|
|
||||||
|
if (requestedCyberware != None):
|
||||||
|
requestedCyberware['lastMalfunction'] = None
|
||||||
|
return '', 204
|
||||||
|
except:
|
||||||
|
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||||
|
return 'UUID Invalid\n', 400
|
||||||
|
|
||||||
|
def getCyberwareHelper(uuid):
|
||||||
|
i = 0
|
||||||
|
for c in cyberware:
|
||||||
|
if c['uuid'] == desiredId:
|
||||||
|
return c
|
||||||
|
break
|
||||||
|
return None
|
||||||
|
|
||||||
# Environment data
|
# Environment data
|
||||||
environmentTemperature = None
|
environmentTemperature = None
|
||||||
|
@ -255,7 +306,7 @@ def getEnvironmentHumidity():
|
||||||
|
|
||||||
@app.route('/api/environment/humidity', methods=['POST'])
|
@app.route('/api/environment/humidity', methods=['POST'])
|
||||||
def setEnvironmentHumidity():
|
def setEnvironmentHumidity():
|
||||||
global environmentHumidity
|
global environmentHumidity
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -280,7 +331,7 @@ def authenticate(uuid, endpoint):
|
||||||
if e == endpoint:
|
if e == endpoint:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def uiindex():
|
def uiindex():
|
||||||
|
|
Loading…
Reference in a new issue