当前位置: 首页 > news >正文

物联网设备字符串转串口指令-SAAS本地化及未来之窗行业应用跨平台架构

一、指令转换作用

现在服务器一般采用json数据格式

但是终端底层都是二进制指令

直接从服务器传输的指令就无法执行,因此需要转换

二、转换源码

void StringToHandleCommand(byte *byteArray, const char *hexString)
{bool oddLength = strlen(hexString) & 1;byte currentByte = 0;byte byteIndex = 0;for (byte charIndex = 0; charIndex < strlen(hexString); charIndex++){bool oddCharIndex = charIndex & 1;if (oddLength){// If the length is oddif (oddCharIndex){// odd characters go in high nibblecurrentByte = wlzcch(hexString[charIndex]) << 4;}else{// Even characters go into low wlzcchcurrentByte |= wlzcch(hexString[charIndex]);byteArray[byteIndex++] = currentByte;currentByte = 0;}}else{// If the length is evenif (!oddCharIndex){// Odd characters go into the high nibblecurrentByte = wlzcch(hexString[charIndex]) << 4;}else{// Odd characters go into low wlzcchcurrentByte |= nibble(hexString[charIndex]);byteArray[byteIndex++] = currentByte;currentByte = 0;}}}
}byte wlzcch(char c)
{if (c >= '0' && c <= '9')return c - '0';if (c >= 'a' && c <= 'f')return c - 'a' + 10;if (c >= 'A' && c <= 'F')return c - 'A' + 10;return 0;  
}

六、阿雪技术观

拥抱开源与共享,见证科技进步奇迹,畅享人类幸福时光!

让我们积极投身于技术共享的浪潮中,不仅仅是作为受益者,更要成为贡献者。无论是分享自己的代码、撰写技术博客,还是参与开源项目的维护和改进,每一个小小的举动都可能成为推动技术进步的巨大力量

扫码,可学习更多


http://www.mrgr.cn/news/5062.html

相关文章:

  • 【数据结构】堆排序
  • 如何优化企业网站的索引情况?
  • 常用API:object
  • Linux入门——09 共享内存
  • 计算机网络——TCP协议与UDP协议详解(下)
  • Ps:首选项 - 文件处理
  • PXE 高效批量网络装机
  • 未来城市的科技展望
  • 搭建Node.js后端
  • 【TB作品】普中V2,数字时钟万年历显示,音乐闹钟,流水灯,Proteus仿真
  • Go开发桌面客户端软件小试:网站Sitemap生成
  • Zookeeper用作服务发现~记当牛马的日子
  • 回归预测|基于北方苍鹰优化NGO-Transformer-BiLSTM组合模型的数据预测Matlab程序多特征输入单输出
  • CSS的:horizontal和:vertical伪类:方向性样式的精准选择
  • UDP 和TCP的应用
  • http request-03-Ajax 的替代方案 axios.js 入门介绍
  • makefile文件基本语法
  • python构建一个web程序
  • 用TensorFlow实现线性回归
  • 图像数据处理20