def test_readline(self): #outFile = open('ant-string-dump.txt','w') logging.debug('Reading fist time.') first = self.file.readline() self.assertIsInstance(first,dict); self.assertEqual(convertRawDataToHexString(first['packet']),\ 'A4 03 40 00 42 00 A5') self.assertEqual(first['timestamp'],0) #outFile.write(first+'\n') logging.debug('Reading second time:'+str(len(first))) second = self.file.readline() self.assertIsInstance(second,dict); self.assertEqual(convertRawDataToHexString(second['packet']),\ 'A4 03 40 00 51 00 B6') self.assertEqual(second['timestamp'],0) self.assertNotEqual(first,second) #outFile.write(second+'\n') while True: second = self.file.readline() if second == False: break; #outFile.write(second+'\n') self.assertIsInstance(second,dict);
def readline(self,size=0): """ Reads one sample from the file. """ event = self.reader.read() while (event != None): if event[0] == log.EVENT_READ: data = event[2] #logging.debug('========== [EVENT_READ:{0}] =========='.format(event[1])) #if logging.isEnabledFor(logging.debug): # length = 8 # while data: # row = data[:length] # data = data[length:] # hex_data = ['%02X' % ord(byte) for byte in row] # logging.debug('0x'+' '.join(hex_data)) logging.debug('TIMESTAMP:'+\ time.ctime(event[1])+\ ' : '+convertRawDataToHexString(data)) return {'packet':data,'timestamp':event[1]}; event = self.reader.read() if event == None: return False;