import struct import scipy.io as spio import math line_buff = [] inv_dali_fix = [0.1835114759, -0.0139180047 ,0.0000104651 ,-0.0000001076] inv_dalo_fix = [0.0605854762, -0.0134594170, 0.0000014590, -0.0000005228] inv_dari_fix = [-0.0628936466, 0.0139820955, -0.0000013965, 0.0000000274] inv_daro_fix = [0.0760199848, 0.0140838792 ,-0.0000000214, -0.0000002133] inv_deli_fix = [0.0279715821 ,-0.0139882897 ,0.0000012014 ,0.0000000240] inv_delo_fix = [-0.1674419142 ,-0.0141767262, -0.0000105237 ,-0.0000001360] inv_deri_fix = [-0.0913878050 ,0.0140764858, -0.0000026448 ,0.0000000087] inv_dero_fix = [-0.0028181221, 0.0140918517 ,-0.0000062197, 0.0000000745] inv_dfli_fix = [0.1593846077 ,-0.0144023415, -0.0000012018 ,-0.0000006111] inv_dflo_fix = [0.0533200329, 0.0139748253 ,0.0000733247, -0.0000011213] inv_dfri_fix = [0.0165723758, 0.0139446481 ,0.0001093034, -0.0000022020] inv_dfro_fix = [0.1713424769, -0.0142385147, -0.0000310481, -0.0000022970] inv_dfali_fix = [0.1608325503, -0.0145932118 ,0.0000025537, -0.0000004630] inv_dfalo_fix = [0.0116635936 ,0.0145875729 ,0.0000099810, -0.0000001501] inv_dfari_fix = [0.3798064479, 0.0148503457 ,-0.0000142067, -0.0000004002] inv_dfaro_fix = [0.0384463888 ,-0.0143005142, 0.0000221575, 0.0000001764] def printline(txt): global line_buff line_buff.append(txt) if len(line_buff) >= 40: print(' '.join(line_buff)) line_buff.clear() def chksum(buff): s = 0 for i in buff: s = s+i return s % 256 def pwm2pos(pwm): if pwm > 0x1000: return 0 elif pwm > 0x7FF: return pwm - 4095 else: return pwm def act2deg_new(para): def wrap(p): x = p if p > 32767: x = p - 65536 x = x / 10 act =(para[0] + para[1] * x + para[2] * x * x + para[3] * x * x * x )*57.3 return act return wrap def parseHJ(filename): hj = open(filename, 'rb') pkgs = \ { 1: [struct.Struct('<2I2d24f3B'), [['boot_time',0.005,'时间戳',0], ['tick',0.005,'时间戳',0], ['lat_ins_inn',1,'内部惯导纬度(deg)',0], ['lon_ins_inn',1,'内部惯导经度(deg)',0], ['alt_ins_inn',1,'内部惯导高度(m)',0], ['phi_ins_inn',57.29,'内部惯导滚转角(deg)',0], ['tht_ins_inn',57.29,'内部惯导俯仰角(deg)',0], ['psi_ins_inn',57.29,'内部惯导偏航角(deg)',0], ['quad1',1,'四元数',0], ['quad2',1,'四元数',0], ['quad3',1,'四元数',0], ['quad4',1,'四元数',0], ['vn_ins_inn',1,'内部惯导北向速度(m/s)',0], ['ve_ins_inn',1,'内部惯导东向速度(m/s)',0], ['vu_ins_inn',-1,'内部惯导天向速度(m/s)',0], ['ax_ins_1',1,'主IMU前向加速度(m/s2)',0], ['ay_ins_1',1,'主IMU侧向加速度(m/s2)',0], ['az_ins_1',-1,'主IMU上向加速度(m/s2)',0], ['ax_ins_2',1,'副IMU前向加速度(m/s2)',0], ['ay_ins_2',1,'副IMU侧向加速度(m/s2)',0], ['az_ins_2',-1,'副IMU上向加速度(m/s2)',0], ['p_ins_1',57.29,'主IMU滚转角速度(deg/sec)',0], ['q_ins_1',57.29,'主IMU俯仰角速度(deg/sec)',0], ['r_ins_1',57.29,'主IMU偏航角速度(deg/sec)',0], ['p_ins_2',57.29,'副IMU滚转角速度(deg/sec)',0], ['q_ins_2',57.29,'副IMU俯仰角速度(deg/sec)',0], ['r_ins_2',57.29,'副IMU偏航角速度(deg/sec)',0], ['acc_g',1,'重力加速度(deg/sec)',0], ['fuse_vel_cnt',1,'速度组合计数',0], ['fuse_hdg_cnt',1,'航向组合计数',0], ['integrated_flag',1,'惯导组合状态',0], ], [], ], 2: [struct.Struct('<2I35f'), [['boot_time',0.005,'时间戳',0], ['tick',0.005,'时间戳',0], ['gyro_bias1',1,'gyro_bias',0], ['gyro_bias2',1,'gyro_bias',0], ['gyro_bias3',1,'gyro_bias',0], ['acc_bias1',1,'acc_bias',0], ['acc_bias2',1,'acc_bias',0], ['acc_bias3',1,'acc_bias',0], ['hdg_bias',1,'hdg_bias',0], ['euler_var1',1,'euler_var',0], ['euler_var2',1,'euler_var',0], ['euler_var3',1,'euler_var',0], ['vn_var',1,'vned_var',0], ['ve_var',1,'vned_var',0], ['vd_var',1,'vned_var',0], ['gyro_bias_var1',1,'gyro_bias_var',0], ['gyro_bias_var2',1,'gyro_bias_var',0], ['gyro_bias_var3',1,'gyro_bias_var',0], ['acc_bias_var1',1,'acc_bias_var',0], ['acc_bias_var2',1,'acc_bias_var',0], ['acc_bias_var3',1,'acc_bias_var',0], ['hdg_bias_var',1,'hdg_bias_var',0], ['vel_innov1',1,'vel_innov',0], ['vel_innov2',1,'vel_innov',0], ['vel_innov3',1,'vel_innov',0], ['vel_innov_var1',1,'vel_innov_var',0], ['vel_innov_var2',1,'vel_innov_var',0], ['vel_innov_var3',1,'vel_innov_var',0], ['pos_innov1',1,'pos_innov',0], ['pos_innov2',1,'pos_innov',0], ['pos_innov3',1,'pos_innov',0], ['pos_innov_var1',1,'pos_innov_var',0], ['pos_innov_var2',1,'pos_innov_var',0], ['pos_innov_var3',1,'pos_innov_var',0], ['LLA_var',1,'LLA_var',0], ['LLA_var',1,'LLA_var',0], ['LLA_var',1,'LLA_var',0], ], [], ], 3: [struct.Struct('<3I2df3f3H7B'), [['boot_time',0.005,'时间戳',0], ['tick',0.005,'时间戳',0], ['tow',1,'GPS周期计数',0], ['lat_gps_inn',1,'内部GPS纬度(deg)',0], ['lon_gps_inn',1,'内部GPS经度(deg)',0], ['alt_gps_inn',1,'内部GPS高度(m)',0], ['vn_gps_inn',1,'内部GPS北向速度(m/s)',0], ['ve_gps_inn',1,'内部GPS东向速度(m/s)',0], ['vu_gps_inn',-1,'内部GPS天向速度(m/s)',0], ['year',1,'年份',0], ['msec',1,'毫秒',0], ['pdop',1,'PDOP值',0], ['month',1,'月份',0], ['day',1,'日期',0], ['hour',1,'小时',0], ['minute',1,'分钟',0], ['second',1,'秒',0], ['fixtype',1,'内部惯导定位模式',0], ['satnum',1,'内部惯导定位星数',0], ], [], ], 4: [struct.Struct('<3I6f9hH'), [['boot_time',0.005,'时间戳',0], ['tick',0.005,'时间戳',0], ['health',1,'传感器健康状态',0], ['ps_raw_1',1,'主静压(Pa)',0], ['ps_raw_2',1,'副静压(Pa)',0], ['qbar_raw_1',1,'主动压(Pa)',0], ['qbar_raw_2',1,'副动压(Pa)',0], ['mag_hdg',57.29,'磁航向(Deg)',0], ['gps_hdg',57.29,'GPS航向(Deg)',0], ['temp_imu_1',0.01,'主IMU温度(Deg)',0], ['temp_imu_2',0.01,'副IMU温度(Deg)',0], ['temp_qbar_1',0.01,'主IMU温度(Deg)',0], ['temp_qbar_2',0.01,'副IMU温度(Deg)',0], ['temp_ps_1',0.01,'主IMU温度(Deg)',0], ['temp_ps_2',0.01,'副IMU温度(Deg)',0], ['magx_raw',1,'磁力计',0], ['magy_raw',1,'磁力计',0], ['magz_raw',1,'磁力计',0], ['cpu_load',1,'导航',0], ], [], ], 5: [struct.Struct('<2IB9f2d10f8B5Hb'), [['boot_time',0.005,'时间戳',0], ['tick',1,'桢计数器',0], ['state',1,'传感器状态',0], ['tht_ins_ext',57.29,'外部惯导俯仰角(deg)',0], ['phi_ins_ext',57.29,'外部惯导滚转角(deg)',0], ['psi_ins_ext',57.29,'外部惯导偏航角(deg)',0], ['psit_ins_ext',57.29,'外部GPS航迹偏航角(deg)',0], ['q_ahrs_ext',57.29,'外部惯导俯仰角速度(deg/sec)',0], ['p_ahrs_ext',57.29,'外部惯导滚转角速度(deg/sec)',0], ['r_ahrs_ext',57.29,'外部惯导偏航角速度(deg/sec)',0], ['gps_hdg',57.29,'外部GPS双天线航向(deg)',0], ['gps_hdg_dev',57.29,'外部GPS双天线航向标准差(deg)',0], ['lon_gps_ext',1,'外部GPS经度(deg)',0], ['lat_gps_ext',1,'外部GPS纬度(deg)',0], ['alt_gps_ext',1,'外部GPS高度(m)',0], ['vn_ins_ext',1,'外部惯导北向速度(m/s)',0], ['ve_ins_ext',1,'外部惯导东向速度(m/s)',0], ['vu_ins_ext',-1,'外部惯导天向速度(m/s)',0], ['acc_n_ext',1,'外部惯导北向加速度(m/s2)',0], ['acc_e_ext',1,'外部惯导东向加速度(m/s2)',0], ['acc_d_ext',1,'外部惯导地向加速度(m/s2)',0], ['vn_gps_ext',1,'外部gps北向速度(m/s)',0], ['ve_gps_ext',1,'外部gps东向速度(m/s)',0], ['vu_gps_ext',-1,'外部gps天向速度(m/s)',0], ['satnum_ext',1,'外部卫星星数',0], ['gps_fixtype',1,'外部惯导定位类型',0], ['gps_hous',1,'GPS时',0], ['gps_minute',1,'GPS分',0], ['gps_second',1,'GPS秒',0], ['gps_day',1,'GPS周内天',0], ['work_state',1,'工作状态',0], ['gps_month',1,'GPS月',0], ['gps_year',1,'GPS年',0], ['gps_week',1,'GPS周',0], ['gps_msec',1,'GPS秒内毫秒',0], ['hdop',1,'水平精度因子',0], ['vdop',1,'垂直精度因子',0], ['temperature',1,'摄氏度',0], ], [], ], 6: [struct.Struct('<4IHd6f'), [['boot_time',0.005,'时间戳',0], ['tow_ms',1,'tow_ms',0], ['GPSWeek_uint32',1,'GPSWeek_uint32',0], ['imu_status',1,'imu_status',0], ['GPSWeek_uint16',1,'GPSWeek_uint16',0], ['tow_s',1,'tow_s',0], ['az_ins_ext',-1,'外部惯导上向加速度(m/s2)',0], ['ax_ins_ext',1,'外部惯导前向加速度(m/s2)',0], ['ay_ins_ext',1,'外部惯导侧向加速度(m/s2)',0], ['r_ins_ext',57.29,'外部惯导偏航角速度(deg/sec)',0], ['p_ins_ext',57.29,'外部惯导滚转角速度(deg/sec)',0], ['q_ins_ext',57.29,'外部惯导俯仰角速度(deg/sec)',0], ], [], ], 7: [struct.Struct('