def control(): logger.debug("getRealtimeData called") try: samplerresponse = readadc.read() logger.info("getRealTimeData sampleresponse = " + str(samplerresponse)) temp = getTemperature.control() except IOError as e: status = 4 value = e logger.critical("%s %s", "Unable to get temperature", e) else: status = 0 value = temp[1] + '\x1E' + samplerresponse[0] + '\x1E' + samplerresponse[1] + '\x1E' + samplerresponse[2] + \ '\x1E' + samplerresponse[3] + '\x1E' + samplerresponse[4] + '\x1E' + samplerresponse[5] logger.debug("%s %s", "getRealtimeData returned value ", value) return status, value
def processor(self, buffer0): self.logger.debug("Interpreter was called.") if re.match("^[0-9a-zA-Z]{14}$", buffer0): # Matched Command with no parameters self.logger.debug("Matched command with no parameters") self.logger.debug("%s %s", "Current current response_command - ", self.response_command) self.logger.debug("%s %s", "Current current response_status - ", self.response_status) self.logger.debug("%s %s", "Current current response_value - ", self.response_value) self.logger.debug("%s %s", "Current current response_crc - ", self.response_crc) try: data = buffer0 self.logger.debug("%s %s", "Stripped control chars from packet ", repr(data)) except Exception as e: self.logger.debug("%s %s", "Unable to strip ctl chars from packet ", e) else: try: address, command, crc = struct.unpack('<2s8s4s', data.encode('utf-8')) command = command.decode('utf-8') address = address.decode('utf-8') self.logger.debug("%s %s %s %s", "Unpacked Staribus command", address, command, crc) except struct.error as e: self.logger.debug("%s %s", "Can not unpack command ", e) else: if int(staribuscrc.checkcrc(buffer0)) == 200: self.logger.debug("Packet failed crc check") self.x = 200, None else: if int(address) != int(self.config.get("instaddr", "iaddr")): # Check Instrument Address Is Correct self.logger.debug("Instrument address does not match our address") self.x = 80, None else: ########## Core Module ################# if re.match('00010000', command): # ping self.logger.debug("Matched command ping") self.x = ping.ping() elif re.match('000A0000', command): # getVersion self.logger.debug("Matched command getVersion") self.x = getVersion.control() elif re.match('000D0000', command): # getMACAddress self.logger.debug("Matched command getMACAddress") self.x = getMACAddress.control() elif re.match('000E0000', command): # getStatus self.logger.debug("Matched command getStatus") self.x = getStatus.control(self.response_command, self.response_status, self.response_crc) ############ Utilities Module ############ elif re.match('01010000', command): # getTemperature self.logger.debug("Matched command getTemperature") self.x = getTemperature.control() elif re.match('010D0000', command): # getClockDate self.logger.debug("Matched command getClockDate") self.x = getClockDate.control() elif re.match('01070000', command): # getHostname self.logger.debug("Matched command getHostname") self.x = getHostname.control() elif re.match('010E0000', command): # getClockTime self.logger.debug("Matched command getClockTime") self.x = getClockTime.control() ############# Data Capture Module ############ elif re.match('03000000', command): # getSpace self.logger.debug("Matched command getSpace") self.x = getSpace.control(self.data_array) elif re.match('03040000', command): # getRate return capture interval self.logger.debug("Matched command getRate") self.x = getRate.control() elif re.match('03020000', command): # getDataBlockCount self.logger.debug("Matched command getDataBlockCount") self.x = getDataBlockCount.control() ############ Logger Plugin ############ elif re.match('04000000', command): # getRealTimeData self.logger.debug("Matched command getRealTimeData") self.x = getRealtimeData.control() else: self.logger.debug("Matched command - NO MATCH") self.x = 20, None elif re.match("^[0-9a-zA-Z]{10}\x1F*(([0-9a-zA-Z]*)(\x1F)*)*", buffer0): # Matched Cmd with parameters self.logger.debug("Matched command with parameters") self.logger.debug("%s %s", "Current current response_command - ", self.response_command) self.logger.debug("%s %s", "Current current response_status - ", self.response_status) self.logger.debug("%s %s", "Current current response_value - ", self.response_value) self.logger.debug("%s %s", "Current current response_crc - ", self.response_crc) try: data = buffer0.split('\x1F') # Strip off ctrl characters and split on <us> self.logger.debug("%s %s", "Stripped control chars from packet", repr(data)) except Exception as e: self.logger.debug("%s %s", "Unable to strip ctl chars from packet ", e) else: try: address, command = struct.unpack('<2s8s', data[0].encode('utf-8')) # Unpack command command = command.decode('utf-8') address = address.decode('utf-8') self.logger.debug("%s %s %s", "Unpacked Staribus command", address, command) except struct.error as e: self.logger.debug("%s %s", "Can not unpack command ", e) else: if int(staribuscrc.checkcrc(buffer0)) == 200: # check crc self.logger.debug("Packet failed crc check") self.x = 200, None else: if int(address) != int(self.config.get("instaddr", "iaddr")): # Check Staribus Inst Address Is Correct self.logger.debug("Packet instrument address does not match our address") self.x = 80, None else: ############ Core Module ############ if re.match('00050000', command): # getConfigurationBlockCount self.logger.debug("Matched command getConfigurationBlockCount") self.x = getConfigurationBlockCount.control(data[1]) elif re.match('00060000', command): # getConfigurationBlock self.logger.debug("Matched command getConfigurationBlock") self.x = getConfigurationBlock.control(data[1], data[2], data[3]) elif re.match('00070000', command): # setConfigurationBlock self.logger.debug("Matched command setConfigurationBlock") self.x = setConfigurationBlock.control(data[1], data[2], data[3]) ############ Analogue Module ############# elif re.match('02000000', command): # getA2D self.logger.debug("Matched command getA2D") self.x = getA2D.control(data[1]) ############### DataCapture Module ############ elif re.match('03030000', command): # getDataBlock self.logger.debug("Matched command getDataBlock") self.x = getDataBlock.control(data[1]) elif re.match('03050000', command): # setRate set capture interval self.logger.debug("Matched command setRate") self.x = setRate.control(data[1]) elif re.match('03060000', command): # capture self.logger.debug("Matched command capture") self.x = capture.control(data[1], self.sampler) else: self.logger.debug("Matched command - NO MATCH") self.x = 20, None if (self.x[0] is not None) and (self.x[1] is not None): status = self.x[0] + self.sampler.status() self.response_status = str(status).zfill(4) self.response_value = str(self.x[1]) self.response_command = str(address) + str(command) joinvalue = self.response_command + str(self.response_status) + '\x1F' + str(self.response_value) + '\x1F' self.response_crc = str(staribuscrc.newcrc(joinvalue)) value = '\x02' + joinvalue + self.response_crc + '\x04\r\n' self.logger.debug("%s %s", "Created Return Message -", repr(value)) elif (self.x[0] is not None) and (self.x[1] is None): status = self.x[0] + self.sampler.status() self.response_status = str(status).zfill(4) self.response_command = str(address) + str(command) self.response_value = None joinvalue = self.response_command + str(self.response_status) self.response_crc = str(staribuscrc.newcrc(joinvalue)) value = '\x02' + joinvalue + self.response_crc + '\x04\r\n' self.logger.debug("%s %s", "Created Return Message -", repr(value)) else: status = 4 + self.sampler.status() self.response_status = str(status).zfill(4) self.response_command = str(address) + str(command) self.response_value = None joinvalue = self.response_command + str(self.response_status) self.response_crc = str(staribuscrc.newcrc(joinvalue)) value = '\x02' + joinvalue + self.response_crc + '\x04\r\n' self.logger.debug("%s %s", "Created Return Message -", repr(value)) return value
def processor(buffer0): global response_status global response_command global response_crc response_value = None logger.debug("Interpreter was called.") if re.match("^\x02*[0-9a-zA-Z]{14}\x04*", buffer0): # Matched Command with no parameters logger.debug("Matched command with no parameters") logger.debug("%s %s", "Current current response_command - ", response_command) logger.debug("%s %s", "Current current response_status - ", response_status) logger.debug("%s %s", "Current current response_value - ", response_value) logger.debug("%s %s", "Current current response_crc - ", response_crc) try: data = buffer0.strip('\x02\x1F\x04\r\n') logger.debug("%s %s", "Stripped control chars from packet ", repr(data)) except Exception as e: logger.debug("%s %s", "Unable to strip ctl chars from packet ", e) else: try: address, command, crc = struct.unpack('<2s8s4s', data) logger.debug("%s %s %s %s", "Unpacked Staribus command", address, command, crc) except struct.error as e: logger.debug("%s %s", "Can not unpack command ", e) else: if int(staribuscrc.checkcrc(buffer0)) == 0200: logger.debug("Packet failed crc check") x = 200, None else: if int(address) != int(config.get("instaddr", "iaddr")): # Check Instrument Address Is Correct logger.debug("Instrument address does not match our address") x = 80, None else: ########## Core Module ################# if re.match('00010000', command): # ping logger.debug("Matched command ping") x = ping.ping() elif re.match('000A0000', command): # getVersion logger.debug("Matched command getVersion") x = getVersion.control() elif re.match('000D0000', command): # getMACAddress logger.debug("Matched command getMACAddress") x = getMACAddress.control() elif re.match('000E0000', command): # getStatus logger.debug("Matched command getStatus") x = getStatus.control(response_command, response_status, response_crc) ############ Utilities Module ############ elif re.match('01010000', command): # getTemperature logger.debug("Matched command getTemperature") x = getTemperature.control() elif re.match('010D0000', command): # getClockDate logger.debug("Matched command getClockDate") x = getClockDate.control() elif re.match('01070000', command): # getHostname logger.debug("Matched command getHostname") x = getHostname.control() elif re.match('010E0000', command): # getClockTime logger.debug("Matched command getClockTime") x = getClockTime.control() ############# Data Capture Module ############ elif re.match('03000000', command): # getSpace logger.debug("Matched command getSpace") x = getSpace.control() elif re.match('03040000', command): # getRate return capture interval logger.debug("Matched command getRate") x = getRate.control() elif re.match('03020000', command): # getDataBlockCount logger.debug("Matched command getDataBlockCount") x = getDataBlockCount.control() ############# Publisher Module ############### elif re.match('05040000', command): # getPublisherLabels logger.debug("Matched command getPublisherLabels") x = getPublisherLabels.control() elif re.match('05030000', command): # getPublisher logger.debug("Matched command getPublisher") x = getPublisher.control() elif re.match('05060000', command): # getPublisherArtist logger.debug("Matched command getPublisherArtist") x = getPublisherArtist.control() elif re.match('06030000', command): # getDataPublisher logger.debug("Matched command getDataPublisher") x = getDataPublisher.control() ############ Logger Plugin ############ elif re.match('04000000', command): # getRealTimeData logger.debug("Matched command getRealTimeData") x = getRealtimeData.control() else: logger.debug("Matched command - NO MATCH") x = 20, None elif re.match("^\x02*[0-9a-zA-Z]{10}\x1F*(([0-9a-zA-Z]*)(\x1F)*)*\x04*", buffer0): # Matched Cmd with parameters logger.debug("Matched command with parameters") logger.debug("%s %s", "Current current response_command - ", response_command) logger.debug("%s %s", "Current current response_status - ", response_status) logger.debug("%s %s", "Current current response_value - ", response_value) logger.debug("%s %s", "Current current response_crc - ", response_crc) try: data = buffer0.strip('\x02\x1F\x03\x04\r\n').split('\x1F') # Strip off ctrl characters and split on <us> logger.debug("%s %s", "Stripped control chars from packet", repr(data)) except Exception as e: logger.debug("%s %s", "Unable to strip ctl chars from packet ", e) else: try: address, command = struct.unpack('<2s8s', data[0]) # Unpack command logger.debug("%s %s %s", "Unpacked Staribus command", address, command) except struct.error as e: logger.debug("%s %s", "Can not unpack command ", e) else: if int(staribuscrc.checkcrc(buffer0)) == 0200: # check crc logger.debug("Packet failed crc check") x = 200, None else: if int(address) != int(config.get("instaddr", "iaddr")): # Check Staribus Inst Address Is Correct logger.debug("Packet instrument address does not match our address") x = 80, None else: ############ Publisher Module ############ if re.match('05050000', command): # setPublisherLabels logger.debug("Matched command setPublisherLabels") x = setPublisherLabels.control(data[1], data[2], data[3]) elif re.match('05070000', command): # setPublisherArtist logger.debug("Matched command setPublisherArtist") x = setPublisherArtist.control(data[1], data[2], data[3], data[4], data[5], data[6]) elif re.match('05010000', command): # publisher logger.debug("Matched command publisher") x = capturePublisher.control(data[1]) elif re.match('05020000', command): # setPublisher logger.debug("Matched command setPublisher") x = setPublisher.control(data[1], data[2], data[3], data[4], data[5], data[6]) ############ Analogue Module ############# elif re.match('02000000', command): # getA2D logger.debug("Matched command getA2D") x = getA2D.control(data[1]) ############### DataCapture Module ############ elif re.match('03030000', command): # getDataBlock logger.debug("Matched command getDataBlock") x = getDataBlock.control(data[1]) elif re.match('03050000', command): # setRate set capture interval logger.debug("Matched command setRate") x = setRate.control(data[1]) elif re.match('03060000', command): # capture logger.debug("Matched command capture") x = capture.control(data[1]) elif re.match('06020000', command): # setDataPublisher logger.debug("Matched command setDataPublisher") x = setDataPublisher.control(data[1], data[2], data[3], data[4], data[5], data[6]) elif re.match('06010000', command): # dataPublisher logger.debug("Matched command dataPublisher") x = dataPublisher.control(data[1]) elif re.match('000F0000', command): # controllerControl logger.debug("Matched command controllerControl") x = controllerControl.control(data[1]) else: logger.debug("Matched command - NO MATCH") x = 20, None if (x[0] is not None) and (x[1] is not None): response_status = str(x[0]).zfill(4) response_value = str(x[1]) response_command = str(address) + str(command) joinvalue = response_command + str(response_status) + '\x1F' + str(response_value) + '\x1F' response_crc = str(staribuscrc.newcrc(joinvalue)) value = '\x02' + joinvalue + response_crc + '\x04\r\n' logger.debug("%s %s", "Created Return Message -", repr(value)) elif (x[0] is not None) and (x[1] is None): response_status = str(x[0]).zfill(4) response_command = str(address) + str(command) response_value = None joinvalue = response_command + str(response_status) response_crc = str(staribuscrc.newcrc(joinvalue)) value = '\x02' + joinvalue + response_crc + '\x04\r\n' logger.debug("%s %s", "Created Return Message -", repr(value)) else: status = 4 + samplerstatus.status() response_status = str(status).zfill(4) response_command = str(address) + str(command) response_value = None joinvalue = response_command + str(response_status) response_crc = str(staribuscrc.newcrc(joinvalue)) value = '\x02' + joinvalue + response_crc + '\x04\r\n' logger.debug("%s %s", "Created Return Message -", repr(value)) return value