jt808-server Documentation

repository·master·Indexed 21 days ago

https://github.com/yezhihao/jt808-server

A 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.

Tokens
2.2K
Snippets
5
Records
7
Agent score
24%

What's inside jt808-server

  1. Overview of jt808-server

    master
    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.
  2. Integrate jt808-server into a Spring Boot project

    master

    For Spring Boot users, the recommended way to integrate is via Maven.

    1. Install the jtt808-protocol module to your local Maven repository using mvn install.
    2. Add the dependency to your pom.xml:
    <dependency>
        <groupId>org.yzh</groupId>
        <artifactId>jtt808-protocol</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    1. Configure the service URL in application.yml:
    jt808-service:
      base-url: http://127.0.0.1:8100
    1. Use JT808Service to 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);
            }
        }
    }
  3. Use Elucidator to debug message encoding/decoding

    master

    The org.yzh.Elucidator tool 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 JT808Beans and use the decode and encode methods provided by the JTMessageAdapter.

    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);
        }
    }
  4. Define custom protocol messages using annotations

    master

    You 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;
    }
  5. Handle incoming terminal messages with @Endpoint

    master

    To process messages received from terminals, create an @Endpoint class and use the @Mapping annotation to route specific message types to methods. This is similar to using @Controller and @RequestMapping in 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;
        }
    }
  6. Send messages to terminals via Web API

    master

    You 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);
        }
    }
  7. Supported Protocols

    master

    The gateway supports the following protocols out of the box:

    ProtocolVersionSupport StatusNotes
    JT/T 8082011Supported
    JT/T 8082013Supported
    JT/T 8082019Supported
    JT/T 10782016SupportedRequires self-built streaming service
    T/JSATL 12 (Su-standard)2017SupportedBased on JT/T 808-2013
    T/GDRTA 002 (Yue-standard)2019SupportedBased 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.