Compare commits
	
		
			No commits in common. "8.8Upgrade_version" and "风火轮发布版" have entirely different histories.
		
	
	
		
			8.8Upgrade
			...
			风火轮发布版
		
	
		
							
								
								
									
										195
									
								
								NEWREADME.md
									
									
									
									
									
								
							
							
						
						
									
										195
									
								
								NEWREADME.md
									
									
									
									
									
								
							| @ -1,195 +0,0 @@ | |||||||
| # 8.8升级 |  | ||||||
| 
 |  | ||||||
| ## 升级内容 |  | ||||||
| 
 |  | ||||||
| ### 增加消防水位检测功能 |  | ||||||
| 
 |  | ||||||
| 针对消防水位的的检测,ADC文件路径:/sys/bus/iio/devices/iio:device0/in_voltage2_raw;设置ADC检测值为1000,一小时检测一次;如果超过便输出0;小于1000则输出1 |  | ||||||
| 
 |  | ||||||
| 指定IP地址,摄像头本身具有多个IP地址;指定有线网络接口:eth0并读取该IP地址 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| # 7.11升级 |  | ||||||
| 
 |  | ||||||
| ## 升级内容 |  | ||||||
| 
 |  | ||||||
| **一、*****\*新增消防控制功能\**** |  | ||||||
| 
 |  | ||||||
| 摄像头硬件升级后,增加5路IO输出、1路IO报警输入的功能。 |  | ||||||
| 
 |  | ||||||
| 1-4路IO输出为电磁阀控制; |  | ||||||
| 
 |  | ||||||
| 5路为水泵电源控制和充电设备断电控制; |  | ||||||
| 
 |  | ||||||
| 1路输入为消防水箱液位报警输入; |  | ||||||
| 
 |  | ||||||
| | ***\*IO口\**** | ***\*GPIO\**** | ***\*控制\**** | |  | ||||||
| | -------------- | -------------- | -------------- | |  | ||||||
| | 1              | 116            | 电磁阀1        | |  | ||||||
| | 2              | 18             | 电磁阀2        | |  | ||||||
| | 3              | 19             | 电磁阀3        | |  | ||||||
| | 4              | 103            | 电磁阀4        | |  | ||||||
| | 5              | 102            | 水泵、电源控制 | |  | ||||||
| 
 |  | ||||||
| ***\*GPIO控制指令:\**** |  | ||||||
| 
 |  | ||||||
| cd /sys/class/gpio |  | ||||||
| 
 |  | ||||||
| echo 18 > export // 导出gpio |  | ||||||
| 
 |  | ||||||
| echo out > gpio18/direction // 设置gpio输出 |  | ||||||
| 
 |  | ||||||
| echo 0 > gpio18/value // 设置gpio输出0 (关闭) |  | ||||||
| 
 |  | ||||||
| echo 1 > gpio18/value // 设置gpio输出1 (打开) |  | ||||||
| 
 |  | ||||||
|   |  | ||||||
| 
 |  | ||||||
| ***\*报警处理:\**** |  | ||||||
| 
 |  | ||||||
| 1、摄像头监测到区域报警,调用摄像头IO输出控制相应区域消防喷淋;先打开报警区域对应电磁阀开关、再打开水泵开关。 |  | ||||||
| 
 |  | ||||||
| 2、1-4检测报警区域对应1-4号IO口。如1号区域报警,则将1号IO口116输出1打开1号电磁阀,同时打开5号IO口水泵电源。5秒内没有再出现报警则关闭电磁阀。 |  | ||||||
| 
 |  | ||||||
|   |  | ||||||
| 
 |  | ||||||
| ***\*处理流程:\**** |  | ||||||
| 
 |  | ||||||
| 设置一个全局数组保存5个IO口的状态,int state[5] = {0,0,0,0,0} |  | ||||||
| 
 |  | ||||||
| 1、摄像头区域报警时开启喷淋控制: |  | ||||||
| 
 |  | ||||||
| 先判定对应区域状态:如果区域状态为0,则打开区域对应IO口(输出1),同时将区域状态置为6;区域状态不为0,则直接将区域状态置为6; |  | ||||||
| 
 |  | ||||||
| 再判定5号IO口水泵状态:如果水泵状态为0,则打开水泵对应5号IO口(输出1),同时将水泵状态置为6;水泵状态不为0,则直接将水泵状态置为6; |  | ||||||
| 
 |  | ||||||
