@@ -118,11 +118,29 @@ def parse_message_from_file(messageID, filename = None):
118118 return result_dict
119119
120120def parse_message_from_buffer (messageID , buffer ):
121- if messageID != data .SYSSTAT_Payload .message_id :
122- msg = data .getMessageWithID (messageID )
121+
122+ def add_time (ret ):
123+ return append_fields (ret , 'gpstime' , ret ['time_of_week_sec' ] + 1e-6 * ret ['time_of_week_usec' ], usemask = False )
124+
125+ msg = getMessageWithID (messageID )
126+ if not msg or get_item_len (msg ) == 0 :
127+ print ('ignored' )
128+ return None
129+
130+ if messageID != SYSSTAT_Payload .message_id :
123131 dtype = np .dtype (msg .get_numpy_dtype ())
124- ret = np .frombuffer (buffer .getbuffer (), dtype )
125- ret = append_fields (ret , 'gpstime' , ret ['time_of_week_sec' ] + 1e-6 * ret ['time_of_week_usec' ], usemask = False )
126- return ret
132+ nlen = int (np .floor (len (buffer .getbuffer ())/ dtype .itemsize ))
133+ return add_time (np .frombuffer (buffer .getbuffer (), dtype ,count = nlen ))
127134 else :
128- return None
135+ def iterate (buffer ):
136+ start = 0
137+ while True :
138+ try :
139+ current = buffer .getbuffer ()[start :]
140+ msg .from_bytes (current )
141+ dtype = msg .get_numpy_dtype ()
142+ start += msg .header .msgLength
143+ yield add_time (np .frombuffer (current , dtype , count = 1 ))
144+ except :
145+ return
146+ return list (iterate (buffer ))
0 commit comments