热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【BUG】串口通信问题

项目场景:提示:这里简述项目相关背景:例如:项目场景:示例:通过蓝牙芯片(HC-05)与手机APP通信&#x
项目场景:

提示:这里简述项目相关背景:
例如:项目场景:示例:通过蓝牙芯片(HC-05)与手机 APP 通信,每隔 5s 传输一批传感器数据(不是很大)


从传感器中读出字节序列,然后每两个字节为一组,进行数据转换,一个简单的串口通信程序。

问题描述:

提示:这里描述项目中遇到的问题:
例如:数据传输过程中数据不时出现丢失的情况,偶尔会丢失一部分数据
APP 中接收数据代码:

@Overridepublic void run() {bytes = mmInStream.read(buffer);mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget();}



  1. 在x86架构和Arm架构下返回的数据不同。
  2. 从缓冲区中读取数据时,会发生字节错位现象,本应该为一组的两个字节数据各成一组。
  3. 每次去缓冲区取数据有时候会不满。

原因分析:

提示:这里填写问题的分析:
例如:Handler 发送消息有两种方式,分别是 Handler.obtainMessage()和 Handler.sendMessage(),其中 obtainMessage 方式当数据量过大时,由于 MessageQuene 大小也有限,所以当 message 处理不及时时,会造成先传的数据被覆盖,进而导致数据丢失。



  1. 可能是大小端数据流的问题。
  2. 不清楚。
  3. 不清楚,采样率是足够快的。

解决方案:

大小端问题

提示:这里填写该问题的具体解决方案:
例如:新建一个 Message 对象,并将读取到的数据存入 Message,然后 mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget();换成 mHandler.sendMessage()。


大小端数据的存储格式:
在这里插入图片描述
网络传输一般采用 大端 序,也被称之为 网络字节序 ,或 网络序 ,即先发送高字节数据再发送低字节数据。

开发环境尽量和生产环境接近,尤其是对于跨架构开发。

sftp


  • 注意 sudo
  • ! 符号用于在本地使用命令;
  • 如果没有!符号,意味着在远程使用命令;
  • put/get -r 针对目录进行操作;

sftp> sftp -P 22 ubuntu@192.168.50.72
sftp> lls
sftp> get /home/ubuntu/Documents/tmp/gdb.txt # 获取文件
sftp> put boot.scr # 上传文件
sftp> get -r /home/ubuntu/Documents/ . # 下载目录
Fetching /home/ubuntu/Documents/ to ./Documents
Retrieving /home/ubuntu/Documents
Retrieving /home/ubuntu/Documents/tmp
/home/ubuntu/Documents/tmp/test 100% 12KB 3.9MB/s 00:00
/home/ubuntu/Documents/tmp/test_for.c 100% 92 51.2KB/s 00:00
remote open("/home/ubuntu/Documents/tmp/core"): Permission denied
...
sftp> !ls # !shellcmd
a.out Documents test.c
sftp> !mkdir test # 使用命令在本地创建目录
sftp> ls # 显示远程目录
Documents Download vimtutor
sftp> !ls # 显示本地目录
a.out Documents test test.c
sftp> put -r test/
Uploading test/ to /home/ubuntu/test
Entering test/
sftp> mkdir testpi # 创建远程目录
sftp> !ls # 查看本地目录
a.out Documents test test.c
sftp> ls # 查看远程目录
Documents Download test testpi vimtutor


