vo 2 输出helloworld

news/2024/4/27 2:18:19/文章来源:https://blog.csdn.net/xiamaocheng/article/details/132001987

vo 2 输出helloworld

  • 目录
    • 概述
      • 需求:
    • 设计思路
    • 实现思路分析
      • 1.code
    • 拓展实现
    • 性能参数测试:
  • 参考资料和推荐阅读

Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.

目录

在这里插入图片描述

概述

需求:

设计思路

实现思路分析

1.code

package cn.com.onlinetool.jt809.decoderDemo2;import cn.com.onlinetool.jt809.decoderDemo.JT809BasePacket;import java.time.LocalDate;
import java.time.LocalTime;/*** @Author: Xiuming Lee* @Date: 2019/9/22 15:41* @Version 1.0* @Describe: 实时上传车辆定位信息包*/
public class JT809Packet0x0000 extends JT809BasePacket {private String name;private Number code;public Number getCode() {return code;}public void setCode(Number code) {this.code = code;}public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic byte[] getMsgBodyByteArr() {return new byte[0];}}
package cn.com.onlinetool.jt809.decoderDemo2;import cn.com.onlinetool.jt809.decoderDemo.Const;
import cn.com.onlinetool.jt809.decoderDemo.JT809Packet0x1202;
import cn.com.onlinetool.jt809.decoderDemo.PacketDecoderUtils;
import io.netty.buffer.ByteBuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.nio.charset.Charset;/*** @Author: Xiuming Lee* @Date: 2019/9/23 15:21* @Version 1.0* @Describe:*/
public class JT809Packet0x0000Decoder {private static Logger log = LoggerFactory.getLogger(JT809Packet0x0000Decoder.class);public JT809Packet0x0000 decoder(byte[] bytes) throws Exception {JT809Packet0x0000 jt809Packet0x0000 = new JT809Packet0x0000();ByteBuf byteBuf = PacketDecoderUtils.baseDecoder(bytes, jt809Packet0x0000);JT809Packet0x0000 pkt = packetDecoder(byteBuf, jt809Packet0x0000);return pkt;}private JT809Packet0x0000 packetDecoder(ByteBuf byteBuf, JT809Packet0x0000 packet) throws Exception{ByteBuf msgBodyBuf = null;if (packet.getEncryptFlag() == Const.EncryptFlag.NO) {msgBodyBuf = PacketDecoderUtils.getMsgBodyBuf(byteBuf);} else {msgBodyBuf = null;}
//        // 车牌号
//        byte [] vehicleNoBytes = new byte[21];
//        msgBodyBuf.readBytes(vehicleNoBytes);
////----------------------数据报文解析--------------------------------------msgBodyBuf.readByte();packet.setCode( msgBodyBuf.readByte());
//        packet.setCode(msgBodyBuf.readInt());return  packet;}}
package cn.com.onlinetool.jt809.jt;import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;//import org.apache.commons.lang3.StringUtils;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;public class TcpClientDemo {private static Logger LOGGER = LoggerFactory.getLogger(TcpClientDemo.class);/*** 交委指定本公司接入码*/public static int PLANT_CODE;/*** 交委指定本公司用户名*/public static int COM_ID;/*** 交委指定本公司密码*/public static String COM_PWD;public static String LONGINSTATUS = "";public static String LOGINING = "logining";private static int LOGIN_FLAG = 0;private static String DOWN_LINK_IP = "127.0.0.1";//初始化基类private static TcpClient tcpClient = TcpClient.getInstence();//初始化private static TcpClientDemo tcpClientDemo = new TcpClientDemo();
//    //初始化配置,将密码相关的内容写在里面
//    private static Properties property = PropertiesReader.getProperties("properName", true);//初始化channel,以便心跳机制及时登录private Channel channel = tcpClient.getChannel("127.0.0.1", 11111);public static TcpClientDemo getInstance(){return tcpClientDemo;}public static ChannelBuffer buildMessage(Message msg){int bodyLength = 0 ;if(null != msg.getMsgBody()){bodyLength = msg.getMsgBody().readableBytes();}msg.setMsgGesscenterId(PLANT_CODE);ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(bodyLength + Message.MSG_FIX_LENGTH);ChannelBuffer headBuffer = ChannelBuffers.buffer(22);//---数据头headBuffer.writeInt(buffer.capacity() - 1);//4headBuffer.writeInt(msg.getMsgSn());//4headBuffer.writeShort((short)msg.getMsgId());//2headBuffer.writeInt(msg.getMsgGesscenterId());//4headBuffer.writeBytes(msg.getVersionFlag());//3headBuffer.writeByte(0);//1headBuffer.writeInt(10);//4buffer.writeBytes(headBuffer);//---数据体if(null != msg.getMsgBody()){buffer.writeBytes(msg.getMsgBody());}ChannelBuffer finalBuffer = ChannelBuffers.copiedBuffer(buffer);//--crc校验码byte[] b = ChannelBuffers.buffer(finalBuffer.readableBytes()).array();finalBuffer.getBytes(0, b);int crcValue = CRC16CCITT.crc16(b);finalBuffer.writeShort((short)crcValue);//2//转义byte[] bytes = ChannelBuffers.copiedBuffer(finalBuffer).array();ChannelBuffer headFormatedBuffer = ChannelBuffers.dynamicBuffer(finalBuffer.readableBytes());formatBuffer(bytes, headFormatedBuffer);ChannelBuffer buffera = ChannelBuffers.buffer(headFormatedBuffer.readableBytes() + 2);buffera.writeByte(Message.MSG_HEAD);buffera.writeBytes(headFormatedBuffer);buffera.writeByte(Message.MSG_TALL);return ChannelBuffers.copiedBuffer(buffera);}//
//    /**
//     * 发送数据到交委接入平台
//     * boolean
//     * @param awsVo
//     * @return
//     * 2016年9月28日 by fox_mt
//     */public boolean sendMsg2Gov(Idc2AwsGpsVo awsVo){boolean success = false;
//        if(isLogined()){//已经登录成功,开始发送数据
//            channel = tcpClient.getChannel(Constants.TCP_ADDRESS, Constants.TCP_PORT);tcpClient.getChannel("127.0.0.1", 11111);if(null != channel && channel.isWritable()){Message msg = buildSendVO(awsVo);ChannelBuffer msgBuffer = buildMessage(msg);channel.write(msgBuffer);}else{LONGINSTATUS = "";}//        }else if(LOGIN_FLAG == 0){
//            LOGIN_FLAG ++;
//            login2Gov();
//            LOGGER.error("--------------第一次登录");
//        }else{
//            LOGGER.error("--------------等待登录");
//        }return success;}
//
///*** 转换VO* void* @param awsVo* 2016年9月28日 by fox_mt*/private Message buildSendVO(Idc2AwsGpsVo awsVo){
//        awsVo.setName("南京");
//        Message msg = new Message(JT809Constants.UP_EXG_MSG);Message msg = new Message( );
//        ChannelBuffer buffer = ChannelBuffers.buffer(36);//是否加密
//        buffer.writeByte((byte)0);//0未加密 // 1
//        //日月年dmyy
//        Calendar cal = Calendar.getInstance();
//        cal.setTime(new Date());
//        buffer.writeByte((byte)cal.get(Calendar.DATE));
//        buffer.writeByte((byte)(cal.get(Calendar.MONTH) + 1));
//        String hexYear = "0" + Integer.toHexString(cal.get(Calendar.YEAR));
//        buffer.writeBytes(hexStringToByte(hexYear));//4
//
//        //时分秒
//        buffer.writeByte((byte)cal.get(Calendar.HOUR_OF_DAY));
//        buffer.writeByte((byte)cal.get(Calendar.MINUTE));
//        buffer.writeByte((byte)cal.get(Calendar.SECOND));//3
//        //经度,纬度
//        buffer.writeInt(formatLonLat(awsVo.getLon()));//4
//        buffer.writeInt(formatLonLat(awsVo.getLat()));//4//        //速度
//        buffer.writeShort(awsVo.getSpeed().shortValue());//2
//        //行驶记录速度
//        buffer.writeShort(awsVo.getSpeed().shortValue());//2
//        //车辆当前总里程数
//        buffer.writeInt(awsVo.getMileage().intValue());//4
//        //方向
//        buffer.writeShort(awsVo.getDirection().shortValue());//2
//        //海拔
//        buffer.writeShort((short)0);//2
//        //车辆状态
//        int accStatus = null == awsVo.getAcc() ? 0 : awsVo.getAcc();
//        int gpsStatus = null == awsVo.getGpsStatus() ? 0 : awsVo.getGpsStatus();
//        if(accStatus == 0 && gpsStatus == 0){
//            buffer.writeInt(0);//4
//        }else if(accStatus == 1 && gpsStatus == 0){
//            buffer.writeInt(1);//4
//        }else if(accStatus == 0 && gpsStatus == 1){
//            buffer.writeInt(2);//4
//        }else{
//            buffer.writeInt(3);//4
//        }
//        //报警状态
//        buffer.writeInt(0);//0表示正常;1表示报警//4ChannelBuffer headBuffer = ChannelBuffers.buffer(16);
//        headBuffer.writeBytes(getBytesWithLengthAfter(21 , awsVo.getVehicleNo().getBytes(Charset.forName("GBK"))));//21
//        headBuffer.writeByte((byte)InitVehicleData.vehicleColor(awsVo.getVehicleNo()));//1
//        headBuffer.writeShort(JT809Constants.UP_EXG_MSG_REAL_LOCATION);//2
//        headBuffer.writeInt(buffer.capacity());//4
//        headBuffer.writeBytes(buffer);
//        msg.setMsgBody(headBuffer);headBuffer.writeShort((awsVo.getCode().intValue()));//2
//        headBuffer.writeBytes((awsVo.getName().getBytes()));//2msg.setMsgBody(headBuffer);return msg;}/*** 报文转义* void* @param bytes* @param formatBuffer* 2016年10月12日 by fox_mt*/private static void formatBuffer(byte[] bytes, ChannelBuffer formatBuffer){for (byte b : bytes) {switch(b){case 0x5b:byte[] formatByte0x5b = new byte[2];formatByte0x5b[0] = 0x5a;formatByte0x5b[1] = 0x01;formatBuffer.writeBytes(formatByte0x5b);break;case 0x5a:byte[] formatByte0x5a = new byte[2];formatByte0x5a[0] = 0x5a;formatByte0x5a[1] = 0x02;formatBuffer.writeBytes(formatByte0x5a);break;case 0x5d:byte[] formatByte0x5d = new byte[2];formatByte0x5d[0] = 0x5e;formatByte0x5d[1] = 0x01;formatBuffer.writeBytes(formatByte0x5d);break;case 0x5e:byte[] formatByte0x5e = new byte[2];formatByte0x5e[0] = 0x5e;formatByte0x5e[1] = 0x02;formatBuffer.writeBytes(formatByte0x5e);break;default: formatBuffer.writeByte(b);break;}}}/*** 16进制字符串转换成byte数组* byte[]* @param hex* @return* 2016年10月12日 by fox_mt*/public static byte[] hexStringToByte(String hex) {hex = hex.toUpperCase();int len = (hex.length() / 2);byte[] result = new byte[len];char[] achar = hex.toCharArray();for (int i = 0; i < len; i++) {int pos = i * 2;result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));}return result;}private static byte toByte(char c) {byte b = (byte) "0123456789ABCDEF".indexOf(c);return b;}/*** 格式化经纬度,保留六位小数* int* @param needFormat* @return* 2016年10月12日 by fox_mt*/private int formatLonLat(Double needFormat){NumberFormat numFormat = NumberFormat.getInstance();numFormat.setMaximumFractionDigits(6);numFormat.setGroupingUsed(false);String fristFromat = numFormat.format(needFormat);Double formatedDouble = Double.parseDouble(fristFromat);numFormat.setMaximumFractionDigits(0);String formatedValue = numFormat.format(formatedDouble * 1000000);return Integer.parseInt(formatedValue);}/*** 补全位数不够的定长参数* byte[]* @param length* @param pwdByte* @return* 2016年10月12日 by fox_mt*/private byte[] getBytesWithLengthAfter(int length, byte[] pwdByte){byte[] lengthByte = new byte[length];for(int i = 0; i < pwdByte.length; i ++){lengthByte[i] = pwdByte[i];}for (int i = 0; i < (length- pwdByte.length); i++) {lengthByte[pwdByte.length + i] = 0x00;}return lengthByte;}public static void main(String[] args) {TcpClientDemo s =  TcpClientDemo.getInstance();Idc2AwsGpsVo awsVo = new Idc2AwsGpsVo();awsVo.setCode(123);//        awsVo.setSpeed(45D);
//        awsVo.setMileage(10001D);
//        awsVo.setVehicleNo("XXXXX");s.sendMsg2Gov(awsVo);try {Thread.sleep(2*1000);} catch (InterruptedException e) {e.printStackTrace();}s.sendMsg2Gov(awsVo);}}

拓展实现

这里参考:github:简单实现上述流程:
入门级实现:
: 部分源码实现.
: 源码实现

性能参数测试:

暂无

参考资料和推荐阅读

