北斗卫星定位GPS解析全过程

这篇博客主要介绍了北斗卫星定位数据的解析过程,特别是使用ASCII编码的数据,通过Socket通讯接收后转化为16进制字符串,再利用解析工具类进行处理的关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解析工具类

package com.jeesite.modules.utils;

import java.text.DecimalFormat;
import org.apache.commons.lang.StringUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

/**
 * @Desc 解析GPS发送数据工具类
 * @author PGQing
 */
@Slf4j
public class HexMathUtils {

	/**
	 * @Desc 1.将收到的GPS定位数据解析成JSON格式
	 * @param hex
	 * @return
	 * @throws Exception
	 */
	public static JSONObject formatHexStr(String hexStr) throws Exception {
		log.info("准备解析的数据:\n" + hexStr);
		JSONObject result = new JSONObject();
		try {
			if (StringUtils.isNotBlank(hexStr) && hexStr.replaceAll(" ", "").length() == 110) {
				JSONObject info = new JSONObject();
				// 去空
				String content = hexStr.replaceAll(" ", "");
				// 长度
				info.put("length", content.getBytes("UTF-8").length / 2);
				// 消息头
				info.put("head", content.substring(0, 2));
				// 消息长度
				info.put("length", content.substring(2, 4));
				// 消息ID
				info.put("id", content.substring(4, 6));
				// 设备编号
				info.put("no", content.substring(6, 14));
				// 消息体
				info.put("body", content.substring(14, 106));
				// 校验位
				info.put("bit", content.substring(106));
				// 解析设备编号、消息体
				result = formatJSONObject(info);
				log.info("解析数据为:\n" + result.toJSONString());
			}
		} catch (Exce
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸟特工007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值