| 2、开启一个线程处理IO状态和IO关闭处理。 |  | ||||||
| 
 |  | ||||||
| 监听所有IO状态,当IO状态不为0时,每间隔1秒状态值减1; |  | ||||||
| 
 |  | ||||||
| 状态值为1时,关闭对应IO口并将状态值置为0。 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ## 注意事项: |  | ||||||
| 
 |  | ||||||
| 时间0秒:区域1报警 → state[0] = 6 (电磁阀1打开) |  | ||||||
| 
 |  | ||||||
| 时间1秒:监控线程 → state[0] = 5 (还剩5秒) |  | ||||||
| 
 |  | ||||||
| 时间2秒:监控线程 → state[0] = 4 (还剩4秒) |  | ||||||
| 
 |  | ||||||
| 时间3秒:监控线程 → state[0] = 3 (还剩3秒) |  | ||||||
| 
 |  | ||||||
| 时间4秒:监控线程 → state[0] = 2 (还剩2秒) |  | ||||||
| 
 |  | ||||||
| 时间5秒:监控线程 → state[0] = 1 (还剩1秒,准备关闭) |  | ||||||
| 
 |  | ||||||
| 时间6秒:监控线程 → state[0] = 0 (关闭电磁阀1) |  | ||||||
| 
 |  | ||||||
|   |  | ||||||
| 
 |  | ||||||
| 发现问题: |  | ||||||
| 
 |  | ||||||
| 增加成上述内容步骤后,启动线程控制台打印报警信息,接收器没有接收到报警信息并输出 |  | ||||||
| 
 |  | ||||||
| 判断: |  | ||||||
| 
 |  | ||||||
| 1.请求的URL地址是否出错 |  | ||||||
| 
 |  | ||||||
| 2.测试接收器是否能接收到该网段的信息 |  | ||||||
| 
 |  | ||||||
| 结果: |  | ||||||
| 
 |  | ||||||
| 1.强制指定部分URL地址,例如:http://192.168.1.23:9527/device/alarm,2,3 IO口 可以接受信息,更换4,5无法接收 |  | ||||||
| 
 |  | ||||||
| 修正: |  | ||||||
| 
 |  | ||||||
| 如何让各个通道都能接收到信息 |  | ||||||
| 
 |  | ||||||
| 最终定义: |  | ||||||
| 
 |  | ||||||
| 地址类型转换错误 |  | ||||||
| 
 |  | ||||||
| 原1631-1632行 |  | ||||||
| 
 |  | ||||||
| // curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.23:9527/device/alarm"); |  | ||||||
| 
 |  | ||||||
|    curl_easy_setopt(curl, CURLOPT_URL,ALARM_URL);  |  | ||||||
| 
 |  | ||||||
| 因为ALARM_URL是需要std::string类型定义地址,所以使用c_str即可; |  | ||||||
| 
 |  | ||||||
|     curl_easy_setopt(curl, CURLOPT_URL, ALARM_URL.c_str()); |  | ||||||
| 
 |  | ||||||
| # 5.26修改 |  | ||||||
| 
 |  | ||||||
| ## 本串口协议必备要求:先发送在接收 |  | ||||||
| 
 |  | ||||||
| ## 注:本项目已经通过串口测试(传感器为115200,摄像头为9500),每次报警前会识别设备名称序号,然后反馈到串口输出序列中 |  | ||||||
| 
 |  | ||||||
| # rknn_yolo_EAI_pic |  | ||||||
| 
 |  | ||||||
| #### 简要说明 |  | ||||||
| 
 |  | ||||||
| 用于跑EAI提供仓库训练出来的yolov5模型的视频检测例程。 |  | ||||||
| 集成了从串口读取红外温度数据,到达阈值后报警并运行rknn模型 |  | ||||||
| 
 |  | ||||||
| 需注意运行该例程需要将npu驱动更新为1.7.3版本 |  | ||||||
| 
 |  | ||||||
| 本项目只适用于EAI-YOLOV5 |  | ||||||
| 详情请参考EAI官网:https://www.easy-eai.com/document_details/3/342 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ## 准备工作 |  | ||||||
| 根据EAI给出的教程训练、转化得到rknn模型 |  | ||||||
| 有两类检测模型:火焰检测和烟雾检测 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ## 安装(install) |  | ||||||
| 
 |  | ||||||
