随笔分类 -  c/c++

摘要:定义的变量名称重复, 例如: int look_up_max(int m, int n) { int m; //... return m; } 阅读全文
posted @ 2019-05-30 16:58 hbg-rohens 阅读(2376) 评论(0) 推荐(0)
摘要:sizeof 后面所跟的数据类型没有定义,或者找不到定义的地方 eg: 头文件中定义结构体如下: struct PersonaL{ char name[]; int age; }; 但是在cpp中使用时如下: struct personal a; int len = sizeof(a); 阅读全文
posted @ 2019-05-30 16:54 hbg-rohens 阅读(5282) 评论(0) 推荐(0)
摘要:GCC: GNU C Complier(GNU C 编译器)不仅仅能支持C语言,它现在还支持 Ada、C++、Java、Objective-C、Pascal、COBOL 以及函数式编程和逻辑编程的Mercury 语言等。因此,现在的 gcc 已经变成了 GNU Compiler Collection 阅读全文
posted @ 2019-05-24 19:22 hbg-rohens 阅读(1005) 评论(0) 推荐(0)
摘要:在产生一个随机字符序列时,当要生成的字符串数据为8位时,会不时的在后面加上"\u0001",而多于8位时,例如9位,则不会出现该问题。 mark一下!!!! 阅读全文
posted @ 2019-05-22 17:23 hbg-rohens 阅读(6807) 评论(0) 推荐(0)
摘要:文件目录结构体为: src 和include 分别用来存放.cpp文件和 .hpp文件 其中:src文件夹下有需要的文件 simulator_client.cpp crc32.cpp ; include文件夹下有对应的头文件 simulator_client.hpp、crc32.h及使用的头文件cJ 阅读全文
posted @ 2019-05-22 09:45 hbg-rohens 阅读(17247) 评论(0) 推荐(0)
摘要:github地址: https://github.com/DaveGamble/cJSON需要将cJSON.h 和 cJSON.c拷贝到路径下,并且连接所需库文件 -lm步骤:1、先将普通的json串处理成json对象,也就是所谓的创建json root的过程char *js_string;cJSO 阅读全文
posted @ 2019-05-07 19:27 hbg-rohens 阅读(461) 评论(0) 推荐(0)
摘要:gilhub上已有开源项目: https://github.com/cepr/android-serialport-api 可以直接使用 阅读全文
posted @ 2019-03-12 17:55 hbg-rohens 阅读(1860) 评论(0) 推荐(0)
摘要:问题描述: ubuntu 16.04 下 C语言开发环境, 已经添加了头文件#include <pthread.h> 以及在Makefile中添加了 -lpthread,但是编译时仍然报错: undefined reference to `pthread_create' 百度后得知,ubuntu下- 阅读全文
posted @ 2019-02-22 10:50 hbg-rohens 阅读(1955) 评论(0) 推荐(0)
摘要:https://github.com/brtiberio/ATV71_CANopen.git https://github.com/linux-can/can-utils.githttps://github.com/CANopenNode/CANopenNode.git https://github 阅读全文
posted @ 2018-12-27 14:25 hbg-rohens 阅读(328) 评论(0) 推荐(0)
摘要:float hex_to_float(uint8_t *data) { float num = 0.0; uint8_t dd[4] = {data[0], data[1], data[2], data[3]}; float *ret = (float *)dd; num = *ret; print 阅读全文
posted @ 2018-12-24 11:46 hbg-rohens 阅读(2911) 评论(0) 推荐(0)
摘要:调用函数(setsockopt)来设置 recv buffer 和send buffer时报错: setsockopt error: Socket operation on non-socket(errno: 88) 原因在于 setsockopt 的 第一个参数为 socket通信使用的文件描述符 阅读全文
posted @ 2018-12-17 10:07 hbg-rohens 阅读(3476) 评论(0) 推荐(0)
摘要:/*把ASCII字符转换为16进制 */ uint8_t char_to_hex(const uint8_t *ch) { uint8_t value = 0; if(*ch >= 0 && *ch <= 9) { value = *ch + 0x30; } else if(*ch >=10 && 阅读全文
posted @ 2018-12-15 16:45 hbg-rohens 阅读(13259) 评论(0) 推荐(0)
摘要:目前涉及到的主要有两种: 1、每隔一段时间执行 QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(1000); // 1秒 2、单独执行一次 阅读全文
posted @ 2018-12-06 16:36 hbg-rohens 阅读(226) 评论(0) 推荐(0)
摘要:当库文件中包含多个头文件和c源文件时,需要执行如下步骤: 1) makefile中添加 库文件依赖, -L 后面跟库文件的路径, -l(小写)后面跟库的名字 2)将库文件中的头文件添加到工程中去,使的编译时可以找到。 可以使用-I后面跟头文件的路径。 阅读全文
posted @ 2018-11-29 16:59 hbg-rohens 阅读(7580) 评论(0) 推荐(0)
摘要:在QT中定义了一个线程类,继承自QThread, 在类中未加 Q_OBJECT 时编译正常,加入后报错如下: undefined reference to `vtable for myThread' 在串口下,手动make,无错误。 百度后得知: 一:预编译器打开宏Q_OBJECT,声明若干个由mo 阅读全文
posted @ 2018-11-23 08:50 hbg-rohens 阅读(4355) 评论(0) 推荐(0)
摘要:RS485通信接收方,丢弃掉了值为 0x11 的数据。 怀疑 0x11 被转义,没有按照原始数据接收, 查看ASCII码对应表 0x11 代表 “本文结束”, 因此丢弃是有可能的。 要想接收原始数据而不被转义,需要修改串口的 c_iflag, 修改为如下 c_iflag &= ~(ICRNL | I 阅读全文
posted @ 2018-10-19 08:44 hbg-rohens 阅读(1186) 评论(0) 推荐(0)
摘要:1、 time() 函数提供了 秒 级的精确度 time_t time(time_t * timer) 函数返回从UTC1970-1-1 0:0:0开始到现在的秒数 2、 struct timespec 提供了 ns 级的精确度 定义如下: typedef long time_t; #ifndef 阅读全文
posted @ 2018-10-10 11:48 hbg-rohens 阅读(2294) 评论(0) 推荐(0)
摘要:自己动手写了创建虚拟接口,删除虚拟接口程序,频繁调用创建删除时,有时将接口up起来时会报错: Name not unique on network 利用ip link命令来查看接口(及其对应的索引) 可以查看到与其他接口不同的是有个标志为 NO-CARRIER,不知道是什么意思,查看ip的源代码(此 阅读全文
posted @ 2018-06-06 17:26 hbg-rohens 阅读(9865) 评论(0) 推荐(0)
摘要:在涉及套接字的I/O操作上设置超时的方法有一下3种: (1)调用alarm,它在指定超时期满时产生SIGALRM信号,这个方法涉及信号处理,而信号处理在不同的实现上存在差异,而且可能干扰进程中现有的alarm调用 (2)在select中阻塞等待 I/O (select有内置的时间限制),以此代替直接 阅读全文
posted @ 2018-06-02 11:45 hbg-rohens 阅读(566) 评论(0) 推荐(0)
摘要:写代码这么久,竟然很少用到perror函数,忘记了其强大的功能。 所在头文件: #include<stdio.h> 函数定义: void perror(const char *str); 函数功能: 将上一个函数发生错误的原因输出到标准设备(stderr)。参数str为所先打印的字符串,后面跟错误原 阅读全文
posted @ 2018-05-21 16:41 hbg-rohens 阅读(290) 评论(0) 推荐(0)