📄 hcgdat114.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 HcGDAT114 extends ParseData implements ParseInterface {
// private HashObj hashobj;
public HcGDAT114() {
}
public void ParseMsg(MsgObj msg) {
parseUdpMsg(msg);
}
private void parseUdpMsg(MsgObj msg) {
//更新hash
HashObj hashobj;
Pattern regex;
//逗号匹配模式
regex = Pattern.compile("[,]");
String[] reStr = regex.split(msg.cMsg);
if (super.centerMap.containsKey(reStr[2])) {//判断表中是否包含此车的值
hashobj = (HashObj)super.centerMap.get(reStr[2]);
if (hashobj.cDeviceUdpUsed & (msg.cDeviceAdd != null)) {//判断使用了UDP同时IP不为空
if (! (hashobj.cDeviceAdd.getHostAddress().equals(msg.cDeviceAdd.
getHostAddress())
) |
(hashobj.cDevicePort != msg.cUdpPort)) {
hashobj.cDateTime = new Date();
hashobj.cDeviceAdd = msg.cDeviceAdd;
hashobj.cDevicePort = msg.cUdpPort;
}
else {
hashobj.cDateTime = new Date();
}
}
else {//否则修正
hashobj.cDateTime = new Date();
hashobj.cUdpSocket = msg.cUdpSocket;
if (msg.cDeviceAdd != null) {
hashobj.cDeviceAdd = msg.cDeviceAdd;
}
hashobj.cDevicePort = msg.cUdpPort;
hashobj.cDeviceUdpUsed = true;
}
}
else {//否则向centerMap中台添加此索引和值
hashobj = new HashObj();
hashobj.cDateTime = new Date();
hashobj.cDeviceAdd = msg.cDeviceAdd;
hashobj.cDevicePort = msg.cUdpPort;
hashobj.cUdpSocket = msg.cUdpSocket;
hashobj.cDeviceUdpUsed = true;
super.centerMap.put(reStr[2], hashobj);
}
//状态解析
//GDAT,00000008,13811932658,000000,V,0000.0000,N,00000.0000,E,00.0,000,000000,01,,,,*
String stateStr = new String("");
System.out.println(reStr[12]);
int bt = Integer.parseInt(reStr[12], 16);
// byte bt = Byte.parseByte(reStr[12]);
//断电报警33:(1000000)0x40 越界23(100000)0x20 超速22(10000)0x10 报警21(100)0x4 ACC(1)0x1
if ( (bt & 0x40) == 0x40) {
if (stateStr.equals("")) {
stateStr = stateStr + ",33";
}
else {
stateStr = stateStr + "+33";
}
}
if ( (bt & 0x20) == 0x20) {
if (stateStr.equals("")) {
stateStr = stateStr + ",23";
}
else {
stateStr = stateStr + "+23";
}
}
if ( (bt & 0x10) == 0x10) {
if (stateStr.equals("")) {
stateStr = stateStr + ",22";
}
else {
stateStr = stateStr + "+22";
}
}
if ( (bt & 0x4) == 0x4) {
if (stateStr.equals("")) {
stateStr = stateStr + ",21";
}
else {
stateStr = stateStr + "+21";
}
}
if ( (bt & 0x1) == 0x1) {
if (stateStr.equals("")) {
stateStr = stateStr + ",1";
}
else {
stateStr = stateStr + "+1";
}
}
if (bt == 0x0) {
if (stateStr.equals("")) {
stateStr = stateStr + ",2";
}
else {
stateStr = stateStr + "+2";
}
}
//添加Msg到sendQueue
//cMsgtype:1--TCPMSG,2--DEVICEUDPMSG,3--SMSMSG
//4--TCPSENDTODEVICE,5--UDPSENDTODEVICE,6--SMSSENDTODEVICE,7--TCPSENDTOTERMINAL,8--TCPRETURNTERMINAL
//GDAT,00001234,13811932658,073831,A,3958.5986,N,11619.8053,E,00.0,000,080903,00,+0022,283848,0089,*
//114, 13954667441, NULL,A,3958.5986,N,11619.8053,E,00.0,000,080903,0,+0022,283848,0089,SMS(UDP,TCP)
//GDAT,00000038,13581877196,000000,V,0000.0000,N,00000.0000,E,00.0,000,000000,01,,,*
// System.out.println(reStr[15]);
for (int i = 0; i < reStr.length; i++) {
if (reStr[i].equals("")) {
reStr[i] = "NULL";
}
}
if (reStr[15].equals("*")) {
reStr[15] = "NULL";
}
else {
if (reStr[15].indexOf("*") != -1) {
reStr[15] = reStr[15].replaceFirst("*", "");
}
}
String DBString = reStr[2]+","+" "+","+reStr[4]+","+reStr[5]+","+reStr[6]+","+reStr[7]+","+reStr[8]+","+reStr[10]+","+reStr[9]+","+stateStr+","+""+","+""+","+"";
/*String sendStr = "114," + reStr[2] + ",NULL," + reStr[4] + "," + reStr[5] +
"," + reStr[6] + "," + reStr[7] + "," + reStr[8] + "," + reStr[9] +
"," + reStr[10] + "," + CanSend.getDateTime() + stateStr +
"," + reStr[13] + "," + reStr[14] + "," + reStr[15] + ",UDP";
msg.cMsgType = TCPSENDTOTERMINAL;
msg.cDeviceID = reStr[2];
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[2];
// System.out.println("reStr[7]:" + reStr[7].substring(0, 3));
// System.out.println("reStr[7]:" + reStr[7].substring(3));
// System.out.println("reStr[7]:" + reStr[5].substring(0, 2));
// System.out.println("reStr[7]:" + reStr[5].substring(2));
//GDAT,00001234,13811932658,073831,A,3958.5986,N,11619.8053,E,00.0,000,080903,00,+0022,283848,0089,*
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(dbStr);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -