Yao Micron Technology Positioning System data analysis -java

Yao Micron Technology Positioning System data analysis -java

package com.ygkj.test;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

import org.apache.commons.codec.binary.Hex;

/*******************************************************************************************************
 * Copyright: vc1.0 2018. All rights reserved.                    <br>
 * The whole package including this class is licensed under        <br>
 *                                                                 <br>
 * @ClassName:                                        <br>
 * @Directory:                                        <br>
 * @version:         v1.0.0                                        <br>
 * @date:                                                <br>
 * @Description:                                                 <br>
 *       1、                                        <br>
 *       2、                                        <br>
 * @Others: 暂无说明                                                <br>
 * @Modification History:                                        <br>
 *       1、                                            <br>
 *       Date:                              <br>
 *       Author:                                        <br>
 *       Modification:                                     <br>
 *                                                                 <br>
 *       2、                                                        <br>
 *       Date:                                                  <br>
 *       Author:                                                   <br>
 *       Modification:                                          <br>
 *       
 * @Statement: If you are using the package or parts of it in any commercial way, a commercial license is required. <br>
 *   Visit <a href='http://www.bim-times.com'>http://www.bim-times.com</a> for more information.<br>
 * 
*********************************************************************************************************/
public class YGDataReceive  extends Thread{
    
    private static Socket socket = null;
    private static String serverHost = "192.168.2.200";  
    private static final int PORT = 9000;  
    byte[] b = new byte[1024];  
    public YGDataReceive(){
        try {
            socket = newThe Socket (ServerHost, PORT); // establish a socket connection 
        } the catch (IOException E) { 
            e.printStackTrace (); 
        } 
    } 
    
    public  void RUN () {
         the while ( to true ) {
             // stop reading sent from the server message 
            the InputStream OIS = null ; 
            DataInputStream DIS = null ;  
             the try { 
                OIS = Socket.getInputStream (); 
                DIS = new new  DataInputStream (OIS);  
                dis.read (B);   
                // String = serverToClient new new String (hexEncode (B));   
                System.out.println ( "information returned from the server to the client:" + printHexString (B));     
            } the catch (Exception E) { 
                e.printStackTrace (); 
            } 
        } 
    } 
    
    public  static  void main (String [] args) { 
        YGDataReceive MSG = new new YGDataReceive (); 
        msg.start (); 
    } 
    
    / ** 
     * Hex decoding 
     * @param INPUT 
     * @return 
     * / 
    public  static byte [] hexDecode (String INPUT) {
         the try {
             return Hex.decodeHex (input.toCharArray ()); 
        } the catch (Exception E) { 
            e.printStackTrace (); 
        } 
        return  null ; 
    } 
    
    / ** 
     * Hex coding 
     * @param INPUT 
     * @return 
     * / 
    public  static String hexEncode ( byte [] INPUT) {
         return Hex.encodeHexString (INPUT); 
    } 

    
    // the specified byte array to print console 13911750029 hexadecimal form 
        public  static String printHexString (byte[] b) { 
            String sd="";
           for (int i = 0; i < b.length; i++) {   
             String hex = Integer.toHexString(b[i] & 0xFF);   
             if (hex.length() == 1) {   
               hex = '0' + hex;   
             }   
             System.out.print(hex.toUpperCase() +"  ");
             sd=sd+hex.toUpperCase();
           } 
           System.out.println("sd:"+sd);
           String str =getPosition(sd);
           return str;
        } 
        
        public static String getPosition(String str){
            String position_msg ="";
            if(str!=null){
                System.out.println("---str.length="+str.length());
                //if(str.length()==40){
                String strID = str.substring(12, 16);
                String strX = str.substring(16, 24);
                String strY = str.substring(24, 32);
                
                String strZ = str.substring(32, 40);
                System.out.println("-----------------------------------");
                System.out.println(strID);
                System.out.println(strX);
                System.out.println(strY);
                System.out.println(strZ);
                
                String endStr="FFFF";
                
                if(!strID.endsWith(endStr)&&!strX.endsWith(endStr)&&!strY.endsWith(endStr)&&!strZ.endsWith(endStr))
                {
                    //System.out.println("ID:"+getInt(getDivLine(str.substring(12, 16)))+"  x:"+getDouble(getDivLine(str.substring(16, 24)))+"  y:"+getDouble(getDivLine(str.substring(24, 32)))+"  z:"+getDouble(getDivLine(str.substring(32, 40))));
                    System.out.println("ID:"+getInt(getDivLine(str.substring(12, 16)))+"  x:"+getDouble(getDivLine(strX))+"  y:"+getDouble(getDivLine(strY))+"  z:"+getDouble(getDivLine(strZ)));
                    position_msg = "ID:"+getInt(getDivLine(str.substring(12, 16)))+"  x:"+getDouble(getDivLine(str.substring(16, 24)))+"  y:"+getDouble(getDivLine(str.substring(24, 32)))+"  z:"+getDouble(getDivLine(str.substring(32, 40)));
                    return position_msg;
                }
                    
                //}
            }
            return null;
        }
            
        public static String getDivLine(String str){
            String result ="";
            if(str.length()==4){
                result = str.substring(2, 4)+str.substring(0, 2);
            }else if(str.length()==8){
                result = str.substring(4, 8)+str.substring(2, 4)+str.substring(0, 2);
            }else{
                result ="0000";
            }
            
            return result;
        }
        
        public static double getDouble(String str){
            Double d = Double.valueOf(Integer.parseInt(str,16));
            return d;
        }
        

        public static int getInt(String str){
            return Integer.parseInt(str,16);
        }
        
        
}

 

Guess you like

Origin www.cnblogs.com/herd/p/11912699.html