  1. 暂无

欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!同时,期望各位大佬的批评指正~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_337342.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

NoSQL-Redis集群

NoSQL-Redis集群 一、集群&#xff1a;1.单点Redis带来的问题&#xff1a;2.解决&#xff1a;3.集群的介绍&#xff1a;4.集群的优势&#xff1a;5.集群的实现方式&#xff1a; 二、集群的模式&#xff1a;1.类型&#xff1a;2.主从复制&#xff1a; 三、搭建主从复制&#xff…

[个人笔记] vCenter设置时区和NTP同步

VMware虚拟化 - 运维篇 第三章 vCenter设置时区和NTP同步 VMware虚拟化 - 运维篇系列文章回顾vCenter设置时区和NTP同步&#xff08;附加&#xff09;ESXi设置alias参考链接 系列文章回顾 第一章 vCenter给虚机添加RDM磁盘 第二章 vCenter回收活跃虚拟机的剩余可用空间 vCente…

【算法基础:动态规划】5.4 数位统计DP(计数问题)(数位DP)

文章目录 例题&#xff1a;338. 计数问题解法1——转换成1067. 范围内的数字计数&#xff0c;数位DP模板解法2——分情况讨论&#xff08;TODO&#xff0c;还没理解&#xff09; 相关链接⭐ 例题&#xff1a;338. 计数问题 https://www.acwing.com/problem/content/340/ 解法…

软考A计划-系统集成项目管理工程师-项目人力资源管理-中

点击跳转专栏>Unity3D特效百例点击跳转专栏>案例项目实战源码点击跳转专栏>游戏脚本-辅助自动化点击跳转专栏>Android控件全解手册点击跳转专栏>Scratch编程案例点击跳转>软考全系列 &#x1f449;关于作者 专注于Android/Unity和各种游戏开发技巧&#xff…

运算放大器--------加减运算电路

反向求和运算电路 电路 公式 同向加法运算电路 电路 公式 加减运算电路 分别求正向输入的输出和反相输入的输出&#xff0c;然后求和就可以得到到最终的输出。 切记&#xff0c;虚短虚断不是真正的断路和短路。

M1/M2 通过VM Fusion安装Win11 ARM,解决联网和文件传输

前言 最近新入了Macmini M2&#xff0c;但是以前的老电脑的虚拟机运行不起来了。&#x1f605;&#xff0c;实际上用过K8S的时候&#xff0c;会发现部分镜像也跑不起来&#xff0c;X86的架构和ARM实际上还是有很多隐形兼容问题。所以只能重新安装ARM Win11&#xff0c;幸好微软…

MySQL的JSON操作

官网地址 1. MySQL json介绍 As of MySQL 5.7.8, MySQL supports a native JSON data type defined by RFC 7159 that enables efficient access to data in JSON (JavaScript Object Notation) documents. Automatic validation of JSON documents stored in JSON columns. …

iOS - 检测项目中无用类和无用图片

一、无引用图片检测 LSUnusedResources 安装插件 LSUnusedResources &#xff0c;用【My Mac】模拟器运行,如下图&#xff1a; Project Path 就是项目所在的路径&#xff0c;然后点击右下角 Search按钮&#xff0c;就可以看到被搜索出来的图片资源。 注意&#xff1a;这里被搜…

绕过TLS/akamai指纹护盾

文章目录 前言TLS指纹什么是TLS指纹测试TLS指纹绕过TLS指纹使用原生urllib使用其他成熟库&#xff01;&#xff01;修改requests底层代码 Akamai指纹相关&#xff08;HTTP/2指纹&#xff09;什么是Akamai指纹测试Akamai指纹绕过Akamai指纹使用其他成熟库 实操参考 前言 有道是…

【计算机网络】11、网桥(bridge)、集线器(hub)、交换机(switch)、路由器(router)、网关(gateway)

文章目录 一、网桥&#xff08;bridge)二、集线器&#xff08;hub&#xff09;三、交换机&#xff08;switch)四、路由器&#xff08;router&#xff09;五、网关&#xff08;gateway&#xff09; 对于hub&#xff0c;一个包过来后&#xff0c;直接将包转发到其他口。 对于桥&…

基于RK3588+FPGA+AI算法定制的智慧交通与智能安防解决方案

随着物联网、大数据、人工智能等技术的快速发展&#xff0c;边缘计算已成为当前信息技术领域的一个热门话题。在物联网领域&#xff0c;边缘计算被广泛应用于智慧交通、智能安防、工业等多个领域。因此&#xff0c;基于边缘计算技术的工业主板设计方案也受到越来越多人的关注。…

【1.1】Java微服务:初识微服务

✅作者简介&#xff1a;大家好&#xff0c;我是 Meteors., 向往着更加简洁高效的代码写法与编程方式&#xff0c;持续分享Java技术内容。 &#x1f34e;个人主页&#xff1a;Meteors.的博客 &#x1f49e;当前专栏&#xff1a; 微服务 ✨特色专栏&#xff1a; 知识分享 &#x…

KWP2000协议和OBD-K线

KWP2000最初是基于K线的诊断协议&#xff0c; 但是由于后来无法满足越来越复杂的需求&#xff0c;以及自身的局限性&#xff0c;厂商又将这套应用层协议移植到CAN上面&#xff0c;所以有KWP2000-K和KWP2000-CAN两个版本。 这篇文章主要讲基于K线的早期版本协议&#xff0c;认…

NICE-SLAM: Neural Implicit Scalable Encoding for SLAM论文阅读

论文信息 标题&#xff1a;NICE-SLAM: Neural Implicit Scalable Encoding for SLAM 作者&#xff1a;Zihan Zhu&#xff0c; Songyou Peng&#xff0c;Viktor Larsson — Zhejiang University 来源&#xff1a;CVPR 代码&#xff1a;https://pengsongyou.github.io/nice-slam…

Spring-mybatis结合的底层原理

1.项目前期准备 1.1 导入maven jar包 <dependencies><!-- spring依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.5.RELEASE</version></depende…

Java中对Redis的常用操作

目录 数据类型五种常用数据类型介绍各种数据类型特点 常用命令字符串操作命令哈希操作命令列表操作命令集合操作命令有序集合操作命令通用命令 在Java中操作RedisRedis的Java客户端Spring Data Redis使用方式介绍环境搭建配置Redis数据源编写配置类&#xff0c;创建RedisTempla…

QT--day5(网络聊天室、学生信息管理系统)

服务器&#xff1a; #include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this);//给服务器指针实例化空间servernew QTcpServer(this); }Widget::~Widget() {delete ui; …

texshop mac中文版-TeXShop for Mac(Latex编辑预览工具)

texshop for mac是一款可以在苹果电脑MAC OS平台上使用的非常不错的Mac应用软件&#xff0c;texshop for mac是一个非常有用的工具&#xff0c;广泛使用在数学&#xff0c;计算机科学&#xff0c;物理学&#xff0c;经济学等领域的合作&#xff0c;这些程序的标准tetex分布特产…

【雕爷学编程】MicroPython动手做(15)——掌控板之AB按键

知识点&#xff1a;什么是掌控板&#xff1f; 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片&#xff0c;支持WiFi和蓝牙双模通信&#xff0c;可作为物联网节点&#xff0c;实现物联网应用。同时掌控板上集成了OLED…

MacOS Monterey VM Install ESXi to 7 U2

一、MacOS Monterey ISO 准备 1.1 下载macOS Monterey 下载&#x1f517;链接 一定是 ISO 格式的&#xff0c;其他格式不适用&#xff1a; https://www.mediafire.com/file/4fcx0aeoehmbnmp/macOSMontereybyTechrechard.com.iso/file 1.2 将 Monterey ISO 文件上传到数据…