⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hqv4.java~4~

📁 用java写编写的一个GPS源代码请大家多多指教
💻 JAVA~4~
📖 第 1 页 / 共 2 页
字号:
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;
import com.gps.center.dataservice.DbServer;

public class HQV4 extends ParseData implements ParseInterface {
  public HQV4() {
  }
  /**
   * 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("V4") == -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);

  }

  //*HQ,2020916012,V4,S17,130305,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFF#
   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("V4 State :" + reStr[reStr.length - 1]);
     for (int i = 0; i < 7; i += 2) {
//      String tempState = new String("");
//      System.out.println("substring:" + reStr[14].substring(i, i + 2));
       bt = Integer.parseInt(reStr[reStr.length - 1].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#
      //*HQ,2020916012,V4,S17,130305,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFF#
       //*HQ,3041117092,V4,S23,61.48.26.11:6666,154332,001144,V,0000.0000,N,00000.0000,E,000.00,000,080320,FFE7FBFF#
        //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[reStr.length - 9] +
            "," + reStr[reStr.length - 8] +
            "," + reStr[reStr.length - 7] + "," + reStr[reStr.length - 6] + "," +
            reStr[reStr.length - 5] + "," + reStr[reStr.length - 4] +
            "," + reStr[reStr.length - 3] + "," + CanSend.getDateTime() +
            stateStr +
            ",NULL,NULL,NULL";
     if (msg.cMsgType == 1) {
       sendStr = sendStr + ",TCP";
     }
     else {
       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[reStr.length - 9].equals("A")) {
       String[] dbStr = new String[4];
       dbStr[0] = reStr[1];
       dbStr[1] = String.valueOf(Float.parseFloat(reStr[reStr.length -
                                                  6].substring(0, 3)) +
                                 (Float.
                                  parseFloat(reStr[reStr.length -
                                             6].substring(3)) / 60));
       dbStr[2] = String.valueOf(Float.parseFloat(reStr[reStr.length -
                                                  8].substring(0, 2)) +
                                 (Float.
                                  parseFloat(reStr[reStr.length -
                                             8].substring(2)) / 60));
       dbStr[3] = reStr[reStr.length - 3];

//       for (int i = 0; i < 4; i++) {
//         System.out.println("dbStr[" + i + "]:" + dbStr[i]);
//       }

     }
   }

  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";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -