def parse_data(self): self.data = {} for filelog in self.finput: logging.info('Parsing "%s" file...', filelog) with open(filelog, 'rb') as csvfile: csvreader = csv.reader(csvfile, delimiter=',') for row in csvreader: # command, answer, valid, timestamp command, answer, valid, timestamp = row if valid == 'Y': value, unit = decode_answer(command, answer) d = { 'answer': value, 'timestamp': timestamp, } if command in self.data: self.data[command].append(d) else: self.data[command] = [d] else: # skip this invalid answer pass logging.info('Parsing done!')
def run(self): if self.connector is None: logging.error('You should connect to the port first.') sys.exit(1) print('INFORMATION FETCHED FROM THE CAR') print('--------------------------------\n\n') supported_pids = self.get_supported_pids() # use the supported commands to get some info for command in supported_pids: # do not run check (supported pids) commands if command in self.commands: continue result, validation = self.connector.run_OBD_command(command) if validation == 'Y': if self.lazy: value, unit = decode_answer(command, result) print( 'Command: {0}\nDescription: {1}\nValue: {2}\nUnit: {3}\n\n' .format(command, ELMdb[command]['description'], value, unit)) else: print('Command: {0}\nResult: {1}'.format(command, result)) else: logging.warning( 'Something wrong happened with "{0}" command'.format( command)) self.disconnect()
def run(self): if self.connector is None: logging.error('You should connect to the port first.') sys.exit(1) print('INFORMATION FETCHED FROM THE CAR') print('--------------------------------\n\n') supported_pids = self.get_supported_pids() # use the supported commands to get some info for command in supported_pids: # do not run check (supported pids) commands if command in self.commands: continue result, validation = self.connector.run_OBD_command(command) if validation == 'Y': if self.lazy: value, unit = decode_answer(command, result) print('Command: {0}\nDescription: {1}\nValue: {2}\nUnit: {3}\n\n' .format(command, ELMdb[command]['description'], value, unit)) else: print('Command: {0}\nResult: {1}'.format(command, result)) else: logging.warning('Something wrong happened with "{0}" command' .format(command)) self.disconnect()
def post(): global QUEUE data = json.loads(request.data) logging.info('Data received: "%s"', data) data['value'], data['unit'] = decode_answer( data['command'], data['answer']) logging.info('Data translated: "%s"', data) del data['answer'] QUEUE.put(data) return Response('OK\n')
def run(self): if self.connector is None: logging.error('You should connect to the port first.') sys.exit(1) logging.info('Launching Expert Mode console...') choice = '' valid_answers = ['Y', 'N'] while choice not in valid_answers: choice = raw_input(MSG_WARNING) if choice.upper() == 'Y': logging.warning(MSG_DISCLAIMER) print('Type "quit" or CTRL-C to exit') while self.keep_going is True: try: user_command = raw_input('ROOT@KT-OBD> ').upper() if re.search('\AAT', user_command): print('Wrong command, ELM configuration is not ' 'allowed') elif re.search('QUIT', user_command): raise KeyboardInterrupt elif user_command == '': pass else: result, validation = self.connector.run_OBD_command( user_command, expert=True) if re.search('ERROR', result) or \ re.search('DATA', result): print('ERROR: Wrong command or not supported, ' 'type another one') elif re.search('BUSY', result): print('ERROR: Bus busy, try again') elif re.search('UNABLE', result): print('ERROR: Communication lost, shutting ' 'down app!') break else: if self.lazy_mode: value, unit = decode_answer( user_command, result) print('{0} {1}'.format(value, unit)) else: print(result) except KeyboardInterrupt: break logging.info('Expert mode aborted by user, finishing...') self.connector.run_OBD_command('END', expert=True)
def get_supported_pids(self): if self.connector is None: logging.error('You should connect to the port first.') sys.exit(1) supported_pids = [] # check which commands are supported by this car for command in self.commands: result, validation = self.connector.run_OBD_command(command) if validation == 'Y': value, unit = decode_answer(command, result) supported_pids += self.check_supported_pids(value, command) return supported_pids
def parse_data(self): self.data = {} for filelog in self.finput: logging.info('Parsing "%s" file...', filelog) with open(filelog, "rb") as csvfile: csvreader = csv.reader(csvfile, delimiter=",") for row in csvreader: # command, answer, valid, timestamp command, answer, valid, timestamp = row if valid == "Y": value, unit = decode_answer(command, answer) d = {"answer": value, "timestamp": timestamp} if command in self.data: self.data[command].append(d) else: self.data[command] = [d] else: # skip this invalid answer pass logging.info("Parsing done!")