nightserver.py more work on cyberware
This commit is contained in:
parent
f579dd4c16
commit
573351760d
|
@ -24,7 +24,7 @@ def setVitalsHeartrate():
|
|||
vitalsHeartrate = json['heartrate']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { heartrate: INT, uuid: STRING }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
return '', 204
|
||||
|
||||
@app.route('/api/vitals/oxygen')
|
||||
def getVitalsOxygen():
|
||||
|
@ -42,7 +42,7 @@ def setVitalsOxygen():
|
|||
vitalsOxygen = json['oxygen']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { oxygen: INT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
return '', 204
|
||||
|
||||
@app.route('/api/vitals/bodytemp')
|
||||
def getVitalsBodytemp():
|
||||
|
@ -60,7 +60,7 @@ def setVitalsBodytemp():
|
|||
vitalsBodytemp = json['bodytemp']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { bodytemp: FLOAT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
return '', 204
|
||||
|
||||
@app.route('/api/vitals')
|
||||
def getVitals():
|
||||
|
@ -86,7 +86,7 @@ def setVitals():
|
|||
vitalsBodytemp = tempB
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { heartrate: INT, oxygen: INT, bodytemp: FLOAT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
return '', 204
|
||||
|
||||
# Fitness
|
||||
fitnessSteps = None
|
||||
|
@ -106,7 +106,7 @@ def setFitnessSteps():
|
|||
vitalsBodytemp = json['steps']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
return '', 204
|
||||
|
||||
|
||||
@app.route('/api/fitness')
|
||||
|
@ -125,12 +125,12 @@ def setFitness():
|
|||
fitnessSteps = json['steps']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
return '', 204
|
||||
|
||||
|
||||
# Cyberware management
|
||||
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.
|
||||
|
@ -161,7 +161,7 @@ def addCyberware():
|
|||
cyberware.append(tempNewCyberware)
|
||||
except:
|
||||
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 }
|
||||
@app.route('/api/cyberware/remove', methods=['POST'])
|
||||
|
@ -175,7 +175,7 @@ def removeCyberware():
|
|||
for c in cyberware:
|
||||
if c['uuid'] == desiredId:
|
||||
del cyberware[i]
|
||||
return 'Cyberware removed', 204
|
||||
return '', 204
|
||||
i = i + 1
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||
|
@ -194,30 +194,81 @@ def getCyberware():
|
|||
|
||||
#if not authenticate(json['uuid'], '/api/cyberware'):
|
||||
# return 'Forbidden.', 403
|
||||
r#eturn jsonify(cyberware)
|
||||
#return jsonify(cyberware)
|
||||
|
||||
@app.route('/api/cyberware/get')
|
||||
@app.route('/api/cyberware/get', methods=['POST'])
|
||||
def getCyberwareSpecific():
|
||||
json = request.get_json()
|
||||
|
||||
try:
|
||||
desiredId = json['uuid']
|
||||
i = 0
|
||||
for c in cyberware:
|
||||
if c['uuid'] == desiredId:
|
||||
return jsonify(c), 204
|
||||
break;
|
||||
|
||||
requestedCyberware = getCyberwareHelper(desiredId)
|
||||
|
||||
if (requestedCyberware != None):
|
||||
return jsonify(requestedCyberware), 200
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||
return 'UUID Invalid\n', 400
|
||||
|
||||
# Arguments { uuid: INT }
|
||||
@app.route('/api/cyberware/reset', methods=['POST'])
|
||||
def resetCyberwareMalfunction():
|
||||
#if not authenticate(json['uuid'], '/api/cyberware/reset'):
|
||||
# return 'Forbidden.', 403
|
||||
@app.route('/api/cyberware/battery')
|
||||
def getCyberwareBattery():
|
||||
json = request.get_json()
|
||||
|
||||
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
|
||||
environmentTemperature = None
|
||||
|
|
Loading…
Reference in a new issue