def _extract(self, data): """ Extract the data portion from the response """ checksum = data[-3:] calc_checksum = Protocol._checksum(data[:-3]) if checksum != calc_checksum: raise exceptions.InstrumentDataException('Invalid checksum on %s, calculated %s' % (data, calc_checksum)) return int(data[-9:-3])
def _generic_response_handler(self, resp, prompt): """ Parse the response from the turbopump. @param resp: response @param prompt: unused, require to match signature @returns: integer value extracted from response @throws InstrumentDataException """ my_checksum = self._checksum(resp[:-3]) if resp[-3:] != my_checksum: err_str = 'bad checksum: %r calculated: %r' % (resp, my_checksum) raise exceptions.InstrumentDataException(err_str) command = int(resp[5:8]) data_length = int(resp[8:10]) data = resp[10:-3] log.trace('command: %s data: %s', command, data) if len(data) != data_length: raise exceptions.InstrumentDataException('invalid data length: %r' % resp) if command not in InstrumentCommand.list(): raise exceptions.InstrumentDataException('command not found: %r' % resp) return int(data)