vo 2 输出helloworld

news2024/9/25 3:23:58

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;
    }

    @Override
    public 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);//4
        headBuffer.writeInt(msg.getMsgSn());//4
        headBuffer.writeShort((short)msg.getMsgId());//2
        headBuffer.writeInt(msg.getMsgGesscenterId());//4
        headBuffer.writeBytes(msg.getVersionFlag());//3
        headBuffer.writeByte(0);//1
        headBuffer.writeInt(10);//4
        buffer.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表示报警//4
        ChannelBuffer 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()));//2

        msg.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.coloradmin.cn/o/810233.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

HCIP重发布实验

目录 实验要求&#xff1a; 步骤一&#xff1a;拓扑设计IP地址规划 拓扑设计 R1 R2 R3 R4 发布路由 R1 R2 R3 R4 双向重发布 在R2和R4 上进行 R2 R4 检查R1 修改开销值选路 择优选择去4.0网段的路径 测试&#xff1a;​编辑 择优选择去32网段的路径 测试&…

redis(四)—— java如何操作redis、springboot集成redis

一、java如何操作redis——Jedis jedis的“j”就是javajedis是java官方推荐的java操作redis工具&#xff0c;是一个非可视化的客户端redis-clientspringboot的redisTemplate对象就相当于这里的jedis对象&#xff08;redisTemplate去调用一系列方法不就相当于jedis这个client去…

使用java将个人微信打造成得力助手

本文提供一个通过java编程将微信打造成得力助手的方案, 先看效果&#xff1a; 查看支持的功能与对该功能开放的用户 接入人工智能 下载BiliBili 视频 原理 这个方案最难的地方就是如何把个人账号安全的接入微信&#xff0c;不会被封号。网上主流的有逆向web端微信&#xff0c…

KY258 日期累加

一、题目 二、代码 #include <iostream> using namespace std; class Date {public:Date(int year 0, int month 0, int day 0) {_year year;_month month;_day day;}Date(const Date& _d);int GetDay(int year, int month);Date& operator(int d);Date o…

this is incompatible with sql_mode=only_full_group_by

查看配置 select global.sql_mode 在sql命令行中输入select sql_mode 能够看到sql_mode配置,如果有ONLY_FULL_GROUP_BY&#xff0c;则需要修改 在mysql5.7.5后&#xff0c;ONLY_FULL_GROUP_BY是默认选项&#xff0c;所以就会导致group by的问题 set sql_mode‘复制去掉ONLY_F…

Python(五十)获取列表中指定的元素

❤️ 专栏简介&#xff1a;本专栏记录了我个人从零开始学习Python编程的过程。在这个专栏中&#xff0c;我将分享我在学习Python的过程中的学习笔记、学习路线以及各个知识点。 ☀️ 专栏适用人群 &#xff1a;本专栏适用于希望学习Python编程的初学者和有一定编程基础的人。无…

嵌入式linux之OLED显示屏SPI驱动实现(SH1106,ssd1306)

周日业余时间太无聊&#xff0c;又不喜欢玩游戏&#xff0c;大家的兴趣爱好都是啥&#xff1f;我觉得敲代码也是一种兴趣爱好。正巧手边有一块儿0.96寸的OLED显示屏&#xff0c;一直在吃灰&#xff0c;何不把玩一把&#xff1f;于是说干就干&#xff0c;最后在我的imax6ul的lin…

BUU [BJDCTF2020]The mystery of ip

BUU [BJDCTF2020]The mystery of ip 再hint的源码里面找到这个东西。 这题一定和IP有关系&#xff0c;试了一下伪造IP还真是。 分析一下&#xff0c;这题可能存在SSTI漏洞&#xff0c;先用模板算式子{{9*‘9’}}测一下 那SSTI稳了&#xff0c;应该是Twig模板。 但是报错测出来是…

Android 面试题 线程间通信 六

&#x1f525; 主线程向子线程发送消息 Threadhandler&#x1f525; 子线程中定义Handler&#xff0c;Handler定义在哪个线程中&#xff0c;就跟那个线程绑定&#xff0c;在线程中绑定Handler需要调用Looper.prepare(); 方法&#xff0c;主线程中不调用是因为主线程默认帮你调用…

