@@ -190,6 +190,8 @@ def monitor2xcom(argv = None):
190190 except ixcom .data .ParseError as e :
191191 frame_name = str (e ).split ('convert ' )[1 ]
192192 args .output .write (f'Corrupt { frame_name } frame\n \n ' )
193+ except SystemError :
194+ pass
193195
194196
195197def split_config (argv = None ):
@@ -213,26 +215,34 @@ def callback(msg_bytes):
213215 args .output .write (msg_bytes )
214216
215217 xcomparser .add_callback (callback )
216- xcomparser .process_bytes (args .inputfile . read () )
218+ xcomparser .process_file_handle (args .inputfile )
217219 sys .exit (0 )
218220 except Exception as ex :
219221 print (ex )
220222 sys .exit (1 )
221223
222224def remove_partial_msgs (argv = None ):
223225 parser = argparse .ArgumentParser (description = 'Removes Partial Messages from XCOMStream' )
224- parser .add_argument ('inputfile' , metavar = 'inputfile' , type = argparse .FileType ('rb' ), nargs = '?' ,
226+ parser .add_argument ('inputfile' , metavar = 'inputfile' , type = argparse .FileType ('rb' ),
225227 help = 'Name of the binary XCOMStream file' , default = 'XCOMStream.bin' )
226- parser .add_argument ('-o' , '--output' , metavar = 'output_filename' , type = argparse . FileType ( mode = 'wb' ),
228+ parser .add_argument ('-o' , '--output' ,
227229 help = 'Filename of the output file' , default = 'XCOMStream.clean.bin' )
228- args = parser .parse_args ()
230+ parser .add_argument ('-rimui' , '--remove_imu_invalid' ,action = "store_true" , help = 'Remove POSTPROC and RAWDATA msgs with IMU invalid status' )
231+ args = parser .parse_args (argv )
229232 xcomparser = ixcom .parser .MessageSearcher (disable_crc = False )
230233
231- iob = io .BytesIO (b'' )
234+ f = open (args .output ,"wb" , buffering = xcomparser .file_write_buffer_length )
235+
232236 def r_callback (in_bytes ):
233- iob .write (in_bytes )
237+ if args .remove_imu_invalid :
238+ if in_bytes [1 ]== 0x40 :#POSTPROC
239+ if in_bytes [216 ] & 0x01 :
240+ return
241+ if in_bytes [1 ]== 0x67 :#RAWDATA
242+ if in_bytes [80 ] & 0x01 :
243+ return
244+ f .write (in_bytes )
234245
235246 xcomparser .add_callback (r_callback )
236- xcomparser .process_bytes (args .inputfile .read ())
237- iob .seek (0 , os .SEEK_SET )
238- args .output .write (iob .read ())
247+ xcomparser .process_file_handle (args .inputfile )
248+ f .close ()
0 commit comments