¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.yzh.commons.util; |
| | | |
| | | import org.apache.commons.codec.binary.Hex; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.io.StringWriter; |
| | | import java.math.BigInteger; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author yezhihao |
| | | * https://gitee.com/yezhihao/jt808-server |
| | | */ |
| | | public class Byte2NumberUtils { |
| | | public static Integer bytesToInteger(byte[] bArray) { |
| | | try { |
| | | return Integer.valueOf(Hex.encodeHexString(bArray),16) ; |
| | | }catch (Exception e){ |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | |
| | | int å¹³å°ä¸è¡æ¶æ¯ä¿ç = 0x8F00 - 0x8FFF; |
| | | int ååèªå®ä¹ä¸è¡æ¶æ¯ = 0xE000 - 0xEFFF;//2019 new |
| | | int åèªå®ä¹ä¸è¡æ¶æ¯ = 0xF000 - 0xFFFF;//2019 new |
| | | int ç»ç«¯æ ¡æ¶è¯·æ±ä¸è¡ = 0x0F01;// |
| | | } |
| | |
| | | .addSchema(AttributeKey.AlarmTPMS, ProtostarUtil.getRuntimeSchema(AlarmTPMS.class, 0)) |
| | | |
| | | .addSchema(AttributeKey.InstallErrorMsg, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.Battery, NumberSchema.BYTE_BYTE) |
| | | .addSchema(AttributeKey.Battery, Battery.SCHEMA) |
| | | .addSchema(AttributeKey.Battery0102, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.Battery0304, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.Battery0506, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.ExtendLength, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.CarDoorStatus, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.CarWindowStatus, NumberSchema.DWORD_INT) |
| | |
| | | .addSchema(AttributeKey.DriverBehaviorAlarm, NumberSchema.WORD_INT) |
| | | |
| | | .addSchema(AttributeKey.Signal, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.Battery, Battery.SCHEMA) |
| | | .addSchema(AttributeKey.Battery0102, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.Battery0304, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.Battery0506, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.IoState, NumberSchema.WORD_INT) |
| | | .addSchema(AttributeKey.AnalogQuantity, NumberSchema.DWORD_INT) |
| | | .addSchema(AttributeKey.SignalStrength, NumberSchema.BYTE_INT) |
| | |
| | | * https://gitee.com/yezhihao/jt808-server |
| | | */ |
| | | public interface AttributeKey { |
| | | Long Mileage = 1L; // 0x01 éç¨,æ°æ®ç±»å为DWORD,åä½ä¸º1/10km,对åºè½¦ä¸éç¨è¡¨è¯»æ° |
| | | Long Fuel = 2L; // 0x02 æ²¹é,æ°æ®ç±»å为WORD,åä½ä¸º1/10L,对åºè½¦ä¸æ²¹éè¡¨è¯»æ° |
| | | Long Speed = 3L; // 0x03 è¡é©¶è®°å½åè½è·åçé度,æ°æ®ç±»å为WORD,åä½ä¸º1/10km/h |
| | | Long AlarmEventId = 4L; // 0x04 éè¦äººå·¥ç¡®è®¤æ¥è¦äºä»¶çID,æ°æ®ç±»å为WORD,ä»1å¼å§è®¡æ° |
| | | Long TirePressure = 5L; // 0x05 èå,åä½ä¸ºPa,æ å®è½®åç顺åºä¸ºä»è½¦å¤´å¼å§ä»å·¦å°å³é¡ºåºæå,å¤ä½çåè为0xFF,è¡¨ç¤ºæ ææ°æ® |
| | | Long CarriageTemperature = 6L; // 0x06 è½¦å¢æ¸©åº¦,åä½ä¸ºææ°åº¦,åå¼èå´ä¸º-32767~+32767,æé«ä½ä¸º1è¡¨ç¤ºè´æ° |
| | | Long OverSpeedAlarm = 17L; // 0x11 è¶
鿥è¦éå ä¿¡æ¯è§è¡¨28 |
| | | Long InOutAreaAlarm = 18L; // 0x12 è¿åºåºå/路线æ¥è¦éå ä¿¡æ¯è§è¡¨29 |
| | | Long RouteDriveTimeAlarm = 19L; // 0x13 路段è¡é©¶æ¶é´ä¸è¶³/è¿é¿æ¥è¦éå ä¿¡æ¯è§è¡¨30 |
| | | Integer Mileage = 1; // 0x01 éç¨,æ°æ®ç±»å为DWORD,åä½ä¸º1/10km,对åºè½¦ä¸éç¨è¡¨è¯»æ° |
| | | Integer Fuel = 2; // 0x02 æ²¹é,æ°æ®ç±»å为WORD,åä½ä¸º1/10L,对åºè½¦ä¸æ²¹éè¡¨è¯»æ° |
| | | Integer Speed = 3; // 0x03 è¡é©¶è®°å½åè½è·åçé度,æ°æ®ç±»å为WORD,åä½ä¸º1/10km/h |
| | | Integer AlarmEventId = 4; // 0x04 éè¦äººå·¥ç¡®è®¤æ¥è¦äºä»¶çID,æ°æ®ç±»å为WORD,ä»1å¼å§è®¡æ° |
| | | Integer TirePressure = 5; // 0x05 èå,åä½ä¸ºPa,æ å®è½®åç顺åºä¸ºä»è½¦å¤´å¼å§ä»å·¦å°å³é¡ºåºæå,å¤ä½çåè为0xFF,è¡¨ç¤ºæ ææ°æ® |
| | | Integer CarriageTemperature = 6; // 0x06 è½¦å¢æ¸©åº¦,åä½ä¸ºææ°åº¦,åå¼èå´ä¸º-32767~+32767,æé«ä½ä¸º1è¡¨ç¤ºè´æ° |
| | | Integer OverSpeedAlarm = 17; // 0x11 è¶
鿥è¦éå ä¿¡æ¯è§è¡¨28 |
| | | Integer InOutAreaAlarm = 18; // 0x12 è¿åºåºå/路线æ¥è¦éå ä¿¡æ¯è§è¡¨29 |
| | | Integer RouteDriveTimeAlarm = 19; // 0x13 路段è¡é©¶æ¶é´ä¸è¶³/è¿é¿æ¥è¦éå ä¿¡æ¯è§è¡¨30 |
| | | |
| | | Long VideoRelatedAlarm = 20L; // 0x14 è§é¢ç¸å
³æ¥è¦,DWORD,æä½è®¾ç½®,æ å¿ä½å®ä¹è§è¡¨14 |
| | | Long VideoMissingStatus = 21L; // 0x15 è§é¢ä¿¡å·ä¸¢å¤±æ¥è¦ç¶æ,DWORD,æä½è®¾ç½®,bit0~bit31åå«è¡¨ç¤ºç¬¬1~32个é»è¾éé,ç¸åºä½ä¸º1å表示该é»è¾ééåçè§é¢ä¿¡å·ä¸¢å¤± |
| | | Long VideoObscuredStatus = 22L; // 0x16 è§é¢ä¿¡å·é®æ¡æ¥è¦ç¶æ,DWORD,æä½è®¾ç½®,bit0~bit31åå«è¡¨ç¤ºç¬¬1~32个é»è¾éé,ç¸åºä½ä¸º1å表示该é»è¾ééåçè§é¢ä¿¡å·é®æ¡ |
| | | Long StorageFailureStatus = 23L; // 0x17 åå¨å¨æ
鿥è¦ç¶æ,WORD,æä½è®¾ç½®.bit0~bit11åå«è¡¨ç¤ºç¬¬1~12个主åå¨å¨.bit12~bit15åå«è¡¨ç¤ºç¬¬1~4个ç¾å¤åå¨è£
ç½®,ç¸åºä½ä¸º1å表示该åå¨å¨åçæ
é |
| | | Long DriverBehaviorAlarm = 24L; // 0x18 å¼å¸¸é©¾é©¶è¡ä¸ºæ¥è¦è¯¦ç»æè¿°,WORD,å®ä¹è§è¡¨15 |
| | | Integer VideoRelatedAlarm = 20; // 0x14 è§é¢ç¸å
³æ¥è¦,DWORD,æä½è®¾ç½®,æ å¿ä½å®ä¹è§è¡¨14 |
| | | Integer VideoMissingStatus = 21; // 0x15 è§é¢ä¿¡å·ä¸¢å¤±æ¥è¦ç¶æ,DWORD,æä½è®¾ç½®,bit0~bit31åå«è¡¨ç¤ºç¬¬1~32个é»è¾éé,ç¸åºä½ä¸º1å表示该é»è¾ééåçè§é¢ä¿¡å·ä¸¢å¤± |
| | | Integer VideoObscuredStatus = 22; // 0x16 è§é¢ä¿¡å·é®æ¡æ¥è¦ç¶æ,DWORD,æä½è®¾ç½®,bit0~bit31åå«è¡¨ç¤ºç¬¬1~32个é»è¾éé,ç¸åºä½ä¸º1å表示该é»è¾ééåçè§é¢ä¿¡å·é®æ¡ |
| | | Integer StorageFailureStatus = 23; // 0x17 åå¨å¨æ
鿥è¦ç¶æ,WORD,æä½è®¾ç½®.bit0~bit11åå«è¡¨ç¤ºç¬¬1~12个主åå¨å¨.bit12~bit15åå«è¡¨ç¤ºç¬¬1~4个ç¾å¤åå¨è£
ç½®,ç¸åºä½ä¸º1å表示该åå¨å¨åçæ
é |
| | | Integer DriverBehaviorAlarm = 24; // 0x18 å¼å¸¸é©¾é©¶è¡ä¸ºæ¥è¦è¯¦ç»æè¿°,WORD,å®ä¹è§è¡¨15 |
| | | |
| | | Long Signal = 37L; // 0x25 æ©å±è½¦è¾ä¿¡å·ç¶æä½,åæ°é¡¹æ ¼å¼åå®ä¹è§è¡¨31 |
| | | Long IoState = 42L; // 0x2a I0ç¶æä½,åæ°é¡¹æ ¼å¼åå®ä¹è§è¡¨32 |
| | | Long AnalogQuantity = 43L; // 0x2b 模æé,bit[0~15],AD0L;bit[l6~31],ADl |
| | | Long SignalStrength = 48L; // 0x30 æ°æ®ç±»å为BYTE,æ 线éä¿¡ç½ç»ä¿¡å·å¼ºåº¦ |
| | | Long GnssCount = 49L; // 0x31 æ°æ®ç±»å为BYTE,GNSSå®ä½å«ææ° |
| | | Long AlarmADAS = 100L; // 0x64 é«çº§é©¾é©¶è¾
å©ç³»ç»æ¥è¦ |
| | | Long AlarmDSM = 101L; // 0x65 驾驶åç¶æçæµ |
| | | Long AlarmTPMS = 102L; // 0x66 è½®èæ°åçæµç³»ç» |
| | | Long AlarmBSD = 103L; // 0x67 ç²ç¹çæµ |
| | | Long InstallErrorMsg = 241L; // 0xF1 å®è£
å¼å¸¸ä¿¡æ¯,ç±åå®¶èªå®ä¹(粤æ ) |
| | | Long AlgorithmErrorMsg = 242L; // 0xF2 ç®æ³å¼å¸¸ä¿¡æ¯,ç±åå®¶èªå®ä¹(粤æ ) |
| | | Long Battery = 0Xe3L; // 0Xe3 data={0x01,0x02,0x03,0x04,0x05,0x06} çµæ± çµéæ¯ 0x0102ï¼çµæ± çµåæ¯0x0304ï¼å
çµçµåæ¯ 0x0506,çµåå使¯0.001vï¼ä¸ä¼ 1000表示 1vã |
| | | Long ExtendLength = 0Xf3L; // 0Xf3 n 表示åç»æ©å±æ°æ®æ»é¿åº¦ã为 OBDè¡è½¦æ°æ®é¡¹å®ä¹ãåç»å®ä¹çæ°æ®é¡¹è§è¡¨ 8-32å®ä¹(注æè¯¥å®ä¹çæ°æ®é¡¹ææå
æ¬ä½ä¸ä¸å®å
¨æ)ã |
| | | Long CarDoorStatus = 0xD0L; // 0xD0 车é¨éç¶æä½ï¼è§è¡¨ 8-24车é¨éç¶æä½ |
| | | Long CarWindowStatus = 0xD1L; // 0xD1 车çªç¶æä½ï¼è§è¡¨ 8-25车çªç¶æä½ã |
| | | Long SafetyBelt = 0xD2L; // 0xD2å®å
¨å¸¦ç¶æä½ï¼è§è¡¨ 8-26å®å
¨å¸¦ç¶æä½ã |
| | | Long CarAlermStatus = 0xD3L; // 0xD3车è¾è¦æ
ç¶æä½ï¼è§è¡¨ 8-27车è¾è¦æ
ç¶æä½ã |
| | | Long CarFaultStatus = 0xD4L; // 0xD4è½¦è¾æ
éç¶æä½ï¼è§è¡¨ 8-28è½¦è¾æ
éç¶æä½ã ã |
| | | Long CarGearStatus = 0xD5L; // 0xD5è½¦è¾æ¡£ä½ç¶æï¼è§è¡¨ 8-29è½¦è¾æ¡£ä½ç¶æã |
| | | Long CarTireStatus = 0xD6L; // 0xD6车è¾èåç¶æãï¼æ¯ä¸ªè½¦èä¿¡æ¯å ç¨ 5个åèï¼è§è¡¨ 8-30车è¾èåç¶æã |
| | | Long Temprature = 0xC0L; // 0xC0ï¼æç¬¦å·æ°ï¼åä½ 0.1度ã |
| | | Long BaseStationExtend = 0xEFL; // 0xEF åºç«éå æ°æ® |
| | | Integer Signal = 37; // 0x25 æ©å±è½¦è¾ä¿¡å·ç¶æä½,åæ°é¡¹æ ¼å¼åå®ä¹è§è¡¨31 |
| | | Integer IoState = 42; // 0x2a I0ç¶æä½,åæ°é¡¹æ ¼å¼åå®ä¹è§è¡¨32 |
| | | Integer AnalogQuantity = 43; // 0x2b 模æé,bit[0~15],AD0;bit[l6~31],ADl |
| | | Integer SignalStrength = 48; // 0x30 æ°æ®ç±»å为BYTE,æ 线éä¿¡ç½ç»ä¿¡å·å¼ºåº¦ |
| | | Integer GnssCount = 49; // 0x31 æ°æ®ç±»å为BYTE,GNSSå®ä½å«ææ° |
| | | Integer AlarmADAS = 100; // 0x64 é«çº§é©¾é©¶è¾
å©ç³»ç»æ¥è¦ |
| | | Integer AlarmDSM = 101; // 0x65 驾驶åç¶æçæµ |
| | | Integer AlarmTPMS = 102; // 0x66 è½®èæ°åçæµç³»ç» |
| | | Integer AlarmBSD = 103; // 0x67 ç²ç¹çæµ |
| | | Integer InstallErrorMsg = 241; // 0xF1 å®è£
å¼å¸¸ä¿¡æ¯,ç±åå®¶èªå®ä¹(粤æ ) |
| | | Integer AlgorithmErrorMsg = 242; // 0xF2 ç®æ³å¼å¸¸ä¿¡æ¯,ç±åå®¶èªå®ä¹(粤æ ) |
| | | Integer Battery = 0Xe3; // 0Xe3 data={0x01,0x02,0x03,0x04,0x05,0x06} çµæ± çµéæ¯ 0x0102ï¼çµæ± çµåæ¯0x0304ï¼å
çµçµåæ¯ 0x0506,çµåå使¯0.001vï¼ä¸ä¼ 1000表示 1vã |
| | | Integer Battery0102 = 0x0102; // 0Xe3 data={0x01,0x02,0x03,0x04,0x05,0x06} çµæ± çµéæ¯ 0x0102ï¼çµæ± çµåæ¯0x0304ï¼å
çµçµåæ¯ 0x0506,çµåå使¯0.001vï¼ä¸ä¼ 1000表示 1vã |
| | | Integer Battery0304 = 0x0304; // 0Xe3 data={0x01,0x02,0x03,0x04,0x05,0x06} çµæ± çµéæ¯ 0x0102ï¼çµæ± çµåæ¯0x0304ï¼å
çµçµåæ¯ 0x0506,çµåå使¯0.001vï¼ä¸ä¼ 1000表示 1vã |
| | | Integer Battery0506 = 0x0506; // 0Xe3 data={0x01,0x02,0x03,0x04,0x05,0x06} çµæ± çµéæ¯ 0x0102ï¼çµæ± çµåæ¯0x0304ï¼å
çµçµåæ¯ 0x0506,çµåå使¯0.001vï¼ä¸ä¼ 1000表示 1vã |
| | | Integer ExtendLength = 0Xf3; // 0Xf3 n 表示åç»æ©å±æ°æ®æ»é¿åº¦ã为 OBDè¡è½¦æ°æ®é¡¹å®ä¹ãåç»å®ä¹çæ°æ®é¡¹è§è¡¨ 8-32å®ä¹(注æè¯¥å®ä¹çæ°æ®é¡¹ææå
æ¬ä½ä¸ä¸å®å
¨æ)ã |
| | | Integer CarDoorStatus = 0xD0; // 0xD0 车é¨éç¶æä½ï¼è§è¡¨ 8-24车é¨éç¶æä½ |
| | | Integer CarWindowStatus = 0xD1; // 0xD1 车çªç¶æä½ï¼è§è¡¨ 8-25车çªç¶æä½ã |
| | | Integer SafetyBelt = 0xD2; // 0xD2å®å
¨å¸¦ç¶æä½ï¼è§è¡¨ 8-26å®å
¨å¸¦ç¶æä½ã |
| | | Integer CarAlermStatus = 0xD3; // 0xD3车è¾è¦æ
ç¶æä½ï¼è§è¡¨ 8-27车è¾è¦æ
ç¶æä½ã |
| | | Integer CarFaultStatus = 0xD4; // 0xD4è½¦è¾æ
éç¶æä½ï¼è§è¡¨ 8-28è½¦è¾æ
éç¶æä½ã ã |
| | | Integer CarGearStatus = 0xD5; // 0xD5è½¦è¾æ¡£ä½ç¶æï¼è§è¡¨ 8-29è½¦è¾æ¡£ä½ç¶æã |
| | | Integer CarTireStatus = 0xD6; // 0xD6车è¾èåç¶æãï¼æ¯ä¸ªè½¦èä¿¡æ¯å ç¨ 5个åèï¼è§è¡¨ 8-30车è¾èåç¶æã |
| | | Integer Temprature = 0xC0; // 0xC0ï¼æç¬¦å·æ°ï¼åä½ 0.1度ã |
| | | Integer BaseStationExtend = 0xEF; // 0xEF åºç«éå æ°æ® |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.yzh.protocol.commons.transform.attribute; |
| | | |
| | | import io.github.yezhihao.protostar.Schema; |
| | | import io.github.yezhihao.protostar.util.ByteBufUtils; |
| | | import io.netty.buffer.ByteBuf; |
| | | import org.yzh.commons.util.Byte2NumberUtils; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * èå 0x05 |
| | | * length 30 |
| | | */ |
| | | |
| | | public class Battery { |
| | | |
| | | public static final Integer key = 0Xe3; |
| | | |
| | | public static final Schema<Battery> SCHEMA = new TirePressureSchema(); |
| | | |
| | | private byte[] value; |
| | | private Integer capacity;//çµæ± çµé |
| | | private Float voltage;//çµæ± çµå |
| | | private Float chargeVoltage;//å
çµçµå |
| | | |
| | | public Integer getCapacity() { |
| | | return capacity; |
| | | } |
| | | |
| | | public void setCapacity(Integer capacity) { |
| | | this.capacity = capacity; |
| | | } |
| | | |
| | | public Float getVoltage() { |
| | | return voltage; |
| | | } |
| | | |
| | | public void setVoltage(Float voltage) { |
| | | this.voltage = voltage; |
| | | } |
| | | |
| | | public Float getChargeVoltage() { |
| | | return chargeVoltage; |
| | | } |
| | | |
| | | public void setChargeVoltage(Float chargeVoltage) { |
| | | this.chargeVoltage = chargeVoltage; |
| | | } |
| | | |
| | | public Battery() { |
| | | } |
| | | |
| | | /** |
| | | * byte[] data={0x01,0x02,0x03,0x04,0x05,0x06} |
| | | * çµæ± çµéæ¯ 0x0102ï¼ |
| | | * çµæ± çµåæ¯0x0304ï¼ |
| | | * å
çµçµåæ¯ 0x0506, |
| | | * çµåå使¯0.001vï¼ |
| | | * ä¸ä¼ 1000表示 1vã |
| | | * @param value |
| | | */ |
| | | public Battery(byte[] value) { |
| | | this.value = value; |
| | | if(value!=null && value.length>2){ |
| | | this.setCapacity(Byte2NumberUtils.bytesToInteger(new byte[]{value[0],value[1]})); |
| | | } |
| | | if(value!=null && value.length>4){ |
| | | try { |
| | | this.setVoltage((float) (Byte2NumberUtils.bytesToInteger(new byte[]{value[2],value[3]}) * 0.001)); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | if(value!=null && value.length>6){ |
| | | try { |
| | | this.setChargeVoltage((float) (Byte2NumberUtils.bytesToInteger(new byte[]{value[4],value[4]}) * 0.001)); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public byte[] getValue() { |
| | | return value; |
| | | } |
| | | |
| | | public void setValue(byte[] value) { |
| | | this.value = value; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | final StringBuilder sb = new StringBuilder(32); |
| | | sb.append("Battery{value=").append(Arrays.toString(value)); |
| | | sb.append('}'); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | private static class TirePressureSchema implements Schema<Battery> { |
| | | |
| | | private TirePressureSchema() { |
| | | } |
| | | |
| | | @Override |
| | | public Battery readFrom(ByteBuf input) { |
| | | int len = input.readableBytes(); |
| | | if (len > 30) |
| | | len = 30; |
| | | byte[] value = new byte[len]; |
| | | input.readBytes(value); |
| | | return new Battery(value); |
| | | } |
| | | |
| | | @Override |
| | | public void writeTo(ByteBuf output, Battery message) { |
| | | ByteBufUtils.writeFixedLength(output, 30, message.value); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import io.github.yezhihao.netmc.core.model.Response; |
| | | import io.github.yezhihao.protostar.annotation.Field; |
| | | import io.github.yezhihao.protostar.annotation.MergeSuperclass; |
| | | import io.github.yezhihao.protostar.annotation.Message; |
| | | import org.yzh.protocol.basics.JTMessage; |
| | | import org.yzh.protocol.commons.JT808; |
| | |
| | | * @author yezhihao |
| | | * https://gitee.com/yezhihao/jt808-server |
| | | */ |
| | | @MergeSuperclass |
| | | @Message(JT808.æ¥è¯¢ç»ç«¯å±æ§åºç) |
| | | public class T0107 extends JTMessage implements Response { |
| | | |
| | |
| | | |
| | | import io.github.yezhihao.protostar.annotation.Field; |
| | | import io.github.yezhihao.protostar.annotation.Message; |
| | | import io.swagger.models.auth.In; |
| | | import lombok.Data; |
| | | import org.yzh.protocol.basics.JTMessage; |
| | | import org.yzh.protocol.commons.JT808; |
| | | import org.yzh.protocol.commons.transform.AttributeConverter; |
| | |
| | | * https://gitee.com/yezhihao/jt808-server |
| | | */ |
| | | @Message(JT808.ä½ç½®ä¿¡æ¯æ±æ¥) |
| | | @Data |
| | | public class T0200 extends JTMessage { |
| | | |
| | | /** |
| | |
| | | private LocalDateTime deviceTime; |
| | | @Field(converter = AttributeConverter.class, desc = "ä½ç½®éå ä¿¡æ¯", version = {-1, 0}) |
| | | @Field(converter = AttributeConverterYue.class, desc = "ä½ç½®éå ä¿¡æ¯(粤æ )", version = 1) |
| | | private Map<Long, Object> attributes; |
| | | private Map<Integer, Object> attributes; |
| | | |
| | | public int getWarnBit() { |
| | | return warnBit; |
| | |
| | | this.deviceTime = deviceTime; |
| | | } |
| | | |
| | | public Map<Long, Object> getAttributes() { |
| | | return attributes; |
| | | } |
| | | |
| | | public void setAttributes(Map<Long, Object> attributes) { |
| | | this.attributes = attributes; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.ByteBufUtil; |
| | | import io.netty.buffer.Unpooled; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.junit.platform.commons.util.StringUtils; |
| | | import org.yzh.protocol.JT808Beans; |
| | | import org.yzh.protocol.basics.JTMessage; |
| | | import org.yzh.protocol.codec.JTMessageAdapter; |
| | | import org.yzh.protocol.codec.JTMessageDecoder; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è§£ç åæ |
| | |
| | | public static final JTMessageAdapter coder = new JTMessageAdapter("org.yzh.protocol"); |
| | | |
| | | public static void main(String[] args) { |
| | | String hex = "0200004c067244400211004600000000000c0400015b197c06c8362e00000000000025020610234801040000083f02020000030200002504000000002a0200002b0400000000300117310100e3060000129d0000f2020000497e"; |
| | | String hex = "0200004c06724440021104ad00000000000c000301e4c49606fcbc04003c00000000250213220412010400001a4e02020000030200002504000000002a0200002b0400000000300115310112e306000012990000f2020000ac7e"; |
| | | // String hex = "0201004e0672444002110097019100000000000c0001015b197c06c8362e00000000000025020616592601040000083f02020000030200002504000000002a0200002b0400000000300117310100e306000012990000f2020000187e"; |
| | | // String hex = "020000d40123456789017fff000004000000080006eeb6ad02633df7013800030063200707192359642f000000400101020a0a02010a1e00640001b2070003640e200707192359000100000061646173200827111111010101652f000000410202020a0000000a1e00c8000516150006c81c20070719235900020000000064736d200827111111020202662900000042031e012c00087a23000a2c2a200707192359000300000074706d732008271111110303030067290000004304041e0190000bde31000d90382007071923590004000000006273642008271111110404049d"; |
| | | JTMessage msg = H2019(T0200JSATL12()); |
| | | // JTMessage msg = H2019(T0200JSATL12()); |
| | | |
| | | msg = decode(hex); |
| | | // msg = decode(hex); |
| | | // hex = encode(msg); |
| | | // System.out.println(decode(hex)); |
| | | |
| | | try (FileInputStream fis = new FileInputStream(new File("C:\\Users\\T14\\Desktop\\member.xlsx")); |
| | | Workbook workbook = new XSSFWorkbook(fis)) { |
| | | Sheet sheet = workbook.getSheetAt(0); // è·å第ä¸ä¸ªå·¥ä½è¡¨ |
| | | List<String> phoneNumbers = new ArrayList<>(); |
| | | for (Row row : sheet) { |
| | | Cell cell = row.getCell(1); // åè®¾ææºå·å¨ç¬¬ä¸å |
| | | if (cell != null) { |
| | | if (cell.getCellType() == CellType.NUMERIC){ |
| | | System.out.println(cell.getCellType()); |
| | | phoneNumbers.add( cell.getNumericCellValue()+""); // æ·»å å°åè¡¨ä¸ |
| | | } |
| | | cell.setCellType(CellType.STRING); // ç¡®ä¿åå
æ ¼ç±»å为å符串 |
| | | String phoneNumber = cell.getStringCellValue(); // è·ååå
æ ¼å¼ä½ä¸ºå符串 |
| | | phoneNumbers.add( phoneNumber); // æ·»å å°åè¡¨ä¸ |
| | | } |
| | | } |
| | | // è¾åºææºå·å表 |
| | | phoneNumbers.forEach(System.out::println); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private static String encode(JTMessage message) { |
| | |
| | | |
| | | import io.github.yezhihao.protostar.util.KeyValuePair; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.swagger.models.auth.In; |
| | | import org.yzh.protocol.basics.JTMessage; |
| | | import org.yzh.protocol.commons.Action; |
| | | import org.yzh.protocol.commons.ShapeAction; |
| | |
| | | //ä½ç½®ä¿¡æ¯æ±æ¥ |
| | | public static T0200 T0200Attributes() { |
| | | T0200 bean = T0200(); |
| | | Map<Long, Object> attributes = new TreeMap<>(); |
| | | Map<Integer, Object> attributes = new TreeMap<>(); |
| | | attributes.put(AttributeKey.Mileage, 11); |
| | | attributes.put(AttributeKey.Fuel, 22); |
| | | attributes.put(AttributeKey.Speed, 33); |
| | |
| | | |
| | | |
| | | T0200 bean = T0200(); |
| | | Map<Long, Object> attributes = new TreeMap<>(); |
| | | attributes.put(Long.valueOf(AlarmADAS.key), alarmADAS); |
| | | attributes.put(Long.valueOf(AlarmDSM.key), alarmDSM); |
| | | attributes.put(Long.valueOf(AlarmTPMS.key), alarmTPMS); |
| | | attributes.put(Long.valueOf(AlarmBSD.key), alarmBSD); |
| | | Map<Integer, Object> attributes = new TreeMap<>(); |
| | | attributes.put( AlarmADAS.key, alarmADAS); |
| | | attributes.put( AlarmDSM.key, alarmDSM); |
| | | attributes.put( AlarmTPMS.key, alarmTPMS); |
| | | attributes.put( AlarmBSD.key, alarmBSD); |
| | | |
| | | bean.setAttributes(attributes); |
| | | return bean; |
| | |
| | | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| | | import io.github.yezhihao.protostar.annotation.Field; |
| | | import io.github.yezhihao.protostar.annotation.Message; |
| | | import lombok.Data; |
| | | import org.yzh.protocol.basics.JTMessage; |
| | | import org.yzh.protocol.commons.JT808; |
| | | import org.yzh.protocol.commons.transform.AttributeConverter; |
| | |
| | | * @author yezhihao |
| | | * https://gitee.com/yezhihao/jt808-server |
| | | */ |
| | | @JsonIgnoreProperties({"attributes", "alarmList", "dateTime", "messageId", "properties", "protocolVersion", "clientId", "serialNo", "packageTotal", "packageNo", "verified", "bodyLength", "encryption", "subpackage", "version", "reserved"}) |
| | | @JsonIgnoreProperties({"attributes", |
| | | "alarmList", |
| | | "dateTime", |
| | | "messageId", |
| | | "properties", |
| | | "protocolVersion", |
| | | "clientId", "serialNo", |
| | | "packageTotal", "packageNo", |
| | | "verified", |
| | | "bodyLength", |
| | | "encryption", |
| | | "subpackage", |
| | | "version", |
| | | "reserved"}) |
| | | @Message(JT808.ä½ç½®ä¿¡æ¯æ±æ¥) |
| | | @Data |
| | | public class T0200 extends JTMessage { |
| | | |
| | | @Field(length = 4, desc = "æ¥è¦æ å¿") |
| | |
| | | private LocalDateTime deviceTime; |
| | | @Field(converter = AttributeConverter.class, desc = "ä½ç½®éå ä¿¡æ¯", version = {-1, 0}) |
| | | @Field(converter = AttributeConverterYue.class, desc = "ä½ç½®éå ä¿¡æ¯(粤æ )", version = 1) |
| | | private Map<Long, Object> attributes; |
| | | private Map<Integer, Object> attributes; |
| | | |
| | | public int getWarnBit() { |
| | | return warnBit; |
| | |
| | | this.deviceTime = deviceTime; |
| | | } |
| | | |
| | | public Map<Long, Object> getAttributes() { |
| | | return attributes; |
| | | } |
| | | |
| | | public void setAttributes(Map<Long, Object> attributes) { |
| | | this.attributes = attributes; |
| | | } |
| | | |
| | | public int getAttributeInt(int key) { |
| | | if (attributes != null) { |
| | |
| | | package org.yzh.web.endpoint; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import io.github.yezhihao.netmc.core.annotation.Async; |
| | | import io.github.yezhihao.netmc.core.annotation.AsyncBatch; |
| | | import io.github.yezhihao.netmc.core.annotation.Endpoint; |
| | | import io.github.yezhihao.netmc.core.annotation.Mapping; |
| | | import io.github.yezhihao.netmc.session.Session; |
| | | import org.apache.commons.codec.binary.Hex; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.yzh.web.model.enums.SessionKey; |
| | | import org.yzh.web.service.FileService; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigInteger; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Properties; |
| | | |
| | | import static org.yzh.protocol.commons.JT808.*; |
| | | |
| | |
| | | |
| | | @Mapping(types = ç»ç«¯å¿è·³, desc = "ç»ç«¯å¿è·³") |
| | | public void T0002(JTMessage message, Session session) { |
| | | log.info("ç»ç«¯å¿è·³========={}", JSONObject.toJSONString(message)); |
| | | } |
| | | |
| | | @Mapping(types = ç»ç«¯æ³¨é, desc = "ç»ç«¯æ³¨é") |
| | |
| | | |
| | | @Mapping(types = ç»ç«¯è¡¥ä¼ åå
请æ±, desc = "ç»ç«¯è¡¥ä¼ åå
请æ±") |
| | | public void T8003(T8003 message, Session session) { |
| | | } |
| | | @Mapping(types = ç»ç«¯æ ¡æ¶è¯·æ±ä¸è¡, desc = "ç»ç«¯æ ¡æ¶è¯·æ±ä¸è¡") |
| | | public void T0F01(JTMessage message, Session session) { |
| | | } |
| | | |
| | | @Mapping(types = ç»ç«¯æ³¨å, desc = "ç»ç«¯æ³¨å") |
| | |
| | | |
| | | @Mapping(types = æ¥è¯¢ç»ç«¯å±æ§åºç, desc = "æ¥è¯¢ç»ç«¯å±æ§åºç") |
| | | public void T0107(T0107 message, Session session) { |
| | | log.info("æ¥è¯¢ç»ç«¯å±æ§åºç========={}", JSONObject.toJSONString(message)); |
| | | session.response(message); |
| | | } |
| | | |
| | |
| | | @AsyncBatch(poolSize = 2, maxElements = 4000, maxWait = 1000) |
| | | @Mapping(types = ä½ç½®ä¿¡æ¯æ±æ¥, desc = "ä½ç½®ä¿¡æ¯æ±æ¥") |
| | | public void T0200(List<T0200> list) { |
| | | |
| | | System.out.println(JSONObject.toJSONString(list) |
| | | ); |
| | | } |
| | | |
| | | @Mapping(types = å®ä½æ°æ®æ¹éä¸ä¼ , desc = "å®ä½æ°æ®æ¹éä¸ä¼ ") |
| | | public void T0704(T0704 message) { |
| | | } |
| | | public static String bcd2String(byte[] bytes) { |
| | | StringBuilder temp = new StringBuilder(bytes.length * 2); |
| | | for (int i = 0; i < bytes.length; i++) { |
| | | // é«åä½ |
| | | temp.append((bytes[i] & 0xf0) >>> 4); |
| | | // ä½åä½ |
| | | temp.append(bytes[i] & 0x0f); |
| | | } |
| | | return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1) : temp.toString(); |
| | | } |
| | | |
| | | @Mapping(types = {ä½ç½®ä¿¡æ¯æ¥è¯¢åºç, è½¦è¾æ§å¶åºç}, desc = "ä½ç½®ä¿¡æ¯æ¥è¯¢åºç/è½¦è¾æ§å¶åºç") |
| | | public void T0201_0500(T0201_0500 message, Session session) { |
| | |
| | | package org.yzh.web.endpoint; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import io.github.yezhihao.netmc.core.HandlerInterceptor; |
| | | import io.github.yezhihao.netmc.session.Session; |
| | | import netscape.javascript.JSObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.yzh.commons.util.Byte2NumberUtils; |
| | | import org.yzh.protocol.basics.JTMessage; |
| | | import org.yzh.protocol.commons.JT808; |
| | | import org.yzh.protocol.commons.transform.AttributeKey; |
| | | import org.yzh.protocol.commons.transform.attribute.Battery; |
| | | import org.yzh.protocol.t808.T0001; |
| | | import org.yzh.protocol.t808.T0200; |
| | | import org.yzh.web.model.entity.DeviceDO; |
| | | import org.yzh.web.model.enums.SessionKey; |
| | | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | public class JTHandlerInterceptor implements HandlerInterceptor<JTMessage> { |
| | | |
| | |
| | | boolean transform = request.transform(); |
| | | if (messageId == JT808.ä½ç½®ä¿¡æ¯æ±æ¥) { |
| | | DeviceDO device = SessionKey.getDevice(session); |
| | | if (device != null) |
| | | if (device != null){ |
| | | device.setLocation((T0200) request); |
| | | if(device.getLocation()!=null && device.getLocation().getAttributes()!=null ){ |
| | | Battery battery= (Battery) device.getLocation().getAttributes().get(AttributeKey.Battery); |
| | | if(battery !=null){ |
| | | device.setBatteryVoltage(battery.getVoltage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return transform; |
| | | } |
| | | if (!session.isRegistered()) { |
| | |
| | | package org.yzh.web.model.entity; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import org.yzh.protocol.t808.T0200; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | @Data |
| | | public class DeviceDO { |
| | | |
| | | @Schema(description = "设å¤id") |
| | |
| | | protected int driverId; |
| | | @Schema(description = "åè®®çæ¬å·") |
| | | private int protocolVersion; |
| | | @Schema(description = "çµæ± çµå") |
| | | private Float batteryVoltage; |
| | | @Schema(description = "宿¶ç¶æ") |
| | | private T0200 location; |
| | | |
| | |
| | | import org.yzh.protocol.codec.JTMessageDecoder; |
| | | import org.yzh.protocol.codec.JTMessageEncoder; |
| | | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | /** |
| | | * JTæ¶æ¯ç¼è§£ç éé
å¨ |
| | | * @author yezhihao |
| | |
| | | JTMessage message = messageDecoder.decode(input); |
| | | return message; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | } |
| | | } |