1 Star 0 Fork 641

zmcoding / 部标JTT808协议快速开发包

forked from 剑器近 / 808协议网关 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

部标808协议快速开发包

项目介绍

  • 基于Netty,实现JT/T 808部标协议的消息分发,与编码解码;
  • 与Spring解耦合,协议编码解码和Netty服务均可独立运行(Android客户端同样适用);
  • SpringBoot 仅负责将协议暴露至Web接口,目的是方便测试,且为二次开发提供样例;
  • 最简洁、清爽、易用的部标开发框架。

问题交流群:[906230542]

主要特性

  • 代码足够精简,便于二次开发;
  • 致敬Spring、Hibernate设计理念,熟悉Web开发的同学上手极快;
  • 使用注解描述协议,告别繁琐的封包、解包;
  • 支持2013、2019部标协议版本,支持分包请求;
  • 支持异步批量处理,显著提升Netty和MySQL入库性能;
  • 提供报文解释器(解析过程分析工具),编码解码不再抓瞎;
  • 全覆盖的测试用例,稳定发版。

代码仓库

下载方式

  • Gitee下载命令:git clone https://gitee.com/yezhihao/jt808-server -b master
  • Github下载命令:git clone https://github.com/yezhihao/jt808-server -b master

使用说明

项目分为四部分:

1.framework,核心模块,不推荐修改,有BUG或扩展的需求,建议提交issues或联系作者

└── framework
    ├── codec 编码解码
    ├── mvc 消息分发、处理
    ├── orm 消息元数据的描述
    ├── session 消息和会话的管理
    └── netty 网络通信 

注解:

  • @Endpoint,服务接入点,等价SpringMVC的 @Controller;

  • @Mapping,定义消息ID,等价SpringMVC中 @RequestMapping;

  • @AsyncBatch, 异步批量消息,对于并发较高的消息,如0x0200(位置信息汇报),使用该注解,显著提升Netty和MySQL入库性能。

  • @Message,协议类型,等价Hibernate的 @Table;

  • @Field,属性定义,等价Hibernate的 @Column;

  • @Fs,多版本协议支持

2.protocol 部标协议定义,不推荐做大量修改

└── protocol
    ├── basics 部标协议通用消息头,以及公共的消息定义
    ├── codec 部标编码解码工具
    ├── commons 部标协议ID,工具类等
    ├── t808 JT/T808协议定义(已完成)
    └── t1078 JT/T1078协议(待补充) 

消息定义样例:

@Message(JT808.定位数据批量上传)
public class T0704 extends AbstractMessage<Header> {

   private Integer total;
   private Integer type;
   private List<Item> items;

   @Field(index = 0, type = DataType.WORD, desc = "数据项个数")
   public Integer getTotal() { return total; }
   public void setTotal(Integer total) { this.total = total; }

   @Field(index = 2, type = DataType.BYTE, desc = "位置数据类型 0:正常位置批量汇报,1:盲区补报")
   public Integer getType() { return type; }
   public void setType(Integer type) { this.type = type; }

   @Field(index = 3, type = DataType.LIST, desc = "位置汇报数据项")
   public List<Item> getItems() { return items; }    
   public void setItems(List<Item> items) { this.items = items; this.total = items.size(); }
}

3.web 开箱即用的Demo,业务需求在这个包下开发,可随意修改

└── web
    ├── config spring 相关配置
    ├── component.mybatis 附赠极简的mybatis分页插件:D
    ├── endpoint 808消息入口,所有netty进入的请求都会根据@Mapping转发到此
    └── controller service mapper ... 不再赘述
消息接入:
@Endpoint
public class JT808Endpoint {

    @Autowired
    private LocationService locationService;
    
    @Autowired
    private DeviceService deviceService;

    //异步批量处理 队列大小20000 最大累积200处理一次 最大等待时间5秒
    @AsyncBatch(capacity = 20000, maxElements = 200, maxWait = 5000)
    @Mapping(types = 位置信息汇报, desc = "位置信息汇报")
    public void 位置信息汇报(List<T0200> list) {
        locationService.batchInsert(list);
    }

    @Async
    @Mapping(types = 终端注册, desc = "终端注册")
    public T8100 register(T0100 message, Session session) {
        Header header = message.getHeader();

        T8100 result = new T8100(session.nextSerialNo(), header.getMobileNo());
        result.setSerialNo(header.getSerialNo());

        String token = deviceService.register(message);
        if (token != null) {
            session.register(header);

            result.setResultCode(T8100.Success);
            result.setToken(token);
        } else {

            result.setResultCode(T8100.NotFoundTerminal);
        }
        return result;
    }
}
消息下发:
@Controller
@RestController("terminal")
public class TerminalController {

    private MessageManager messageManager = MessageManager.getInstance();

