📄 hqv1.java
字号:
package com.gps.center.parsedata;
import java.util.regex.Pattern;
import java.util.Date;
import com.gps.center.baseclass.MsgObj;
import com.gps.center.baseclass.ParseData;
import com.gps.center.baseclass.ParseInterface;
import com.gps.center.baseclass.HashObj;
public class HQV1 extends ParseData implements ParseInterface {
public HQV1() {
}
/**
* ParseMsg
* @param msg MsgObj
*/
public void ParseMsg(MsgObj msg) {
//将字符串分解,避免多条首尾相连
Pattern regex = Pattern.compile("[#]");
String reStr[] = regex.split(msg.cMsg);
// System.out.println("reStr[0]:" + msg.cMsg);
if (reStr.length > 1) {
boolean msgUsed = false;
for (int i = 0; i < reStr.length; i++) {
if (reStr[i].indexOf("V1") == -1) {
MsgObj msgobj = new MsgObj();
msgobj.cMsg = reStr[i] + "#";
// System.out.println("reStr[" + i + "]:" + msgobj.cMsg);
msgobj.cMsgType = msg.cMsgType;
msgobj.cSelectionKey = msg.cSelectionKey;
super.addRecieveMsg(msgobj);
}
else {
if (!msgUsed) {
msgUsed = true;
msg.cMsg = reStr[i] + "#";
}
else {
MsgObj msgobj = new MsgObj();
msgobj.cMsg = reStr[i] + "#";
// System.out.println("reStr[" + i + "]:" + msgobj.cMsg);
msgobj.cMsgType = msg.cMsgType;
msgobj.cSelectionKey = msg.cSelectionKey;
super.addRecieveMsg(msgobj);
}
// System.out.println("reStr[" + i + "]:" + msg.cMsg);
}
}
}
else {
msg.cMsg = reStr[0] + "#";
// System.out.println("reStr[0]:" + msg.cMsg);
}
parseTcpMsg(msg);
}
private void parseTcpMsg(MsgObj msg) {
// System.out.println("FenMi Device V1 msg :" + msg.cMsg);
// //更新hash
HashObj hashobj;
Pattern regex;
regex = Pattern.compile("[,]");
String[] reStr = regex.split(msg.cMsg);
//for (int i = 0; i < reStr.length; i++) {
//System.out.println(reStr[i]);
//}
//cMsgtype:1--TCPMSG,2--DEVICEUDPMSG,3--SMSMSG
//4--TCPSENDTODEVICE,5--UDPSENDTODEVICE,6--SMSSENDTODEVICE,7--TCPSENDTOTERMINAL,8--TCPRETURNTERMINAL
// //if (super.centerMap.containsKey(reStr[1])) {
if (super.centerMap.containsKey(reStr[1])) {
hashobj = (HashObj)super.centerMap.get(reStr[1]);
if (msg.cMsgType == 1) {
if ( (hashobj.cDeviceKey != null) & (hashobj.cDeviceTcpUsed)) {
if (!msg.cSelectionKey.equals(hashobj.cDeviceKey)) {
hashobj.cDeviceKey = msg.cSelectionKey;
hashobj.cDateTime = new Date();
}
}
else {
hashobj.cDeviceKey = msg.cSelectionKey;
hashobj.cDateTime = new Date();
hashobj.cDeviceTcpUsed = true;
}
}
else if (msg.cMsgType == 3) {
if (hashobj.cDeviceSmsUsed) {
if (!msg.cPhoneNum.equals(hashobj.cPhonNum)) {
hashobj.cPhonNum = msg.cPhoneNum;
//hashobj.cDateTime = new Date();
}
}
else {
//hashobj.cDateTime = new Date();
hashobj.cPhonNum = msg.cPhoneNum;
hashobj.cDeviceSmsUsed = true;
}
}
}
else {
hashobj = new HashObj();
if (msg.cMsgType == 1) {
hashobj.cTerminalKey = msg.cSelectionKey;
hashobj.cDateTime = new Date();
hashobj.cDeviceTcpUsed = true;
super.centerMap.put(reStr[1], hashobj);
}
else if (msg.cMsgType == 3) {
hashobj.cPhonNum = msg.cPhoneNum;
hashobj.cDeviceSmsUsed = true;
}
}
//状态解析 FFFFFBFF
String stateStr = new String("");
int bt = 0;
String tmpStr = new String("");
// System.out.println(reStr[12]);
for (int i = 0; i < 7; i += 2) {
// String tempState = new String("");
// System.out.println("substring:" + reStr[12].substring(i, i + 2));
bt = Integer.parseInt(reStr[12].substring(i, i + 2), 16);
switch (i) {
case 0:
tmpStr = getState1(bt);
if (!tmpStr.equals("")) {
if (stateStr.equals("")) {
stateStr = stateStr + "," + tmpStr;
}
else {
stateStr = stateStr + "+" + tmpStr;
}
}
break;
case 2:
tmpStr = getState2(bt);
if (!tmpStr.equals("")) {
if (stateStr.equals("")) {
stateStr = stateStr + "," + tmpStr;
}
else {
stateStr = stateStr + "+" + tmpStr;
}
}
break;
case 4:
tmpStr = getState3(bt);
if (!tmpStr.equals("")) {
if (stateStr.equals("")) {
stateStr = stateStr + "," + tmpStr;
}
else {
stateStr = stateStr + "+" + tmpStr;
}
}
break;
case 6:
tmpStr = getState4(bt);
if (!tmpStr.equals("")) {
if (stateStr.equals("")) {
stateStr = stateStr + "," + tmpStr;
}
else {
stateStr = stateStr + "+" + tmpStr;
}
}
break;
}
}
//*HQ,2020916012,V1,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFF#
//114, 13954667441, NULL,A,3958.5986,N,11619.8053,E,00.0,000,080903,0,+0022,283848,0089,SMS(UDP,TCP)
//114, 13954667441, 京A-1234,A,3958.5986,N,11619.8053,E,00.0,000,2005-06-13 13:12:06,0,+0022,283848,0089,SMS(UDP,TCP)
String sendStr = "114," + reStr[1] + ",NULL," + reStr[4] + "," + reStr[5] +
"," + reStr[6] + "," + reStr[7] + "," + reStr[8] + "," + reStr[9] +
"," + reStr[10] + "," + CanSend.getDateTime() + stateStr +
",NULL,NULL,NULL";
//cMsgtype:1--TCPMSG,2--DEVICEUDPMSG,3--SMSMSG
//4--TCPSENDTODEVICE,5--UDPSENDTODEVICE,6--SMSSENDTODEVICE,7--TCPSENDTOTERMINAL,8--TCPRETURNTERMINAL
if (msg.cMsgType == TCPMSG) {
sendStr = sendStr + ",TCP";
}
else if (msg.cMsgType == DEVICEUDPMSG) {
sendStr = sendStr + ",UDP";
}
else { //if(msg.cMsgType == SMSMSG){
sendStr = sendStr + ",SMS";
}
msg.cMsgType = TCPSENDTOTERMINAL;
msg.cDeviceID = reStr[1];
msg.cMsg = sendStr;
super.addSendMsg(msg);
//DeviceID,Longitude,Latitude,Speed
//3958.5986,N,11619.8053,E
if (reStr[4].equals("A")) {
String[] dbStr = new String[4];
dbStr[0] = reStr[1];
dbStr[1] = String.valueOf(Float.parseFloat(reStr[7].substring(0, 3)) +
(Float.parseFloat(reStr[7].substring(3)) / 60));
dbStr[2] = String.valueOf(Float.parseFloat(reStr[5].substring(0, 2)) +
(Float.parseFloat(reStr[5].substring(2)) / 60));
dbStr[3] = reStr[9];
// for (int i = 0; i < 4; i++) {
// System.out.println("dbStr[" + i + "]:" + dbStr[i]);
// }
// DbServer.updateTrackForceGpsInfo(String[] gpsStr);
}
}
private String getState1(int intState) {
int state = ~intState;
String stateStr = new String("");
if ( (state & 0x10) == 0x10) {
if (stateStr.equals("")) {
stateStr = stateStr + "28";
}
else {
stateStr = stateStr + "+28";
}
}
if ( (state & 0x8) == 0x8) {
if (stateStr.equals("")) {
stateStr = stateStr + "34";
}
else {
stateStr = stateStr + "+34";
}
}
if ( (state & 0x4) == 0x4) {
if (stateStr.equals("")) {
stateStr = stateStr + "35";
}
else {
stateStr = stateStr + "+35";
}
}
if ( (state & 0x2) == 0x2) {
if (stateStr.equals("")) {
stateStr = stateStr + "36";
}
else {
stateStr = stateStr + "+36";
}
}
if ( (state & 0x1) == 0x1) {
if (stateStr.equals("")) {
stateStr = stateStr + "31";
}
else {
stateStr = stateStr + "+31";
}
}
// if ( (state & 0x80) == 0x80) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "31";
// }
// else {
// stateStr = stateStr + "+31";
// }
// }
// if ( (state & 0x40) == 0x40) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "24";
// }
// else {
// stateStr = stateStr + "+24";
// }
// }
// if ( (state & 0x20) == 0x20) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "3";
// }
// else {
// stateStr = stateStr + "+3";
// }
// }
// if ( (state & 0x10) == 0x10) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "28";
// }
// else {
// stateStr = stateStr + "+28";
// }
// }
// if ( (state & 0x8) == 0x8) {
// if (stateStr.equals("")) {
// stateStr = stateStr + ",35";
// }
// else {
// stateStr = stateStr + "+35";
// }
// }
// if ( (state & 0x2) == 0x2) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "4";
// }
// else {
// stateStr = stateStr + "+4";
// }
// }
// if ( (state & 0x1) == 0x1) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "36";
// }
// else {
// stateStr = stateStr + "+36";
// }
// }
return stateStr;
}
private String getState2(int intState) {
int state = ~intState;
String stateStr = new String("");
if ( (state & 0x40) == 0x40) {
if (stateStr.equals("")) {
stateStr = stateStr + "37";
}
else {
stateStr = stateStr + "+37";
}
}
if ( (state & 0x20) == 0x20) {
if (stateStr.equals("")) {
stateStr = stateStr + "38";
}
else {
stateStr = stateStr + "+38";
}
}
if ( (state & 0x10) == 0x10) {
if (stateStr.equals("")) {
stateStr = stateStr + "28";
}
else {
stateStr = stateStr + "+28";
}
}
if ( (state & 0x8) == 0x8) {
if (stateStr.equals("")) {
stateStr = stateStr + "27";
}
else {
stateStr = stateStr + "+27";
}
}
if ( (state & 0x1) == 0x1) {
if (stateStr.equals("")) {
stateStr = stateStr + "24";
}
else {
stateStr = stateStr + "+24";
}
}
// if ( (state & 0x80) == 0x80) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "21";
// }
// else {
// stateStr = stateStr + "+21";
// }
// }
// // if ( ( state & 0x40) == 0x40) {
// // if (stateStr.equals("")) {
// // stateStr = stateStr + "24";
// // }
// // else {
// // stateStr = stateStr + "+24";
// // }
// // }
// if ( (state & 0x20) == 0x20) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "2";
// }
// else {
// stateStr = stateStr + "+2";
// }
// }
// if ( (state & 0x10) == 0x10) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "22";
// }
// else {
// stateStr = stateStr + "+22";
// }
// }
// if ( (state & 0x4) == 0x4) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "27";
// }
// else {
// stateStr = stateStr + "+27";
// }
// }
// if ( (state & 0x2) == 0x2) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "29";
// }
// else {
// stateStr = stateStr + "+29";
// }
// }
// if ( (state & 0x1) == 0x1) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "38";
// }
// else {
// stateStr = stateStr + "+38";
// }
// }
return stateStr;
}
private String getState3(int intState) {
int state = ~intState;
String stateStr = new String("");
if ( (state & 0x20) == 0x20) {
if (stateStr.equals("")) {
stateStr = stateStr + "3";
}
else {
stateStr = stateStr + "+3";
}
}
// if ( ( state & 0x40) == 0x40) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "24";
// }
// else {
// stateStr = stateStr + "+24";
// }
// }
if ( (state & 0x4) == 0x4) {
if (stateStr.equals("")) {
stateStr = stateStr + "2";
}
else {
stateStr = stateStr + "+2";
}
}
// if ( ( state & 0x10) == 0x10) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "22";
// }
// else {
// stateStr = stateStr + "+22";
// }
// }
if ( (state & 0x2) == 0x2) {
if (stateStr.equals("")) {
stateStr = stateStr + "4";
}
else {
stateStr = stateStr + "+4";
}
}
if ( (state & 0x1) == 0x1) {
if (stateStr.equals("")) {
stateStr = stateStr + "5";
}
else {
stateStr = stateStr + "+5";
}
}
// if ( (state & 0x1) == 0x1) {
// if (stateStr.equals("")) {
// stateStr = stateStr + "38";
// }
// else {
// stateStr = stateStr + "+38";
// }
// }
return stateStr;
}
private String getState4(int intState) {
int state = ~intState;
String stateStr = new String("");
if ( (state & 0x80) == 0x80) {
if (stateStr.equals("")) {
stateStr = stateStr + "39";
}
else {
stateStr = stateStr + "+39";
}
}
if ( (state & 0x40) == 0x40) {
if (stateStr.equals("")) {
stateStr = stateStr + "40";
}
else {
stateStr = stateStr + "+40";
}
}
if ( (state & 0x20) == 0x20) {
if (stateStr.equals("")) {
stateStr = stateStr + "41";
}
else {
stateStr = stateStr + "+41";
}
}
if ( (state & 0x10) == 0x10) {
if (stateStr.equals("")) {
stateStr = stateStr + "42";
}
else {
stateStr = stateStr + "+42";
}
}
if ( (state & 0x8) == 0x8) {
if (stateStr.equals("")) {
stateStr = stateStr + "43";
}
else {
stateStr = stateStr + "+43";
}
}
if ( (state & 0x4) == 0x4) {
if (stateStr.equals("")) {
stateStr = stateStr + "44";
}
else {
stateStr = stateStr + "+44";
}
}
if ( (state & 0x2) == 0x2) {
if (stateStr.equals("")) {
stateStr = stateStr + "45";
}
else {
stateStr = stateStr + "+45";
}
}
if ( (state & 0x1) == 0x1) {
if (stateStr.equals("")) {
stateStr = stateStr + "46";
}
else {
stateStr = stateStr + "+46";
}
}
return stateStr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -