예제 #1
0
    def PorcessInclinometer(self, port, bindata):
        try:
            index = 0
            sendData = list()
            writData = list()

            while 1:
                index = bindata.find(b'\xAA', index)

                # 未找到头
                if index == -1:
                    break

                # 数据长度不足
                if len(bindata[index:]) < self.serPackLen:
                    return bindata[index:]

                # 结尾错误
                if bindata[index + self.serPackLen - 1] == b'\xFF':
                    index += 1
                    self.txtfileDict[port].writelines('数据结尾错误!\r\n')
                    continue

                # 解码
                pack = ()
                pack = struct.unpack('>chhhc',
                                     bindata[index:index + self.serPackLen])

                # 加入时间标记
                t = time.time()
                lpack = [t, pack[1] / 1000, pack[2] / 1000, pack[3] / 10]
                sendData.append(lpack)

                ts = get_time_stamp(t)
                wpack = str([ts, pack[1] / 1000, pack[2] / 1000, pack[3] / 10])
                writData.append(wpack)

                index += self.serPackLen

            if sendData:
                if self.saveflagDict[port]:
                    day = int(sendData[0][0] / 86400)
                    if day > self.txtfileDayDict[port]:
                        self.txtfileDict[port].close()

                        self.txtfileDayDict[port] = day
                        fname = 'data\\' + port + '_Data_' + time.strftime(
                            "%Y%m%d%H%M%S", time.localtime(t)) + '.txt'
                        self.txtfileDict[port] = open(fname, 'w')

                    for w in writData:
                        self.txtfileDict[port].writelines(w + '\r\n')

                self.sinRefresh.emit(port, sendData)
            else:
                pass
            return bytes()
        except Exception as err:
            QMessageBox.information(self, "PorcessInclinometer", str(err),
                                    QMessageBox.Ok)
예제 #2
0
    def Refresh(self, ld):
        if not ld:
            return
        for d in ld:
            ts = get_time_stamp(d[0])
            self.textEdit.append(ts + ": " + str(d[1:]))

        self.sinOnDraw.emit(ld)
예제 #3
0
    def PorcessImu(self, port, bindata):
        try:
            index = 0
            sendData = list()

            while 1:
                index = bindata.find(b'\xAA\xFF\x55\x01', index)

                # 未找到头
                if index == -1:
                    break

                # 数据长度不足
                if len(bindata[index:]) < self.serPackLen:
                    return bindata[index:]

                # 校验判断
                ck = 0x00
                for b in bindata[index:index + self.serPackLen - 2]:
                    ck += b
                if bindata[index + self.serPackLen - 1] != ck % 256:
                    # 校验错误
                    index += self.serPackLen
                    print('数据包校验错误!!!')
                    continue

                # 解码
                pack = ()
                pack = struct.unpack('<ccccHHHiiiiiihhhhhhBc',
                                     bindata[index:index + self.serPackLen])

                # 加入时间戳
                t = time.time()
                ts = get_time_stamp(t)

                # time, frameID, gyro_dx, gyro_dy, gyro_dz, aac_dx, acc_dy, acc_z, gyro_tx, gyro_ty, gyro_tz, aaa_tx, acc_ty, acc_tz
                lpack = [t]
                lpack.append(pack[6])
                for i in range(3):
                    lpack.append(round(pack[7 + i] * 1e-5, 8))
                for i in range(3):
                    lpack.append(round(pack[10 + i] * 1e-7, 8))
                for i in range(6):
                    lpack.append(round(pack[13 + i] * 0.1, 1))
                #print(lpack)

                sendData.append(lpack)

                # 更新index
                index += self.serPackLen

            if self.saveflagDict[port]:
                for l in sendData:
                    self.txtfileDict[port].writelines(str(l) + '\n')

            self.sinRefresh.emit(port, sendData)

            return bytes()
        except Exception as err:
            QMessageBox.information(self, "PorcessImu", str(err),
                                    QMessageBox.Ok)