    @ApiOperation("设置终端参数")
    @PostMapping("{terminalId}/parameters")
    public T0001 updateParameters(@PathVariable("terminalId") String terminalId, @RequestBody List<TerminalParameter> parameters) {
        T8103 request = new T8103(terminalId);
        request.setItems(parameters);
        T0001 response = messageManager.request(request, T0001.class);
        return response;
    }
}
已集成Swagger文档,启动后可访问如下地址

4.test 808协议全覆盖的测试用例,以及报文解释器

  • QuickStart 不依赖Spring的启动,可用于Android客户端

  • Beans 测试数据

  • TestBeans 消息对象的封包解包

  • TestHex 原始报文测试

  • Elucidator 报文解释器 - 解码

  • DarkRepulsor 报文解释器 - 编码

分析报文内每个属性所处的位置以及转换后的值,以便查询报文解析出错的原因

Elucidator 运行效果如下:

020000610123456789017fff000004000000080006eeb6ad02633df701380003006320070719235901040000000b02020016030200210402002c05033737371105420000004212064d0000004d4d1307000000580058582504000000632a02000a2b040000001430011e3101286b

0	0200	消息ID	512
2	0061	消息体属性	97
4	012345678901	终端手机号	12345678901
10	7fff	流水号	32767
12	0000	消息包总数	0
14	0400	包序号	1024
0	00000400	报警标志	1024
4	00000800	状态	2048
8	06eeb6ad	纬度	116307629
12	02633df7	经度	40058359
16	0138	海拔	312
18	0003	速度	3
20	0063	方向	99
22	200707192359	时间	200707192359
0	01	附加信息ID	1
1	04	附加信息长度	4
2	0000000b	参数值	[B@2a798d51
0	02	附加信息ID	2
1	02	附加信息长度	2
2	0016	参数值	[B@6d763516
0	03	附加信息ID	3
1	02	附加信息长度	2
2	0021	参数值	[B@52bf72b5
0	04	附加信息ID	4
1	02	附加信息长度	2
2	002c	参数值	[B@37afeb11
0	05	附加信息ID	5
1	03	附加信息长度	3
2	373737	参数值	[B@515aebb0
0	11	附加信息ID	17
1	05	附加信息长度	5
2	4200000042	参数值	[B@dd8ba08
0	12	附加信息ID	18
1	06	附加信息长度	6
2	4d0000004d4d	参数值	[B@245b4bdc
0	13	附加信息ID	19
1	07	附加信息长度	7
2	00000058005858	参数值	[B@6c64cb25
0	25	附加信息ID	37
1	04	附加信息长度	4
2	00000063	参数值	[B@6ae5aa72
0	2a	附加信息ID	42
1	02	附加信息长度	2
2	000a	参数值	[B@222545dc
0	2b	附加信息ID	43
1	04	附加信息长度	4
2	00000014	参数值	[B@5c5eefef
0	30	附加信息ID	48
1	01	附加信息长度	1
2	1e	参数值	[B@16293aa2
0	31	附加信息ID	49
1	01	附加信息长度	1
2	28	参数值	[B@5158b42f
28	01040000000b02020016030200210402002c05033737371105420000004212064d0000004d4d1307000000580058582504000000632a02000a2b040000001430011e310128	位置附加信息	[BytesAttribute[id=1,length=4,value={0,0,0,11}], BytesAttribute[id=2,length=2,value={0,22}], BytesAttribute[id=3,length=2,value={0,33}], BytesAttribute[id=4,length=2,value={0,44}], BytesAttribute[id=5,length=3,value={55,55,55}], BytesAttribute[id=17,length=5,value={66,0,0,0,66}], BytesAttribute[id=18,length=6,value={77,0,0,0,77,77}], BytesAttribute[id=19,length=7,value={0,0,0,88,0,88,88}], BytesAttribute[id=37,length=4,value={0,0,0,99}], BytesAttribute[id=42,length=2,value={0,10}], BytesAttribute[id=43,length=4,value={0,0,0,20}], BytesAttribute[id=48,length=1,value={30}], BytesAttribute[id=49,length=1,value={40}]]

使用发包工具模拟请求

7e020000610123456789017fff000004000000080006eeb6ad02633df701380003006320070719235901040000000b02020016030200210402002c05033737371105420000004212064d0000004d4d1307000000580058582504000000632a02000a2b040000001430011e3101286b7e

使用发包工具模拟请求

项目会不定期进行更新,建议star和watch一份,您的支持是我最大的动力。

如有任何疑问或者BUG,请联系我,非常感谢。

技术交流QQ群:[906230542]

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2019 剑器近 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

808服务端与客户端程序;同时兼容2011、2013、2019版本协议,支持分包。后续支持JT/T1078协议,以及T/JSATL12苏标主动安防协议。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/showmeonly/jt808-server.git
git@gitee.com:showmeonly/jt808-server.git
showmeonly
jt808-server
部标JTT808协议快速开发包
master

搜索帮助

14c37bed 8189591 565d56ea 8189591