jt808-server Documentation
repository·master·Indexed 21 days ago
https://github.com/yezhihao/jt808-serverA high-performance JT808/JT1078 protocol gateway built on Netty and Spring WebFlux for vehicle management and IoT. It supports JT/T 808 (2011, 2013, 2019), JT/T 1078 (2016), and regional Chinese standards including Su-standard (T/JSATL 12) and Yue-standard (T/GDRTA 002). The server supports TCP and UDP transport, automatic version compatibility, and provides a declarative approach to defining custom protocol messages via annotations.
What's inside jt808-server
- jt808-server is a high-performance gateway for JT808, JT1078, and regional Chinese standards (Su-standard and Yue-standard) protocols. Built on Netty, it supports both TCP and UDP transport layers without code changes. It uses Spring WebFlux for high-concurrency Web interfaces and is designed to be lightweight enough to run independently of Spring (e.g., on Android) for encoding/decoding tasks.
Integrate jt808-server into a Spring Boot project
masterFor Spring Boot users, the recommended way to integrate is via Maven.
- Install the
jtt808-protocolmodule to your local Maven repository usingmvn install. - Add the dependency to your
pom.xml:
<dependency> <groupId>org.yzh</groupId> <artifactId>jtt808-protocol</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency>- Configure the service URL in
application.yml:
jt808-service: base-url: http://127.0.0.1:8100- Use
JT808Serviceto interact with the gateway in your code.
package com.xxx; import org.yzh.protocol.service.JT808Service; @Service public class YourService { @Autowired private JT808Service jt808Service; public void test() { JTMessage message = new JTMessage(); message.setClientId("12345678901"); try { T0001 result = jt808Service.send("8304", message); System.out.println(result); } catch (WebClientResponseException e) { R error = e.getResponseBodyAs(R.class); System.out.println(error); } } }- Install the
Use Elucidator to debug message encoding/decoding
masterThe
org.yzh.Elucidatortool is a message interpreter used to analyze the mapping between hex strings and Java objects. It helps identify exactly which byte positions correspond to which object properties, making it easier to debug parsing errors.To use it, extend
JT808Beansand use thedecodeandencodemethods provided by theJTMessageAdapter.package org.yzh; public class Elucidator extends JT808Beans { public static final JTMessageAdapter coder = new JTMessageAdapter("org.yzh.protocol"); public static void main(String[] args) { String hex = "020000d40123456789017fff000004000000080006eeb6ad02633df7013800030063200707192359642f000000400101020a0a02010a1e00640001b2070003640e200707192359000100000061646173200827111111010101652f000000410202020a0000000a1e00c8000516150006c81c20070719235900020000000064736d200827111111020202662900000042031e012c00087a23000a2c2a200707192359000300000074706d732008271111110303030067290000004304041e0190000bde31000d90382007071923590004000000006273642008271111110404049d"; JTMessage msg = H2019(T0200JSATL12()); msg = decode(hex); hex = encode(msg); } }Define custom protocol messages using annotations
masterYou can extend the protocol by defining new message classes using annotations. This replaces manual packet assembly/disassembly with a declarative approach similar to Hibernate.
@Message(description): Defines the message type (equivalent to@Table).@Field(desc, length, ...): Defines a specific property within the message (equivalent to@Column).
package org.yzh.protocol.t808; @Message(JT808.终端注册) public class T0100 extends JTMessage { @Field(desc = "省域ID") private short provinceId; @Field(desc = "市县域ID") private short cityId; @Field(length = 11, desc = "制造商ID") private String makerId; @Field(length = 30, desc = "终端型号") private String deviceModel; @Field(length = 30, desc = "终端ID") private String deviceId; @Field(desc = "车牌颜色:0.未上车牌 1.蓝色 2.黄色 3.黑色 4.白色 9.其他") private byte plateColor; @Field(desc = "车辆标识") private String plateNo; }Handle incoming terminal messages with @Endpoint
masterTo process messages received from terminals, create an
@Endpointclass and use the@Mappingannotation to route specific message types to methods. This is similar to using@Controllerand@RequestMappingin Spring MVC.package org.yzh.web.endpoint; @Endpoint public class JT808Endpoint { @Autowired private DeviceService deviceService; @Mapping(types = 0x0100, desc = "终端注册") public T8100 register(T0100 message, Session session) { T8100 result = new T8100(); result.setResponseSerialNo(message.getSerialNo()); DeviceInfo device = deviceService.register(message); if (device != null) { session.register(message); result.setToken("1234567890A"); result.setResultCode(T8100.Success); } else { result.setResultCode(T8100.NotFoundTerminal); } return result; } }Send messages to terminals via Web API
masterYou can trigger commands to terminals by calling a Web controller that uses the
MessageManager. This allows your business logic to interact with the protocol gateway via standard HTTP requests.package org.yzh.web.controller; @RestController @RequestMapping("device") public class JT808Controller { @Autowired private MessageManager messageManager; @Operation(summary = "8103 设置终端参数") @PostMapping("8103") public Mono<T0001> T8103(@RequestBody T8103 request) { return messageManager.request(request, T0001.class); } }Supported Protocols
masterThe gateway supports the following protocols out of the box:
Protocol Version Support Status Notes JT/T 808 2011 Supported JT/T 808 2013 Supported JT/T 808 2019 Supported JT/T 1078 2016 Supported Requires self-built streaming service T/JSATL 12 (Su-standard) 2017 Supported Based on JT/T 808-2013 T/GDRTA 002 (Yue-standard) 2019 Supported Based on JT/T 808-2019 Note: The system automatically handles version compatibility (2011, 2013, 2019), packet fragmentation (split requests/responses), and timeout retransmissions. For JT/T 1078, you must provide your own media streaming service.