| 通过adb连接设备并将编译结果推送至板端,执行以下命令推送,这里板端默认使用/userdata路径 |  | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| adb push install/rknn_yolo_demo /userdata/ |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| 将前面准备好的RKNN模型推送至板端,这里假设模型名字为 yolov5s_u8.rknn |  | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| adb push ./yolov5s_u8.rknn /userdata/rknn_yolo_demo/model/yolov5s_u8.rknn |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ## 单图测试执行 |  | ||||||
| 详情请了解官网:9.模型部署实例 |  | ||||||
| 
 |  | ||||||
| 进入EAI环境之后编译,将编译文件放置到可执行程序,假设是first_yolov5_detect_demo |  | ||||||
| 用下列命令将可执行程序推送到开发板端 |  | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| cp first_yolov5_detect_demo/ /mnt/userdata/ -rf |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| 进入办卡运行环境 |  | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| adb shell |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| 定位到指定位置后,运行程序 |  | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| ./rknn_yolo_EAI |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ## 编译(build) |  | ||||||
| 
 |  | ||||||
| 在项目文件中,根据设备,调整 GCC_COMPILER 参数,终端执行下面命令进行编译 |  | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| ./build.sh |  | ||||||
| ``` |  | ||||||
							
								
								
									
										67
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,67 @@ | |||||||
|  | ## 注:本项目已经通过串口测试(传感器为115200,摄像头为9500),每次报警前会识别设备名称序号,然后反馈到串口输出序列中 | ||||||
|  | 
 | ||||||
|  | # rknn_yolo_EAI_pic | ||||||
|  | 
 | ||||||
|  | #### 简要说明 | ||||||
|  | 
 | ||||||
|  | 用于跑EAI提供仓库训练出来的yolov5模型的视频检测例程。 | ||||||
|  | 集成了从串口读取红外温度数据,到达阈值后报警并运行rknn模型 | ||||||
|  | 
 | ||||||
|  | 需注意运行该例程需要将npu驱动更新为1.7.3版本 | ||||||
|  | 
 | ||||||
|  | 本项目只适用于EAI-YOLOV5 | ||||||
|  | 详情请参考EAI官网:https://www.easy-eai.com/document_details/3/342 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ## 准备工作 | ||||||
|  | 根据EAI给出的教程训练、转化得到rknn模型 | ||||||
|  | 有两类检测模型:火焰检测和烟雾检测 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ## 安装(install) | ||||||
|  | 
 | ||||||
|  | 通过adb连接设备并将编译结果推送至板端,执行以下命令推送,这里板端默认使用/userdata路径 | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | adb push install/rknn_yolo_demo /userdata/ | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | 将前面准备好的RKNN模型推送至板端,这里假设模型名字为 yolov5s_u8.rknn | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | adb push ./yolov5s_u8.rknn /userdata/rknn_yolo_demo/model/yolov5s_u8.rknn | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ## 单图测试执行 | ||||||
|  | 详情请了解官网:9.模型部署实例 | ||||||
|  | 
 | ||||||
|  | 进入EAI环境之后编译,将编译文件放置到可执行程序,假设是first_yolov5_detect_demo | ||||||
|  | 用下列命令将可执行程序推送到开发板端 | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | cp first_yolov5_detect_demo/ /mnt/userdata/ -rf | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | 进入办卡运行环境 | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | adb shell | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | 定位到指定位置后,运行程序 | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | ./rknn_yolo_EAI | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ## 编译(build) | ||||||
|  | 
 | ||||||
|  | 在项目文件中,根据设备,调整 GCC_COMPILER 参数,终端执行下面命令进行编译 | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | ./build.sh | ||||||
|  | ``` | ||||||
| @ -1,81 +0,0 @@ | |||||||
| /***********************************************************************
 |  | ||||||
|  * @file jlinux_uart.h |  | ||||||
|      JLINUX_UART |  | ||||||
|  * @brief   header file |  | ||||||
|  * @history |  | ||||||
|  * Date       Version Author    description |  | ||||||
|  * ========== ======= ========= ======================================= |  | ||||||
|  * 2022-07-27 V1.0    Lucky,lukai@jovision.com   Create |  | ||||||
|  * |  | ||||||
|  * @Copyright (C)  2022  Jovision Technology Co., Ltd. |  | ||||||
| ***********************************************************************/ |  | ||||||
| #ifndef __JLINUX_UART_H__ |  | ||||||
| #define __JLINUX_UART_H__ |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" |  | ||||||
| { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| typedef struct _uart_ctx *juart_hdl_t; |  | ||||||
| 
 |  | ||||||
| typedef struct |  | ||||||
| { |  | ||||||
| 	int baudrate;   //波特率:1200/2400/4800/9600/19200/38400/57600/115200/230400/380400/460800/921600
 |  | ||||||
| 	int datawidth;  //数据位宽度:5/6/7/8
 |  | ||||||
| 	int stopbit;    //停止位宽度:1/2
 |  | ||||||
| 	int parity;		//奇偶校验:0无校验,1奇校验,2偶校验
 |  | ||||||
| }JUartAttr_t; |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 打开串口设备设备,如果是485设备请配合jctrl_rs485相关接口使用 |  | ||||||
|  *@param name 设备名称,如:/dev/ttyS0 |  | ||||||
|  *@return 句柄 |  | ||||||
|  */ |  | ||||||
| juart_hdl_t juart_open(const char *name); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 关闭串口 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  */ |  | ||||||
| int juart_close(juart_hdl_t handle); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 配置串口属性 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  *@param attr 属性 |  | ||||||
|  */ |  | ||||||
| int juart_set_attr(juart_hdl_t handle, JUartAttr_t *attr); |  | ||||||
| 
 |  | ||||||
| int juart_get_fd(juart_hdl_t uart); |  | ||||||
| /**
 |  | ||||||
|  *@brief 通过串口发送数据 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  *@param data 数据buffer |  | ||||||
|  *@param len 数据长度 |  | ||||||
|  *@return 0成功 |  | ||||||
|  */ |  | ||||||
| int juart_send(juart_hdl_t handle, char *data, int len); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 通过串口接受数据 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  *@param data 数据buffer |  | ||||||
|  *@param len buffer的长度 |  | ||||||
|  *@param timeout 超时毫秒 |  | ||||||
|  *@return 收到数据的长度 |  | ||||||
|  */ |  | ||||||
| int juart_recv(juart_hdl_t handle, char *data, int len, int timeout); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 设置rs485模式 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  *@param mode 0:发送后立刻置为接收状态;非0:发送后保持发送状态 |  | ||||||
|  *@return 0 成功 |  | ||||||
|  */ |  | ||||||
| int juart_set_rs485(juart_hdl_t handle, int mode); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| #endif // __JLINUX_UART_H__
 |  | ||||||
							
								
								
									
										2129
									
								
								src/8.8main.cpp
									
									
									
									
									
								
							
							
						
						
									
										2129
									
								
								src/8.8main.cpp
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -1,313 +0,0 @@ | |||||||
| /***********************************************************************
 |  | ||||||
|  * @file jctrl_uart.cpp |  | ||||||
|      JCTRL_UART |  | ||||||
|  * @brief   header file |  | ||||||
|  * @history |  | ||||||
|  * Date       Version Author    description |  | ||||||
|  * ========== ======= ========= ======================================= |  | ||||||
|  * 2022-07-21 V1.0    Lucky,lukai@jovision.com   Create |  | ||||||
|  * |  | ||||||
|  * @Copyright (C)  2022  Jovision Technology Co., Ltd. |  | ||||||
| ***********************************************************************/ |  | ||||||
| #include <termios.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include <stdio.h> |  | ||||||
| #include <string.h> |  | ||||||
| #include <unistd.h> |  | ||||||
| #include <errno.h> |  | ||||||
| #include <linux/stat.h> |  | ||||||
| #include <sys/prctl.h> |  | ||||||
| #include <sys/ioctl.h> |  | ||||||
| #include <sys/types.h> |  | ||||||
| #include <fcntl.h> |  | ||||||
| #include <linux/serial.h> |  | ||||||
| #include "jlinux_uart.h" |  | ||||||
| 
 |  | ||||||
| struct _uart_ctx{ |  | ||||||
|     int fd; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| int _get_baudrate(int nBaud) |  | ||||||
| { |  | ||||||
|     switch(nBaud) |  | ||||||
|     { |  | ||||||
|     case 1200: |  | ||||||
|         return B1200;	//注:B1200为系统定义
 |  | ||||||
|     case 2400: |  | ||||||
|         return B2400; |  | ||||||
|     case 4800: |  | ||||||
|         return B4800; |  | ||||||
|     case 9600: |  | ||||||
|         return B9600; |  | ||||||
|  	case 19200 : |  | ||||||
|         return B19200; |  | ||||||
| 	case 38400: |  | ||||||
| 	     return B38400; |  | ||||||
| 	case 57600: |  | ||||||
| 	     return B57600; |  | ||||||
| 	case 115200: |  | ||||||
| 	     return B115200; |  | ||||||
|     default: |  | ||||||
|         return B2400; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| juart_hdl_t juart_open(const char *name){ |  | ||||||
|     juart_hdl_t uart = new _uart_ctx; |  | ||||||
|     uart->fd = open(name, O_RDWR | O_NONBLOCK | O_NOCTTY |  O_EXCL|O_SYNC); |  | ||||||
|     return uart; |  | ||||||
| } |  | ||||||
| int juart_close(juart_hdl_t uart){ |  | ||||||
|     if(uart->fd>0) |  | ||||||
| 		close(uart->fd); |  | ||||||
| 	uart->fd = 0; |  | ||||||
|     return 0; |  | ||||||
| } |  | ||||||
| int juart_get_fd(juart_hdl_t uart){ |  | ||||||
|     return uart->fd; |  | ||||||
| } |  | ||||||
| int juart_set_attr(juart_hdl_t uart, JUartAttr_t *attr){ |  | ||||||
|     if (uart->fd <= 0) |  | ||||||
|     { |  | ||||||
|         printf("jv_uart_recv_ex fd error\n"); |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     struct termios newtio, oldtio; |  | ||||||
|     memset(&oldtio, 0, sizeof(oldtio)); |  | ||||||
|     /* save the old serial port configuration */ |  | ||||||
|     if (tcgetattr(uart->fd, &oldtio) != 0) { |  | ||||||
|         perror("set_port/tcgetattr"); |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     memset(&newtio, 0, sizeof(newtio)); |  | ||||||
|     //设置波特率
 |  | ||||||
|     int nBaud = _get_baudrate(attr->baudrate); |  | ||||||
|     switch (nBaud) |  | ||||||
|     { |  | ||||||
|     case B300: |  | ||||||
|     case B1200: |  | ||||||
|     case B2400: |  | ||||||
|     case B4800: |  | ||||||
|     case B9600: |  | ||||||
|     case B19200: |  | ||||||
|     case B38400: |  | ||||||
|     case B57600: |  | ||||||
|     case B115200: |  | ||||||
|         cfsetospeed(&newtio, nBaud); |  | ||||||
|         cfsetispeed(&newtio, nBaud); |  | ||||||
|         break; |  | ||||||
|     default: |  | ||||||
|         printf("jv_uart_set_attr:Unsupported baudrate!\n"); |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     /* ignore modem control lines and enable receiver */ |  | ||||||
|     newtio.c_cflag |= CLOCAL | CREAD; |  | ||||||
|     newtio.c_cflag &= ~CSIZE; |  | ||||||
|     /* set character size */ |  | ||||||
|     switch (attr->datawidth) { |  | ||||||
|     case 5: |  | ||||||
|         newtio.c_cflag |= CS5; |  | ||||||
|         break; |  | ||||||
|     case 6: |  | ||||||
|         newtio.c_cflag |= CS6; |  | ||||||
|         break; |  | ||||||
|     case 7: |  | ||||||
|         newtio.c_cflag |= CS7; |  | ||||||
|         break; |  | ||||||
|     case 8: |  | ||||||
|     default: |  | ||||||
|         newtio.c_cflag |= CS8; |  | ||||||
|         break; |  | ||||||
|     } |  | ||||||
|     /* set the stop bits */ |  | ||||||
|     switch (attr->stopbit) { |  | ||||||
|     default: |  | ||||||
|     case 1: |  | ||||||
|         newtio.c_cflag &= ~CSTOPB; |  | ||||||
|         break; |  | ||||||
|     case 2: |  | ||||||
|         newtio.c_cflag |= CSTOPB; |  | ||||||
|         break; |  | ||||||
|     } |  | ||||||
|     /* set the parity */ |  | ||||||
|     switch (attr->parity) { |  | ||||||
|     case 'o': |  | ||||||
|     case 'O': |  | ||||||
|     case 1: |  | ||||||
|         newtio.c_cflag |= PARENB; |  | ||||||
|         newtio.c_cflag |= PARODD; |  | ||||||
|         newtio.c_iflag |= INPCK; |  | ||||||
|         break; |  | ||||||
|     case 'e': |  | ||||||
|     case 'E': |  | ||||||
|     case 2: |  | ||||||
|         newtio.c_cflag |= PARENB; |  | ||||||
|         newtio.c_cflag &= ~PARODD; |  | ||||||
|         newtio.c_iflag |= INPCK; |  | ||||||
|         break; |  | ||||||
|     case 'n': |  | ||||||
|     case 'N': |  | ||||||
|     case 0: |  | ||||||
|     default: |  | ||||||
|         newtio.c_cflag &= ~PARENB; |  | ||||||
|         newtio.c_iflag &= ~INPCK; |  | ||||||
|         break; |  | ||||||
|     } |  | ||||||
|     /* Raw input */ |  | ||||||
|     newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); |  | ||||||
|     /* Software flow control is disabled */ |  | ||||||
|     newtio.c_iflag &= ~(IXON | IXOFF | IXANY); |  | ||||||
|     /* Raw ouput */ |  | ||||||
|     newtio.c_oflag &=~ OPOST; |  | ||||||
|     /* set timeout in deciseconds for non-canonical read */ |  | ||||||
|     newtio.c_cc[VTIME] = 0; |  | ||||||
|     /* set minimum number of characters for non-canonical read */ |  | ||||||
|     newtio.c_cc[VMIN] = 0; |  | ||||||
|     /* flushes data received but not read */ |  | ||||||
|     tcflush(uart->fd, TCIFLUSH); |  | ||||||
|     /* set the parameters associated with the terminal from
 |  | ||||||
|         the termios structure and the change occurs immediately */ |  | ||||||
|     if ((tcsetattr(uart->fd, TCSANOW, &newtio)) != 0) { |  | ||||||
|         perror("set_port/tcsetattr"); |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     return 0; |  | ||||||
| } |  | ||||||
| int juart_send(juart_hdl_t uart, char *data, int len){ |  | ||||||
|     if (uart->fd > 0) |  | ||||||
|     { |  | ||||||
|         int ret = write(uart->fd, data, len); |  | ||||||
|         if (ret == len) |  | ||||||
|             return 0; |  | ||||||
|     } |  | ||||||
|     return -1; |  | ||||||
| } |  | ||||||
| int _modbus_rtu_select(juart_hdl_t uart, struct timeval *tv) |  | ||||||
| { |  | ||||||
|     fd_set rfds; |  | ||||||
|     FD_ZERO(&rfds); |  | ||||||
|     FD_SET(uart->fd, &rfds); |  | ||||||
|     int s_rc; |  | ||||||
|     while ((s_rc = select(uart->fd+1, &rfds, NULL, NULL, tv)) == -1) { |  | ||||||
|         if (errno == EINTR) { |  | ||||||
|             fprintf(stderr, "A non blocked signal was caught\n"); |  | ||||||
|             /* Necessary after an error */ |  | ||||||
|             FD_ZERO(&rfds); |  | ||||||
|             FD_SET(uart->fd, &rfds); |  | ||||||
|         } else { |  | ||||||
|             return -1; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     if (s_rc == 0) { |  | ||||||
|         /* Timeout */ |  | ||||||
|         errno = ETIMEDOUT; |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     return s_rc; |  | ||||||
| } |  | ||||||
| int juart_recv(juart_hdl_t uart, char *data, int len, int timeout){ |  | ||||||
|     if (uart->fd > 0) |  | ||||||
|     { |  | ||||||
|         struct timeval tv; |  | ||||||
|         tv.tv_sec = 0; |  | ||||||
|         tv.tv_usec = timeout*1000; |  | ||||||
|         if(_modbus_rtu_select(uart, &tv) > 0){ |  | ||||||
|             return read(uart->fd, data, len); |  | ||||||
|         } |  | ||||||
|         return -1; |  | ||||||
|     }else{ |  | ||||||
|         usleep(timeout*1000); |  | ||||||
|     } |  | ||||||
|     return -1; |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 接收串口数据扩展接口,从收到start开始接收,到收到stop返回 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  *@param data 接收数据缓存 |  | ||||||
|  *@param len 缓存大小 |  | ||||||
|  *@param start 数据头标志:前nstart个字节 |  | ||||||
|  *@param nstart 数据头字节数 |  | ||||||
|  *@param stop 数据截止标志:后nstop个字节 |  | ||||||
|  *@param nstop 数据截止标志的字节数 |  | ||||||
|  */ |  | ||||||
| extern "C" int juart_recv_ex(juart_hdl_t handle, char *data, int len, char *start, int nstart, char *stop, int nstop, int timeout); |  | ||||||
| int juart_recv_ex(juart_hdl_t uart, char *data, int len, char *start, int nstart, char *stop, int nstop, int timeout){ |  | ||||||
|     if (uart->fd <= 0) |  | ||||||
|     { |  | ||||||
|         printf("jv_uart_recv_ex fd error\n"); |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     int offset = 0; |  | ||||||
|     int offset_end = 0; |  | ||||||
|     int bytes_read = 0; |  | ||||||
|     while (1) |  | ||||||
|     { |  | ||||||
|         bytes_read = read(uart->fd, &data[offset], 1); |  | ||||||
|         if (bytes_read == 1 && offset < nstart && data[offset] == start[offset]) |  | ||||||
|         { |  | ||||||
|             offset++; |  | ||||||
|         } |  | ||||||
|         if (offset == nstart) |  | ||||||
|             break; |  | ||||||
|         if (bytes_read < 1) |  | ||||||
|             usleep(0); |  | ||||||
|     } |  | ||||||
|     while (offset < len) |  | ||||||
|     { |  | ||||||
|         if (data[offset] == stop[offset_end]) |  | ||||||
|         { |  | ||||||
|             offset_end++; |  | ||||||
|         } |  | ||||||
|         if (offset_end == nstop) |  | ||||||
|             break; |  | ||||||
|         bytes_read = read(uart->fd, &data[offset], 1); |  | ||||||
|         if (bytes_read == 1) |  | ||||||
|         { |  | ||||||
|             offset++; |  | ||||||
|         } |  | ||||||
|         else |  | ||||||
|         { |  | ||||||
|             usleep(0); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     return offset; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *@brief 设置rs485模式 |  | ||||||
|  *@param handle 句柄 |  | ||||||
|  *@param mode 0:发送后立刻置为接收状态;非0:发送后保持发送状态 |  | ||||||
|  *@return 0 成功 |  | ||||||
|  */ |  | ||||||
| int juart_set_rs485(juart_hdl_t handle, int mode) |  | ||||||
| { |  | ||||||
|     struct serial_rs485 rs485; |  | ||||||
| 	if (ioctl(handle->fd, TIOCGRS485, &rs485) == -1) |  | ||||||
| 	{ |  | ||||||
| 		printf("TIOCGRS485 ioctl error.\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	rs485.flags |= SER_RS485_ENABLED; |  | ||||||
| 	if (mode == 0) |  | ||||||
| 	{ |  | ||||||
| 		rs485.flags &= ~SER_RS485_RTS_ON_SEND; |  | ||||||
| 		rs485.flags |= SER_RS485_RTS_AFTER_SEND; |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		rs485.flags |= SER_RS485_RTS_ON_SEND; |  | ||||||
| 		rs485.flags &= ~SER_RS485_RTS_AFTER_SEND; |  | ||||||
| 	} |  | ||||||
| 	rs485.delay_rts_before_send = 0; |  | ||||||
| 	rs485.delay_rts_after_send = 0; |  | ||||||
| 	if (ioctl(handle->fd, TIOCSRS485, &rs485) == -1) |  | ||||||
| 	{ |  | ||||||
| 	    printf("TIOCSRS485 ioctrl error.\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
							
								
								
									
										1729
									
								
								src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1729
									
								
								src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -62,8 +62,6 @@ void *upload_message_controller(void *args); | |||||||
| void *heart_beat(void *args);     //上传心跳检测
 | void *heart_beat(void *args);     //上传心跳检测
 | ||||||
| void *distortion(void *args);      //矫正
 | void *distortion(void *args);      //矫正
 | ||||||
| void *read_serial_thread(void *args); //读取串口传来的红外温度数据
 | void *read_serial_thread(void *args); //读取串口传来的红外温度数据
 | ||||||
| void *storage_serial_thread(void *args); |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| struct Alarm { | struct Alarm { | ||||||
|     int ifalarm; |     int ifalarm; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user