package tbDataModel_Dell;
|
import java.math.BigInteger;
|
import java.util.LinkedHashMap;
|
import BaoWen.Dell_55AA03;
|
import Frame.AnchorSet;
|
import Method.GetNowTime;
|
public class ReadPeizhiMessage {
|
|
/**±£´æÅäÖÃÐÅÏ¢
|
* @param anchorid»ùÕ¾id
|
* @param gonglv»ùÕ¾¹¦ÂÊ
|
* @param wucha»ùÕ¾Îó²î
|
* @param lvboÂ˲¨²ÎÊý
|
* @param zu×é
|
* @param hzƵÂÊ
|
* @param shangxianͨѶÊýÁ¿ÉÏÏÞ
|
* @param rootanchorͬ²½»ùÕ¾
|
* @param xuhaoͬ²½»ùÕ¾ÀàÐÍ0ÆÕͨ»ùÕ¾£¬1Ö÷»úÕ¾£¬2ÊÇ´Ó»ùÕ¾*/
|
public static byte[] save(
|
String anchorid,
|
String gonglv,
|
String wucha,
|
String lvbo,
|
String zu,
|
String hz,
|
String shangxian,
|
String type,
|
String nearnum,
|
String near1,
|
String near2,
|
String near3,
|
String near4,
|
String near5,
|
String near6,
|
String near7,
|
String near8,
|
String near9,
|
String near10,
|
String qiehuan,
|
String initiative,
|
String heart,
|
String rootanchor,
|
String xuhao,
|
String jiaozhungao
|
) {
|
byte[] data=null;
|
if(Dell_55AA03.isReadpeizhi_succ()) {
|
|
int[] value=new int[36];
|
|
//É豸id 0x4
|
value[0]=covert(anchorid);
|
|
//±êǩͨѶ¼ä¸ô 0x6
|
value[1]=Integer.parseInt(hz);
|
|
//µ¥´ÎͨѶ»ùÕ¾ÊýÁ¿ÉÏÏÞ
|
value[2]=Integer.parseInt(shangxian);
|
|
//0xA ͨѶ×éID£¨2Byte£©
|
value[3]=Integer.parseInt(zu);
|
|
//0xC ¾àÀëУ׼ֵ£¨2Byte£©
|
value[4]=Integer.parseInt(wucha);
|
|
//0xE Ä£¿éÀàÐÍ£¨2Byte£©
|
value[5]=1;
|
if(type.equals("0")) {
|
value[5]=0;
|
}
|
|
//0x10 »ùÕ¾Ö÷¶¯²â¾à£¨2Byte£©
|
value[6]=0;
|
if(initiative.equals("1")) {
|
value[6]=1;
|
}
|
|
|
//0x12 ±¨¾¯É豸£¨2Byte£©
|
value[7]=0;
|
|
//0x14 ±¨¾¯¾àÀë1£¨2Byte£©
|
value[8]=Integer.parseInt(qiehuan);;
|
|
//0x16 ±¨¾¯¾àÀë2£¨2Byte£©
|
value[9]=0;
|
|
//0x18 ±¨¾¯¾àÀë3£¨2Byte£©
|
value[10]=0;
|
|
//0x1A Åä¶ÔIDÎÞ×÷Óã¨2Byte£©
|
value[11]=0;
|
|
//0x1C ÐÄÌø°ü£¨2Byte£©
|
value[12]=0;
|
if(heart.equals("1")) {
|
value[12]=1;
|
}
|
|
//0x1E Modbusģʽ£¨2Byte£©
|
value[13]=0;
|
|
value[14]=Integer.parseInt(nearnum);
|
value[15]=covert(near1);
|
value[16]=covert(near2);
|
value[17]=covert(near3);
|
value[18]=covert(near4);
|
value[19]=covert(near5);
|
value[20]=covert(near6);
|
value[21]=covert(near7);
|
value[22]=covert(near8);
|
value[23]=covert(near9);
|
value[24]=covert(near10);
|
|
//·¢É书ÂÊ
|
value[25]=Integer.parseInt(gonglv);
|
|
//¼ÓËÙ¶ÈÁéÃô¶È
|
value[26]=2;
|
|
//ÐÝÃßʱ¼ä
|
value[27]=120;
|
|
//Õñ¶¯Ê¹ÄÜ
|
value[28]=0;
|
|
|
//¼ÓËÙ¶ÈʹÄÜ
|
value[29]=0;
|
|
|
//±êǩϷ¢ÅäÖÃ״̬
|
value[30]=Integer.parseInt(lvbo);
|
|
//±êǩϷ¢ÅäÖÃID 0x42
|
value[31]=0;
|
|
//ͬ²½»ùÕ¾µØÖ· 0x44
|
value[32]=covert(rootanchor);
|
|
//ͬ²½ÀàÐÍ0/1/2(0ÆÕͨ»ùÕ¾£¬1Ö÷»úÕ¾£¬2ÊÇ´Ó»ùÕ¾)46
|
value[33]=Integer.parseInt(xuhao);
|
|
//µØÖ·48
|
value[34]=0;
|
|
//µØÖ·50,ÆøÑ¹¼Æ¸ß¶ÈУ׼ֵ
|
value[35]=Integer.parseInt(jiaozhungao);
|
|
//±£´æÅäÖÃÐÅÏ¢
|
data=WriteDatapeiz((byte)0x4,(byte)0x48, value);
|
AnchorSet.jt_area.setText(GetNowTime.now2()+":±£´æÅäÖóɹ¦...");
|
|
}else {
|
AnchorSet.jt_area.setText(GetNowTime.now2()+": \n±£´æÅäÖÃʧ°Ü,ÇëÏȶÁÈ¡É豸ÅäÖÃÐÅÏ¢...");
|
}
|
return data;
|
}
|
|
|
/**ÐÞ¸ÄËùÓлùÕ¾*/
|
public static byte[] alert_all_anchor(
|
String gonglv,
|
String wucha,
|
String lvbo,
|
String zu,
|
String hz,
|
String shangxian,
|
String rootanc,
|
String xuhao
|
) {
|
|
int[] value=new int[30];
|
//±êǩͨѶ¼ä¸ô 0x6
|
value[0]=Integer.parseInt(hz);
|
|
//µ¥´ÎͨѶ»ùÕ¾ÊýÁ¿ÉÏÏÞ
|
value[1]=Integer.parseInt(shangxian);
|
|
//0xA ͨѶ×éID£¨2Byte£©
|
value[2]=Integer.parseInt(zu);
|
|
//0xC ¾àÀëУ׼ֵ£¨2Byte£©
|
value[3]=Integer.parseInt(wucha);
|
|
//0xE Ä£¿éÀàÐÍ£¨2Byte£©
|
value[4]=0;
|
|
//0x10 »ùÕ¾Ö÷¶¯²â¾à£¨2Byte£©
|
value[5]=0;
|
|
//0x12 ±¨¾¯É豸£¨2Byte£©
|
value[6]=0;
|
|
//0x14 ±¨¾¯¾àÀë1£¨2Byte£©
|
value[7]=0;
|
|
//0x16 ±¨¾¯¾àÀë2£¨2Byte£©
|
value[8]=0;
|
|
//0x18 ±¨¾¯¾àÀë3£¨2Byte£©
|
value[9]=0;
|
|
//0x1A Åä¶ÔIDÎÞ×÷Óã¨2Byte£©
|
value[10]=0;
|
|
//0x1C ÐÄÌø°ü£¨2Byte£©
|
value[11]=1;
|
|
//0x1E Modbusģʽ£¨2Byte£©
|
value[12]=0;
|
|
value[13]=0;
|
value[14]=0;
|
value[15]=0;
|
value[16]=0;
|
value[17]=0;
|
value[18]=0;
|
value[19]=0;
|
value[20]=0;
|
value[21]=0;
|
value[22]=0;
|
value[23]=0;
|
|
//·¢É书ÂÊ
|
value[24]=Integer.parseInt(gonglv);
|
|
//¼ÓËÙ¶ÈÁéÃô¶È
|
value[25]=2;
|
|
//ÐÝÃßʱ¼ä
|
value[26]=120;
|
|
//Õñ¶¯Ê¹ÄÜ
|
value[27]=0;
|
|
|
//¼ÓËÙ¶ÈʹÄÜ
|
value[28]=0;
|
|
//Â˲¨²ÎÊý
|
value[29]=Integer.parseInt(lvbo);
|
|
//±êǩϷ¢ÅäÖÃID
|
value[30]=0;
|
|
//ͬ²½»ùÕ¾ID
|
value[31]=covert(rootanc);
|
|
//ͬ²½»ùÕ¾½ÇÉ«
|
value[32]=Integer.parseInt(xuhao);
|
|
byte[] data=WriteDatapeiz((byte)0x6,(byte)0x3F, value);
|
AnchorSet.jt_area.setText(GetNowTime.now2()+":Ð޸ijÉ...");
|
|
|
return data;
|
}
|
|
/**д±£´æÅäÖÃ
|
* @param ref ÆðʼµØÖ·
|
* @param lenth Êý¾Ý³¤¶È
|
* @param value дÈëÖµ*/
|
public static byte[] WriteDatapeiz(byte ref ,byte lenth,int[] value) {
|
byte[] buf =new byte[9+lenth];
|
byte[] buf1 =new byte[5+lenth];
|
//°üÍ·
|
buf[0]=(byte) 0x55;
|
//°üÍ·
|
buf[1]=(byte) 0xAA;
|
//Ö¸ÁîÀàÐÍ
|
buf1[0]=(byte) 0x03;
|
//Êý¾Ý³¤¶È
|
buf1[1]=(byte) ((byte) 5+lenth);
|
//¶Áģʽ
|
buf1[2]=(byte) 0x02;
|
//ÆðʼµØÖ·
|
buf1[3]=(byte) ref;
|
|
//¶Áд³¤¶È
|
buf1[4]=(byte) lenth;
|
|
for(int i=0;i<value.length;i++) {
|
buf1[5+2*i]=intToRegisters(value[i])[3];
|
buf1[6+2*i]=intToRegisters(value[i])[2];
|
}
|
|
for(int i=0;i<buf1.length;i++) {
|
buf[i+2]=buf1[i];
|
}
|
//УÑéÂë
|
buf[buf.length-2]=Jiaoyan.check(buf1)[1];
|
buf[buf.length-1]=Jiaoyan.check(buf1)[0];
|
|
return buf;
|
}
|
|
/**±£´æÁÙ½ü»ùÕ¾ÅäÖÃ*/
|
public static byte[] save_nerby(String[] anchornearid,int distance,int baoliu1,int baoliu2 ) {
|
int size=anchornearid.length+2;
|
int lenth=size*2;
|
byte[] buf =new byte[19+lenth];
|
byte[] buf1 =new byte[15+lenth];
|
//°üÍ·
|
buf[0]=(byte) 0x55;
|
//°üÍ·
|
buf[1]=(byte) 0xAA;
|
//Ö¸ÁîÀàÐÍ
|
buf1[0]=(byte) 0x03;
|
//Êý¾Ý³¤¶È
|
buf1[1]=(byte) (15+lenth);
|
//¶Áģʽ
|
buf1[2]=(byte) 0x02;
|
//ÆðʼµØÖ·
|
buf1[3]=(byte) 0x14;
|
|
//¶Áд³¤¶È
|
buf1[4]=(byte) (lenth+10);
|
|
//Çл»¾àÀë
|
buf1[5]=intToRegisters(distance)[3];
|
buf1[6]=intToRegisters(distance)[2];
|
|
|
//»ùÕ¾×îÔ¶²âÁ¿·¶Î§
|
buf1[7]=intToRegisters(baoliu1)[3];
|
buf1[8]=intToRegisters(baoliu1)[2];
|
|
//Ö»Êä³ö±¾»ùվΪÖ÷»ùÕ¾µÄÊý¾Ý
|
buf1[9]=intToRegisters(baoliu2)[3];
|
buf1[10]=intToRegisters(baoliu2)[2];
|
|
//Åä¶ÔID
|
buf1[11]= (byte)0x0;
|
buf1[12]= (byte)0x0;
|
|
//ÐÄÌø°ü,¿ªÆôÐÄÌø°ü
|
buf1[13]= (byte)0x01;
|
buf1[14]= (byte)0x0;
|
|
//MODBUSģʽ
|
buf1[15]= (byte)0x0;
|
buf1[16]= (byte)0x0;
|
|
//ÁÙ½ü»ùÕ¾ÊýÁ¿
|
int nearnum=anchornearid.length;
|
buf1[17]=int_to_Byt(nearnum)[1];
|
buf1[18]=int_to_Byt(nearnum)[0];
|
|
|
for(int i=0;i<nearnum;i++) {
|
buf1[19+i*2]=toByteArray(anchornearid[i])[1];
|
buf1[20+i*2]=toByteArray(anchornearid[i])[0];
|
}
|
|
for(int i=0;i<buf1.length;i++) {
|
buf[i+2]=buf1[i];
|
}
|
//УÑéÂë
|
buf[buf.length-2]=Jiaoyan.check(buf1)[1];
|
buf[buf.length-1]=Jiaoyan.check(buf1)[0];
|
|
|
return buf;
|
|
}
|
|
/**д±£´æÇл»¾àÀë
|
* @param ref ÆðʼµØÖ·
|
* @param lenth Êý¾Ý³¤¶È
|
* @param value дÈëÖµ*/
|
public static byte[] Write(byte ref ,byte lenth,int[] value) {
|
byte[] buf =new byte[9+lenth];
|
byte[] buf1 =new byte[5+lenth];
|
//°üÍ·
|
buf[0]=(byte) 0x55;
|
//°üÍ·
|
buf[1]=(byte) 0xAA;
|
//Ö¸ÁîÀàÐÍ
|
buf1[0]=(byte) 0x03;
|
//Êý¾Ý³¤¶È
|
buf1[1]=(byte) ((byte) 5+lenth);
|
//¶Áģʽ
|
buf1[2]=(byte) 0x02;
|
//ÆðʼµØÖ·
|
buf1[3]=(byte) ref;
|
|
//¶Áд³¤¶È
|
buf1[4]=(byte) lenth;
|
|
|
for(int i=0;i<value.length;i++) {
|
//Çл»¾àÀë
|
buf1[5+2*i]=intToRegisters(value[i])[3];
|
buf1[6+2*i]=intToRegisters(value[i])[2];
|
}
|
|
|
for(int i=0;i<buf1.length;i++) {
|
buf[i+2]=buf1[i];
|
}
|
//УÑéÂë
|
buf[buf.length-2]=Jiaoyan.check(buf1)[1];
|
buf[buf.length-1]=Jiaoyan.check(buf1)[0];
|
return buf;
|
}
|
|
/**ÅäÖÃдÈë»ùÕ¾£¬Ö÷ÒªÓÃÓÚдÈëÁÙ½üºÍºÍͬ²½
|
* @param ÆðʼµØÖ·
|
* @param Êý¾Ý³¤¶È
|
* @param дÈëµÄ¾ßÌåÖµ16½øÖÆ×Ö·û´®*/
|
public static byte[] Write_in_anchor(byte ref,byte lenth,String[] hex) {
|
byte[] buf =new byte[9+lenth];
|
byte[] buf1 =new byte[5+lenth];
|
//°üÍ·
|
buf[0]=(byte) 0x55;
|
//°üÍ·
|
buf[1]=(byte) 0xAA;
|
//Ö¸ÁîÀàÐÍ
|
buf1[0]=(byte) 0x03;
|
//Êý¾Ý³¤¶È
|
buf1[1]=(byte) ((byte)5+lenth);
|
//¶Áģʽ
|
buf1[2]=(byte) 0x02;
|
//ÆðʼµØÖ·
|
buf1[3]=(byte) ref;
|
|
//¶Áд³¤¶È
|
buf1[4]=(byte) lenth;
|
|
|
for(int i=0;i<hex.length;i++) {
|
buf1[5+i*2]=toByteArray(hex[i])[1];
|
buf1[6+i*2]=toByteArray(hex[i])[0];
|
}
|
|
|
for(int i=0;i<buf1.length;i++) {
|
buf[i+2]=buf1[i];
|
}
|
//УÑéÂë
|
buf[buf.length-2]=Jiaoyan.check(buf1)[1];
|
buf[buf.length-1]=Jiaoyan.check(buf1)[0];
|
return buf;
|
}
|
|
|
|
public static byte[] intToRegisters(int v) {
|
byte[] registers = new byte[4];
|
registers[0] = (byte) (0xff & (v >> 24));
|
registers[1] = (byte) (0xff & (v >> 16));
|
registers[2] = (byte) (0xff & (v >> 8));
|
registers[3] = (byte) (0xff & v);
|
return registers;
|
}
|
|
|
/**
|
* @param: [content]
|
* @return: int
|
* @description: Ê®Áù½øÖÆ×ªÊ®½øÖÆ
|
*/
|
public static int covert(String content){
|
int number=0;
|
String [] HighLetter = {"A","B","C","D","E","F"};
|
LinkedHashMap<String,Integer> map = new LinkedHashMap<>();
|
for(int i = 0;i <= 9;i++){
|
map.put(i+"",i);
|
}
|
for(int j= 10;j<HighLetter.length+10;j++){
|
map.put(HighLetter[j-10],j);
|
}
|
String[] str = new String[content.length()];
|
for(int i = 0; i < str.length; i++){
|
str[i] = content.substring(i,i+1);
|
}
|
for(int i = 0; i < str.length; i++){
|
number += map.get(str[i])*Math.pow(16,str.length-1-i);
|
}
|
return number;
|
}
|
|
|
/**½ØÈ¡Ö¸¶¨³¤¶ÈµÄBYTEÊý×é
|
* @param srcÔ×Ö½ÚÊý×é
|
* @param ¿ªÊ¼Î»ÖÃ
|
* @param ½ØÈ¡³¤¶È*/
|
public static byte[] subBytes(byte[] src, int begin, int count) {
|
byte[] bs = new byte[count];
|
System.arraycopy(src, begin, bs, 0, count);
|
return bs;
|
}
|
|
/**
|
* ½«byte[]תΪ¸÷ÖÖ½øÖƵÄ×Ö·û´®
|
* @param bytes byte[]
|
* @param radix »ùÊý¿ÉÒÔת»»½øÖƵķ¶Î§£¬´ÓCharacter.MIN_RADIXµ½Character.MAX_RADIX£¬³¬³ö·¶Î§ºó±äΪ10½øÖÆ
|
* @return ת»»ºóµÄ×Ö·û´®
|
*/
|
public static String binary(byte[] bytes, int radix){
|
return new BigInteger(1, bytes).toString(radix);// ÕâÀïµÄ1´ú±íÕýÊý
|
}
|
|
|
private static final char[] HEXES = {
|
'0', '1', '2', '3',
|
'4', '5', '6', '7',
|
'8', '9', 'a', 'b',
|
'c', 'd', 'e', 'f'
|
};
|
|
/**
|
* byteÊý×é ת»»³É 16½øÖÆÐ¡Ð´×Ö·û´®
|
*/
|
public static String bytes2Hex(byte[] bytes) {
|
if (bytes == null || bytes.length == 0) {
|
return null;
|
}
|
|
StringBuilder hex = new StringBuilder();
|
|
for (byte b : bytes) {
|
hex.append(HEXES[(b >> 4) & 0x0F]);
|
hex.append(HEXES[b & 0x0F]);
|
}
|
|
return hex.toString();
|
}
|
|
/**16½øÖÆ×ªÎª10½øÖÆ*/
|
public static int decodeHEX(String hexs){
|
BigInteger bigint=new BigInteger(hexs, 16);
|
int numb=bigint.intValue();
|
return numb;
|
|
}
|
|
/**½«10½øÖÆÊý×éתΪ2×Ö½ÚµÄ16½øÖÆÔÚתΪbytÊý×éÊä³ö*/
|
public static byte[] int_to_Byt(int b) {
|
String a=String.format("%04x", b);
|
final byte[] byteArray = new byte[a.length() / 2];
|
int k = 0;
|
for (int i = 0; i < byteArray.length; i++) {//ÒòΪÊÇ16½øÖÆ£¬×î¶àÖ»»áÕ¼ÓÃ4λ£¬×ª»»³É×Ö½ÚÐèÒªÁ½¸ö16½øÖƵÄ×Ö·û£¬¸ßλÔÚÏÈ
|
byte high = (byte) (Character.digit(a.charAt(k), 16) & 0xff);
|
byte low = (byte) (Character.digit(a.charAt(k + 1), 16) & 0xff);
|
byteArray[i] = (byte) (high << 4 | low);
|
k += 2;
|
}
|
return byteArray;
|
}
|
/**
|
* 16½øÖƵÄ×Ö·û´®±íʾת³É×Ö½ÚÊý×é
|
*
|
* @param hexString 16½øÖƸñʽµÄ×Ö·û´®
|
* @return ת»»ºóµÄ×Ö½ÚÊý×é
|
**/
|
public static byte[] toByteArray(String hexString) {
|
hexString = hexString.replaceAll(" ", "");
|
final byte[] byteArray = new byte[hexString.length() / 2];
|
int k = 0;
|
for (int i = 0; i < byteArray.length; i++) {//ÒòΪÊÇ16½øÖÆ£¬×î¶àÖ»»áÕ¼ÓÃ4λ£¬×ª»»³É×Ö½ÚÐèÒªÁ½¸ö16½øÖƵÄ×Ö·û£¬¸ßλÔÚÏÈ
|
byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff);
|
byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff);
|
byteArray[i] = (byte) (high << 4 | low);
|
k += 2;
|
}
|
return byteArray;
|
}
|
|
|
|
}
|