added general telemetry read query
@@ -18,28 +18,35 @@ MODULES = mcu_api.CONFIG_DATA['modules']
# Local subsystem instance for tracking state
# May not be neccesary when tied into actual hardware
-_command_count = 0#Subsystem(power_on=False)
+#_local = Subsystem(power_on=False)
class Query(graphene.ObjectType):
"""
Creates query endpoints exposed by graphene.
"""
-
+ class Arguments:
module = graphene.String()
- count = graphene.Int()
+ field = graphene.String()
- def read(self, info, module, count):
+ mcuTelemetry = graphene.Field(readData)
+
+ def resolve_mcuTelemetry(self, info, module, field):
"""
Handles request for subsystem query.
"""
if module not in MODULES:
- raise KeyError('Module not configured: ',module)
+ raise KeyError('Module not configured',module)
address = MODULES[module]['address']
+ if address == 0:
+ raise ValueError('Module not present',module)
+ if type(field) == unicode: field = str(field)
mcu = mcu_api.MCU(address = address)
- out = mcu.read(count = count)
+ out = mcu.get_module_telemetry(module = module,fields = [field])
- readData = ReadData(status = out[0], command = out[1])
+ readData = ReadData(
+ timestamp = out[field]['timestamp'],
+ data = out[field]['data'])
return readData
@@ -60,9 +67,11 @@ class CommandPassthrough(graphene.Mutation):
Handles passthrough commands to the Pumpkin MCU modules.
"""
if module not in MODULES:
- raise KeyError('Module not configured: ',module)
- if type(command) == unicode: command = str(command)
+ raise KeyError('Module not configured',module)
address = MODULES[module]['address']
+ if address == 0:
+ raise KeyError('Module not present',module)
+ if type(command) == unicode: command = str(command)
mcu = mcu_api.MCU(address = address)
out = mcu.write(command)
@@ -86,8 +95,10 @@ class ReadPassthrough(graphene.Mutation):
Handles request for subsystem query.
"""
if module not in MODULES:
- raise KeyError('Module not configured: ',module)
+ raise KeyError('Module not configured',module)
address = MODULES[module]['address']
+ if address == 0:
+ raise KeyError('Module not present',module)
mcu = mcu_api.MCU(address = address)
out = mcu.read(count = count)
@@ -95,7 +106,7 @@ class ReadPassthrough(graphene.Mutation):
timestamp = out['timestamp'],
data = out['data'])
- return commandStatus
+ return readData
class Mutation(graphene.ObjectType):
@@ -104,5 +115,6 @@ class Mutation(graphene.ObjectType):
"""
commandPassthrough = CommandPassthrough.Field()
+ readPassthrough = ReadPassthrough.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