put [-afPpr] local-path [remote-path]Upload local-path and store it on the remote machine. If theremote path name is not specified, it is given the same name ithas on the local machine. local-path may contain glob(3) charac‐ters and may match multiple files. If it does and remote-path isspecified, then remote-path must specify a directory.If the -a flag is specified, then attempt to resume partialtransfers of existing files. Note that resumption assumes thatany partial copy of the remote file matches the local copy. Ifthe local file contents differ from the remote local copy thenthe resultant file is likely to be corrupt.If the -f flag is specified, then a request will be sent to theserver to call fsync(2) after the file has been transferred.Note that this is only supported by servers that implement the"fsync@openssh.com" extension.If either the -P or -p flag is specified, then full file permis‐sions and access times are copied too.If the -r flag is specified then directories will be copiedrecursively. Note that sftp does not follow symbolic links whenperforming recursive transfers.get [-afPpr] remote-path [local-path]Retrieve the remote-path and store it on the local machine. Ifthe local path name is not specified, it is given the same nameit has on the remote machine. remote-path may contain glob(3)characters and may match multiple files. If it does andlocal-path is specified, then local-path must specify a direc‐tory.If the -a flag is specified, then attempt to resume partialtransfers of existing files. Note that resumption assumes thatany partial copy of the local file matches the remote copy. Ifthe remote file contents differ from the partial local copy thenthe resultant file is likely to be corrupt.If the -f flag is specified, then fsync(2) will be called afterthe file transfer has completed to flush the file to disk.If either the -P or -p flag is specified, then full file permis‐sions and access times are copied too.If the -r flag is specified then directories will be copiedrecursively. Note that sftp does not follow symbolic links whenperforming recursive transfers.

遇到问题:

remote open("/home/ubuntu/Documents/gdb.txt"): Permission denied

解决方法:

可以先ssh,改变目录所属权限,增加写权限。然后再 sftp

字节错位问题

判断两个字节是否为一组,如果不是那么顺延一个字节。

缓冲区数据较少的问题

判断个数是否符合要求,如果不符合,那么就重传。


推荐阅读
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
  • 本文讨论了如何使用GStreamer来删除H264格式视频文件中的中间部分,而不需要进行重编码。作者提出了使用gst_element_seek(...)函数来实现这个目标的思路,并提到遇到了一个解决不了的BUG。文章还列举了8个解决方案,希望能够得到更好的思路。 ... [详细]
  • 本文介绍了5个基本Linux命令行工具的现代化替代品,包括du、top和ncdu。这些替代品在功能上进行了改进,提高了可用性,并且适用于现代化系统。其中,ncdu是du的替代品,它提供了与du类似的结果,但在一个基于curses的交互式界面中,重点关注占用磁盘空间较多的目录。 ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 本文介绍了一个误删Oracle数据文件导致数据库无法打开的问题,并提供了解决方式。解决方式包括切换到mount状态、离线删除报错的数据文件等。 ... [详细]
  • 纠正网上的错误:自定义一个类叫java.lang.System/String的方法
    本文纠正了网上关于自定义一个类叫java.lang.System/String的错误答案,并详细解释了为什么这种方法是错误的。作者指出,虽然双亲委托机制确实可以阻止自定义的System类被加载,但通过自定义一个特殊的类加载器,可以绕过双亲委托机制,达到自定义System类的目的。作者呼吁读者对网上的内容持怀疑态度,并带着问题来阅读文章。 ... [详细]
  • 在Oracle11g以前版本中的的DataGuard物理备用数据库,可以以只读的方式打开数据库,但此时MediaRecovery利用日志进行数据同步的过 ... [详细]
  • 图像因存在错误而无法显示 ... [详细]
  • ***byte(字节)根据长度转成kb(千字节)和mb(兆字节)**parambytes*return*publicstaticStringbytes2kb(longbytes){ ... [详细]
  • 本文整理了Java面试中常见的问题及相关概念的解析,包括HashMap中为什么重写equals还要重写hashcode、map的分类和常见情况、final关键字的用法、Synchronized和lock的区别、volatile的介绍、Syncronized锁的作用、构造函数和构造函数重载的概念、方法覆盖和方法重载的区别、反射获取和设置对象私有字段的值的方法、通过反射创建对象的方式以及内部类的详解。 ... [详细]
  • 本文介绍了使用数据库管理员用户执行onstat -l命令来监控GBase8s数据库的物理日志和逻辑日志的使用情况,并强调了对已使用的逻辑日志是否及时备份的重要性。同时提供了监控方法和注意事项。 ... [详细]
author-avatar
天使的眼泪174
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有