|
@@ -78,6 +78,38 @@ QByteArray MkSensorThread::mkRtn()
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 将16进制字符串转换为ASCII字符串
|
|
|
|
|
+QString hexToAscii(QString hexString)
|
|
|
|
|
+{
|
|
|
|
|
+ // 移除所有空格(处理类似"48 65 6C 6C 6F"这样的格式)
|
|
|
|
|
+ QString hex = hexString.remove(' ');
|
|
|
|
|
+
|
|
|
|
|
+ // 检查16进制字符串长度是否为偶数
|
|
|
|
|
+ if (hex.length() % 2 != 0) {
|
|
|
|
|
+ qWarning() << "Invalid hex string: length is odd";
|
|
|
|
|
+ return QString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QByteArray byteArray;
|
|
|
|
|
+
|
|
|
|
|
+ // 每次处理两个字符(一个字节)
|
|
|
|
|
+ for (int i = 0; i < hex.length(); i += 2) {
|
|
|
|
|
+ QString hexPair = hex.mid(i, 2);
|
|
|
|
|
+ bool ok;
|
|
|
|
|
+ char byte = hexPair.toUInt(&ok, 16); // 将16进制字符串转换为字节
|
|
|
|
|
+
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ qWarning() << "Invalid hex character:" << hexPair;
|
|
|
|
|
+ return QString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ byteArray.append(byte);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将字节数组转换为ASCII字符串
|
|
|
|
|
+ return QString(byteArray);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void MkSensorThread::checkDevice(QString deviceid)
|
|
void MkSensorThread::checkDevice(QString deviceid)
|
|
|
{
|
|
{
|
|
|
if((DevIdx3>=0)&&(DevIdx3<10240))
|
|
if((DevIdx3>=0)&&(DevIdx3<10240))
|
|
@@ -133,10 +165,12 @@ void MkSensorThread::check_framedata(QString data, QString etime, QString ip)
|
|
|
// QDateTime stime = QDateTime::fromTime_t(static_cast<uint>(((Dat[2]&0x000000ff)<<24)|((Dat[3]&0x000000ff)<<16)|((Dat[4]&0x000000ff)<<8)|(Dat[5]&0x000000ff)));
|
|
// QDateTime stime = QDateTime::fromTime_t(static_cast<uint>(((Dat[2]&0x000000ff)<<24)|((Dat[3]&0x000000ff)<<16)|((Dat[4]&0x000000ff)<<8)|(Dat[5]&0x000000ff)));
|
|
|
quint16 bodyLen = static_cast<quint16>(((Dat[3]&0x00ff)<<8)|(Dat[4]&0x00ff));
|
|
quint16 bodyLen = static_cast<quint16>(((Dat[3]&0x00ff)<<8)|(Dat[4]&0x00ff));
|
|
|
table.append( QString("bodyLen:%1,").arg(bodyLen));
|
|
table.append( QString("bodyLen:%1,").arg(bodyLen));
|
|
|
- QString device_code = "";
|
|
|
|
|
|
|
+ QString device_code1 = "";
|
|
|
for(int i=5;i<17;i++){
|
|
for(int i=5;i<17;i++){
|
|
|
- device_code.append( QString("%1").arg(Dat[i]&0xff,2,16,QLatin1Char('0')));
|
|
|
|
|
|
|
+ device_code1.append( QString("%1").arg(Dat[i]&0xff,2,16,QLatin1Char('0')));
|
|
|
}
|
|
}
|
|
|
|
|
+ QString device_code = hexToAscii(device_code1);
|
|
|
|
|
+ checkDevice(device_code);
|
|
|
table.append( QString("device_code:%1,").arg(device_code));
|
|
table.append( QString("device_code:%1,").arg(device_code));
|
|
|
|
|
|
|
|
int batteryLevel = 0;
|
|
int batteryLevel = 0;
|
|
@@ -178,7 +212,7 @@ void MkSensorThread::check_framedata(QString data, QString etime, QString ip)
|
|
|
int alarmUpper1=alarmUpper;
|
|
int alarmUpper1=alarmUpper;
|
|
|
table.append( QString("alarmUpper:%1,").arg(alarmUpper1*sb1[deviceType]));
|
|
table.append( QString("alarmUpper:%1,").arg(alarmUpper1*sb1[deviceType]));
|
|
|
quint16 dataNow = static_cast<quint16>(((Dat[29]&0x00ff)<<8)|(Dat[30]&0x00ff));
|
|
quint16 dataNow = static_cast<quint16>(((Dat[29]&0x00ff)<<8)|(Dat[30]&0x00ff));
|
|
|
- int dataNow1=dataNow*sb1[deviceType];
|
|
|
|
|
|
|
+ double dataNow1=dataNow*sb1[deviceType];
|
|
|
table.append( QString("dataNow:%1,").arg(dataNow1));
|
|
table.append( QString("dataNow:%1,").arg(dataNow1));
|
|
|
QDateTime dataTime = QDateTime::fromTime_t(static_cast<uint>(((Dat[31]&0x000000ff)<<24)|((Dat[32]&0x000000ff)<<16)|((Dat[33]&0x000000ff)<<8)|(Dat[34]&0x000000ff)));
|
|
QDateTime dataTime = QDateTime::fromTime_t(static_cast<uint>(((Dat[31]&0x000000ff)<<24)|((Dat[32]&0x000000ff)<<16)|((Dat[33]&0x000000ff)<<8)|(Dat[34]&0x000000ff)));
|
|
|
table.append( QString("dataTime:%1,").arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")));
|
|
table.append( QString("dataTime:%1,").arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")));
|
|
@@ -200,11 +234,11 @@ void MkSensorThread::check_framedata(QString data, QString etime, QString ip)
|
|
|
emit getCommData(QString("NBtable18=====:%1++++++++++++++++++%2")
|
|
emit getCommData(QString("NBtable18=====:%1++++++++++++++++++%2")
|
|
|
.arg("table").arg(deviceType));
|
|
.arg("table").arg(deviceType));
|
|
|
if(deviceType == 1){
|
|
if(deviceType == 1){
|
|
|
- emit getValue(DevIdx3,"WP0",batteryLevel,signal,dataNow1,ip,dataTime);
|
|
|
|
|
|
|
+ emit getValue(DeviceID3,"WP0",batteryLevel,signal,dataNow1,ip,dataTime);
|
|
|
}else if (deviceType == 8){
|
|
}else if (deviceType == 8){
|
|
|
emit getCommData(QString("NBtable8=====:%1++++++++++++++++++%2")
|
|
emit getCommData(QString("NBtable8=====:%1++++++++++++++++++%2")
|
|
|
.arg("table").arg(deviceType));
|
|
.arg("table").arg(deviceType));
|
|
|
- emit getValue(DevIdx3,"LL0",batteryLevel,signal,dataNow1,ip,dataTime);
|
|
|
|
|
|
|
+ emit getValue(DeviceID3,"LL0",batteryLevel,signal,dataNow1,ip,dataTime);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if ((Dat[24] & 0x01) == 0x01) {
|
|
if ((Dat[24] & 0x01) == 0x01) {
|
|
@@ -212,18 +246,18 @@ void MkSensorThread::check_framedata(QString data, QString etime, QString ip)
|
|
|
alarm_state = "下限报警";
|
|
alarm_state = "下限报警";
|
|
|
judge = true;
|
|
judge = true;
|
|
|
if(deviceType==1){
|
|
if(deviceType==1){
|
|
|
- emit getAlarm(DevIdx3,"WP1",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("低压"),dataTime);
|
|
|
|
|
|
|
+ emit getAlarm(DeviceID3,"WP1",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("低压"),dataTime);
|
|
|
}else if (deviceType==8){
|
|
}else if (deviceType==8){
|
|
|
- emit getAlarm(DevIdx3,"LL1",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("低水位"),dataTime);
|
|
|
|
|
|
|
+ emit getAlarm(DeviceID3,"LL1",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("低水位"),dataTime);
|
|
|
}
|
|
}
|
|
|
} else if ((Dat[24] & 0x02) == 0x02) {
|
|
} else if ((Dat[24] & 0x02) == 0x02) {
|
|
|
bjstr += "上限报警 ";
|
|
bjstr += "上限报警 ";
|
|
|
alarm_state = "上限报警";
|
|
alarm_state = "上限报警";
|
|
|
judge = true;
|
|
judge = true;
|
|
|
if(deviceType==1){
|
|
if(deviceType==1){
|
|
|
- emit getAlarm(DevIdx3,"WP2",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("高压"),dataTime);
|
|
|
|
|
|
|
+ emit getAlarm(DeviceID3,"WP2",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("高压"),dataTime);
|
|
|
}else if (deviceType==8){
|
|
}else if (deviceType==8){
|
|
|
- emit getAlarm(DevIdx3,"LL2",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("高水位"),dataTime);
|
|
|
|
|
|
|
+ emit getAlarm(DeviceID3,"LL2",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("高水位"),dataTime);
|
|
|
}
|
|
}
|
|
|
} else if ((Dat[24] & 0x03) == 0x00) {
|
|
} else if ((Dat[24] & 0x03) == 0x00) {
|
|
|
alarm_state = "状态正常";
|
|
alarm_state = "状态正常";
|
|
@@ -240,9 +274,9 @@ void MkSensorThread::check_framedata(QString data, QString etime, QString ip)
|
|
|
bjstr += "传感器异常";
|
|
bjstr += "传感器异常";
|
|
|
sensor_state = "传感器异常";
|
|
sensor_state = "传感器异常";
|
|
|
if(deviceType==1){
|
|
if(deviceType==1){
|
|
|
- emit getAlarm(DevIdx3,"WP3",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("故障"),dataTime);
|
|
|
|
|
|
|
+ emit getAlarm(DeviceID3,"WP3",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("故障"),dataTime);
|
|
|
}else if (deviceType==8){
|
|
}else if (deviceType==8){
|
|
|
- emit getAlarm(DevIdx3,"LL3",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("故障"),dataTime);
|
|
|
|
|
|
|
+ emit getAlarm(DeviceID3,"LL3",batteryLevel,signal,dataNow1,ip,QString::fromUtf8("故障"),dataTime);
|
|
|
}
|
|
}
|
|
|
} else if ((Dat[24] & 0x08) == 0x00) {
|
|
} else if ((Dat[24] & 0x08) == 0x00) {
|
|
|
sensor_state = "状态正常";
|
|
sensor_state = "状态正常";
|
|
@@ -299,8 +333,8 @@ void MkSensorThread::check_serverdata(QString data, QString ip){
|
|
|
emit getCommData(QString("[ %1 47.98.201.187 (wuji) ] %2")
|
|
emit getCommData(QString("[ %1 47.98.201.187 (wuji) ] %2")
|
|
|
.arg(ip)
|
|
.arg(ip)
|
|
|
.arg(DStr.replace('\n',"\\n").replace('\r',"\\r")));
|
|
.arg(DStr.replace('\n',"\\n").replace('\r',"\\r")));
|
|
|
-// QString data1 = data.replace("\r","").replace("\n","").replace(" ","");
|
|
|
|
|
-// check_framedata(data1,ip,ip);
|
|
|
|
|
|
|
+ QString data1 = data.replace("\r","").replace("\n","").replace(" ","");
|
|
|
|
|
+ check_framedata(data1,ip,ip);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static unsigned char auchCRCHi[] =
|
|
static unsigned char auchCRCHi[] =
|
|
@@ -425,7 +459,7 @@ void MkSensorThread::readData(QTcpSocket *so)
|
|
|
{
|
|
{
|
|
|
QByteArray data = so->readAll();
|
|
QByteArray data = so->readAll();
|
|
|
QDateTime t = QDateTime::currentDateTime();
|
|
QDateTime t = QDateTime::currentDateTime();
|
|
|
- quint16 bytesDataArray[] = { 0x48, 0x0A, 0x02, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x75};
|
|
|
|
|
|
|
+ quint16 bytesDataArray[] = { 0xa5, 0x5a, 0xff, 0x00, 0x1b, 0x4a, 0x53, 0x53, 0x48, 0x31, 0x39, 0x30, 0x35, 0x30, 0x30, 0x30, 0x35, 0x5d, 0x19, 0xbb, 0xde, 0x00, 0x00, 0xa3, 0x2b, 0x55, 0xaa};
|
|
|
#ifdef comm_debug
|
|
#ifdef comm_debug
|
|
|
QString DStr = "";
|
|
QString DStr = "";
|
|
|
for(int i=0;i<data.length();i++){
|
|
for(int i=0;i<data.length();i++){
|
|
@@ -476,6 +510,23 @@ void MkSensorThread::readData(QTcpSocket *so)
|
|
|
bytesSend.append(bytesDataArray[7]);
|
|
bytesSend.append(bytesDataArray[7]);
|
|
|
bytesSend.append(bytesDataArray[8]);
|
|
bytesSend.append(bytesDataArray[8]);
|
|
|
bytesSend.append(bytesDataArray[9]);
|
|
bytesSend.append(bytesDataArray[9]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[10]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[11]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[12]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[13]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[14]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[15]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[16]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[17]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[18]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[19]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[20]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[21]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[22]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[23]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[24]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[25]);
|
|
|
|
|
+ bytesSend.append(bytesDataArray[26]);
|
|
|
// check_serverdata(data, so->peerAddress().toString());
|
|
// check_serverdata(data, so->peerAddress().toString());
|
|
|
so->write(bytesSend);
|
|
so->write(bytesSend);
|
|
|
}
|
|
}
|