编写脚本,使用mysqldump实现分库分表备份。

一、实现分库备份&#xff1a; #!/bin/bash #分库备份 bak_userroot-----------备份用户 bak_password513721ykp--------备份密码 bak_path/backup/db_bak---------备份路径 bak_cmd"-u$bak_user -p$bak_password"-------登录命令&#xff0c;以便后面重复编写 exc_…

分布式锁漫谈

简单解释一下个人理解的分布式锁以及主要的实现手段。 文章目录 什么是分布式锁常用分布式锁实现 什么是分布式锁 以java应用举例&#xff0c;如果是单应用的情况下&#xff0c;我们通常使用synchronized或者lock进行线程锁&#xff0c;主要为了解决多线程或者高并发场景下的共…

3ds MAX绘制摄像机动画

之前&#xff0c;我们已经绘制了山地、山间小路、以及树林&#xff1a; 这里我们添加一个自由摄像机&#xff1a;&#xff08;前视图&#xff09; 在动作窗口&#xff0c;给摄像机添加一个按路径移动的设定&#xff1a; 这样&#xff0c;我们只要把指定的路径绘制出来&#xff…

UE4/5C++多线程插件制作(0.简介)

目录 插件介绍 插件效果 插件使用 English 插件介绍 该插件制作&#xff0c;将从零开始&#xff0c;由一个空白插件一点点的制作&#xff0c;从写一个效果到封装&#xff0c;层层封装插件&#xff0c;简单粗暴的对插件进行了制作&#xff1a; 插件效果 更多的是在cpp中去…

Cpp04 — 默认成员函数

前言&#xff1a;本文章主要用于个人复习&#xff0c;追求简洁&#xff0c;感谢大家的参考、交流和搬运&#xff0c;后续可能会继续修改和完善。 因为是个人复习&#xff0c;会有部分压缩和省略。 一、默认成员函数 当类里面成员函数什么都不写的时候&#xff0c;编译器会自动…

AutoSAR系列讲解(实践篇)10.3-BswM配置

目录 一、ECU State Handing(ESH) 二、Module Initialization 三、Communication Control 说起BswM的配置,其实博主问过很多朋友了,大家基本都只用自动配置;很少有用到手动配置的时候,对于刚刚入门的大家来说,掌握自动配置基 本也就足够了。 一、ECU State Handing(…

【雕爷学编程】MicroPython动手做(12)——掌控板之Hello World

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

内网隧道代理技术(十四)之 Earthworm的使用(一级代理)

Earthworm的使用(一级代理) ew 全称是EarchWorm,是一套轻量便携且功能强大的网络穿透工具,基于标准C开发,具有socks5代理、端口转发和端口映射三大功能,可在复杂网络环境下完成网络穿透,且支持全平台(Windows/Linux/Mac)。该工具能够以“正向”、“反向”、“多级级联”…

谷粒商城第七天-商品服务之分类管理下的删除、新增以及修改商品分类

目录 一、总述 1.1 前端思路 1.2 后端思路 二、前端部分 2.1 删除功能 2.2 新增功能 2.3 修改功能 三、后端部分 3.1 删除接口 3.2 新增接口 3.3 修改接口 四、总结 一、总述 1.1 前端思路 删除和新增以及修改的前端无非就是点击按钮&#xff0c;就向后端发送请求…

动脑学院Jetpack Compose学习笔记

最近b站学习了一下Compose相关内容&#xff0c;整理了相关笔记&#xff0c;仅供大家参考。 资源链接如下&#xff0c;象征性收取1个积分 https://download.csdn.net/download/juliantem/88125198

C数据结构——无向图(邻接表方式) 创建与基本使用

源码注释 // // Created by Lenovo on 2022-05-17-下午 4:37. // 作者&#xff1a;小象 // 版本&#xff1a;1.0 //#include <stdio.h> #include <malloc.h>#define TRUE 1 #define FALSE 0#define MAX_ALVNUMS 100 // 最大顶点数/** 定义链队*/ typedef int QEle…