更新:蓝牙设备<---485--->上位机,透传功能完成
This commit is contained in:
parent
53bd382658
commit
dec8462463
|
@ -19,6 +19,11 @@
|
|||
#include "ip5310_i2c.h"
|
||||
#include "eeprom_spi.h"
|
||||
#include "stdlib.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
extern osThreadId task_lcdHandle;
|
||||
extern osThreadId task_menuHandle;
|
||||
extern uint8_t screen_suspend_flag;
|
||||
/**********************************************Drivers**********************************************/
|
||||
//
|
||||
//
|
||||
|
@ -154,6 +159,8 @@ extern SIG_TRANSMISSION sig_trans; //通讯模式
|
|||
|
||||
//绝对值计算
|
||||
#define MY_ABS(pa) ( ( (pa) >= 0 )?( (pa) ):( 0 - (pa) ) )
|
||||
#define LVGL_BREATHE_INTERVAL 5
|
||||
#define BLE_TASK_PERIOD 100
|
||||
|
||||
//屏幕显示
|
||||
void screen_run(void);
|
||||
|
|
152
App/BLE/ble.c
152
App/BLE/ble.c
|
@ -18,20 +18,32 @@ void transparent_bluetooth(st_scom *scom)
|
|||
{
|
||||
if (scom != &scom6_ble) return;
|
||||
|
||||
//来自蓝牙设备的数据是否接收完成
|
||||
if (scom->rx_flag == TRUE)
|
||||
{
|
||||
scom->rx_flag = FALSE;
|
||||
|
||||
//将接收到的数据存入485的tx,准备发送至上位机
|
||||
memcpy(scom2_rs485.tx_buff, scom->rx_buff, sizeof(scom->rx_buff));
|
||||
scom2_rs485.tx_len = scom->rx_len;
|
||||
scom2_rs485.tx_flag = TRUE;
|
||||
|
||||
//清空缓存区,等待新的数据
|
||||
memset(scom->rx_buff, 0, sizeof(scom->rx_buff));
|
||||
scom->rx_len = 0;
|
||||
}
|
||||
|
||||
//来自上位机的数据是否准备完毕
|
||||
if (scom->tx_flag == TRUE)
|
||||
{
|
||||
scom->tx_flag = FALSE;
|
||||
|
||||
//将tx中的数据发送至蓝牙设备
|
||||
ble_send(&huart6, scom6_ble.tx_buff);
|
||||
|
||||
//清空缓存区,等待新的数据
|
||||
memset(scom->tx_buff, 0, sizeof(scom->tx_buff));
|
||||
scom->tx_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,3 +58,143 @@ int8_t write_ble_id(char *id)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void write_ble_cmd(char *cmd)
|
||||
{
|
||||
if(!cmd) return;
|
||||
|
||||
usart_printf(&huart6, cmd);
|
||||
}
|
||||
|
||||
uint8_t ble_init_step = 0;
|
||||
uint8_t ble_cnt = 0;
|
||||
uint8_t ble_init(void)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
switch (ble_init_step)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if(ble_cnt == 0)
|
||||
{
|
||||
char ble_id[9];
|
||||
strcpy (ble_id, "00000001");
|
||||
|
||||
write_ble_id(ble_id); //修改蓝牙名称
|
||||
ble_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ble_cnt++;
|
||||
if( (ble_cnt * BLE_TASK_PERIOD) > 500)
|
||||
{
|
||||
ble_cnt = 0;
|
||||
ble_init_step++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if(ble_cnt == 0)
|
||||
{
|
||||
write_ble_cmd("AT+UUIDS=FFF0\r\n"); //主服务通道
|
||||
|
||||
ble_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ble_cnt++;
|
||||
if( (ble_cnt * BLE_TASK_PERIOD) > 500)
|
||||
{
|
||||
ble_cnt = 0;
|
||||
ble_init_step++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
if(ble_cnt == 0)
|
||||
{
|
||||
write_ble_cmd("AT+UUIDN=FFF1\r\n"); //读通道FFF1
|
||||
|
||||
ble_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ble_cnt++;
|
||||
if( (ble_cnt * BLE_TASK_PERIOD) > 500)
|
||||
{
|
||||
ble_cnt = 0;
|
||||
ble_init_step++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
if(ble_cnt == 0)
|
||||
{
|
||||
write_ble_cmd("AT+UUIDW=FFF2\r\n"); //写通道FFF2
|
||||
|
||||
ble_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ble_cnt++;
|
||||
if( (ble_cnt * BLE_TASK_PERIOD) > 500)
|
||||
{
|
||||
ble_cnt = 0;
|
||||
ble_init_step++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
{
|
||||
if(ble_cnt == 0)
|
||||
{
|
||||
write_ble_cmd("AT+REBOOT=1\r\n"); //重启
|
||||
|
||||
ble_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ble_cnt++;
|
||||
if( (ble_cnt * BLE_TASK_PERIOD) > 1000)
|
||||
{
|
||||
ble_cnt = 0;
|
||||
ble_init_step++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
{
|
||||
//清空缓存区(蓝牙配置时收获的响应)
|
||||
memset(scom6_ble.rx_buff, 0, sizeof(scom6_ble.rx_buff));
|
||||
scom6_ble.rx_len = 0;
|
||||
|
||||
ble_init_step++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,4 +13,8 @@ void transparent_bluetooth(st_scom *scom);
|
|||
|
||||
int8_t write_ble_id(char *id);
|
||||
|
||||
void write_ble_cmd(char *cmd);
|
||||
|
||||
uint8_t ble_init(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -57,12 +57,12 @@ void transparent_hart(st_scom *scom)
|
|||
|
||||
HART_RTS(RTS_OFF);
|
||||
|
||||
//DEVICE -> SIG
|
||||
//来自HART设备的数据是否接收完成
|
||||
if (scom->rx_flag == TRUE)
|
||||
{
|
||||
scom->rx_flag = FALSE;
|
||||
|
||||
//中断内接收到的数据是否符合HART数据报,符合则写入com485_tx,准备发送至PC
|
||||
//接收到的数据是否符合HART数据报,符合则写入485的tx,准备发送至上位机
|
||||
if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xAA))
|
||||
{
|
||||
//SIG -> PC
|
||||
|
@ -70,19 +70,27 @@ void transparent_hart(st_scom *scom)
|
|||
scom2_rs485.tx_len = scom->rx_len;
|
||||
scom2_rs485.tx_flag = TRUE;
|
||||
}
|
||||
|
||||
//清空缓存区,等待新的数据
|
||||
memset(scom->rx_buff, 0, sizeof(scom->rx_buff));
|
||||
scom->rx_len = 0;
|
||||
}
|
||||
|
||||
//SIG -> DEVICE
|
||||
//来自上位机的数据是否准备完毕
|
||||
if (scom->tx_flag == TRUE)
|
||||
{
|
||||
scom->tx_flag = FALSE;
|
||||
HART_RTS(RTS_ON);
|
||||
vTaskDelay(5);
|
||||
|
||||
//将tx中的数据发送至HART设备
|
||||
hart_send(&huart1, scom->tx_buff);
|
||||
|
||||
HART_RTS(RTS_OFF);
|
||||
|
||||
//清空缓存区,等待新的数据
|
||||
memset(scom->tx_buff, 0, sizeof(scom->tx_buff));
|
||||
scom->tx_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ void transparent_485(st_scom *scom)
|
|||
{
|
||||
if(scom != &scom2_rs485) return;
|
||||
|
||||
//PC -> SIG
|
||||
//来自上位机的数据是否接收完成
|
||||
if(scom->rx_flag == TRUE)
|
||||
{
|
||||
scom->rx_flag = FALSE;
|
||||
|
@ -56,7 +56,7 @@ void transparent_485(st_scom *scom)
|
|||
{
|
||||
if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xaa))
|
||||
{
|
||||
//SIG -> DEVICE
|
||||
//接收到的数据是否符合HART数据报,符合则写入HART的tx,准备发送至HART设备
|
||||
memcpy(scom1_hart.tx_buff, scom->rx_buff, sizeof(scom->rx_buff));
|
||||
scom1_hart.tx_flag = TRUE;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ void transparent_485(st_scom *scom)
|
|||
|
||||
case TRANS_BLUETOOTH:
|
||||
{
|
||||
//将接收到的数据存入BLE的tx,准备发送至蓝牙设备
|
||||
memcpy(scom6_ble.tx_buff, scom->rx_buff, sizeof(scom->rx_buff));
|
||||
scom6_ble.tx_flag = TRUE;
|
||||
}
|
||||
|
@ -82,16 +83,24 @@ void transparent_485(st_scom *scom)
|
|||
break;
|
||||
}
|
||||
|
||||
//清空缓存区,等待新的数据
|
||||
memset(scom->rx_buff, 0, sizeof(scom->rx_buff));
|
||||
scom->rx_len = 0;
|
||||
}
|
||||
|
||||
//SIG -> PC
|
||||
if(scom->tx_flag == TRUE)
|
||||
//数据是否准备完成
|
||||
if( (scom->tx_flag == TRUE) && (sig_trans != TRANS_NONE) )
|
||||
{
|
||||
scom->tx_flag = FALSE;
|
||||
|
||||
vTaskDelay(10);
|
||||
|
||||
//将数据发送至上位机
|
||||
HAL_UART_Transmit(&huart2, scom->tx_buff, scom->tx_len, 0xFFFF);
|
||||
|
||||
//清空缓存区,等待新的数据
|
||||
memset(scom->tx_buff, 0, sizeof(scom->tx_buff));
|
||||
scom->tx_len = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
void parse_scom_485(st_scom *scom);
|
||||
|
||||
//PC <---SIG---> HART/BLUETOOTH/MODBUS
|
||||
//HART:将com485_tx的数据发送至PC,将来自PC的HART数据装载至comhart_tx
|
||||
//BLE:将接收完成的BLE数据发送至上位机,将来自上位机的BLE数据装载至comhart_tx
|
||||
//HART:将接收完成的HART的数据发送至上位机,将来自上位机的HART数据装载至comhart_tx
|
||||
void transparent_485(st_scom *scom);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "string.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
|
@ -36,7 +35,7 @@
|
|||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define LVGL_BREATHE_INTERVAL 5
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
|
@ -47,6 +46,7 @@
|
|||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Variables */
|
||||
uint16_t breathe_cnt = 0;
|
||||
uint8_t screen_suspend_flag = 0;
|
||||
/* USER CODE END Variables */
|
||||
osThreadId defaultTaskHandle;
|
||||
osThreadId task_lcdHandle;
|
||||
|
@ -185,6 +185,9 @@ void start_task_lcd(void const * argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
//挂起自身
|
||||
if( screen_suspend_flag == 1 ) vTaskSuspend(task_lcdHandle);
|
||||
|
||||
lv_timer_handler(); //LVGL刷新任务
|
||||
|
||||
osDelay(LVGL_BREATHE_INTERVAL);
|
||||
|
@ -231,37 +234,23 @@ void start_task_ble(void const * argument)
|
|||
{
|
||||
/* USER CODE BEGIN start_task_ble */
|
||||
/* Infinite loop */
|
||||
int count = 0;
|
||||
char lock = 0;
|
||||
char id[9];
|
||||
strcpy (id,"00000001");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if((count++ > 5*10) &&(lock == 0))
|
||||
{
|
||||
lock = 1;
|
||||
write_ble_id(id);
|
||||
}
|
||||
|
||||
if(count < 10*10)
|
||||
{
|
||||
}
|
||||
else
|
||||
if( ble_init() == 1 )
|
||||
{
|
||||
if(ble_send_test == 1)
|
||||
{
|
||||
ble_send_test = 0;
|
||||
|
||||
|
||||
//驱动验证,DEVICE <--- BLUETOOTH ---> SIG
|
||||
strcpy((char *)(scom6_ble.tx_buff), "hellow I am ble.\r\n");
|
||||
strcpy((char *)scom6_ble.tx_buff, "hellow I am ble.\r\n");
|
||||
ble_send(&huart6, scom6_ble.tx_buff);
|
||||
}
|
||||
|
||||
//transparent_bluetooth(&scom6_ble);
|
||||
|
||||
transparent_bluetooth(&scom6_ble);
|
||||
}
|
||||
|
||||
osDelay(100);
|
||||
osDelay(BLE_TASK_PERIOD);
|
||||
}
|
||||
/* USER CODE END start_task_ble */
|
||||
}
|
||||
|
@ -339,6 +328,9 @@ void start_menu(void const * argument)
|
|||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
//挂起自身
|
||||
if( screen_suspend_flag == 1 ) vTaskSuspend(task_menuHandle);
|
||||
|
||||
screen_run();
|
||||
|
||||
osDelay(500);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "apps_gather.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
|
@ -399,18 +400,30 @@ void proc_huart_it(UART_HandleTypeDef *huart)
|
|||
|
||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET)
|
||||
{
|
||||
//接收数据时将显示任务挂起,但是vTaskSuspend无法在中断中调用
|
||||
//vTaskSuspend(task_lcdHandle);
|
||||
//vTaskSuspend(task_menuHandle);
|
||||
screen_suspend_flag = 1;
|
||||
|
||||
if (scom->rx_len >= BUFFER_SIZE - 1)
|
||||
scom->rx_len = 0;
|
||||
|
||||
scom->rx_buff[scom->rx_len++] = (uint8_t)(huart->Instance->DR & 0xff);
|
||||
|
||||
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
|
||||
|
||||
}
|
||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET)
|
||||
{
|
||||
|
||||
scom->rx_flag = TRUE;
|
||||
|
||||
__HAL_UART_CLEAR_IDLEFLAG(huart);
|
||||
|
||||
//数据接收结束,进入空闲后释放显示任务,中断中只能使用xTaskResumeFromISR
|
||||
xTaskResumeFromISR(task_lcdHandle);
|
||||
xTaskResumeFromISR(task_menuHandle);
|
||||
screen_suspend_flag = 0;
|
||||
}
|
||||
}
|
||||
/* USER CODE END 1 */
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)</Name>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1024,278,-837,553,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1785,169,-1308,484,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -158,17 +158,17 @@
|
|||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>scom1_hart,0x10</ItemText>
|
||||
<ItemText>scom1_hart,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>scom2_rs485</ItemText>
|
||||
<ItemText>scom2_rs485,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>scom6_ble</ItemText>
|
||||
<ItemText>scom6_ble,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
|
@ -228,7 +228,7 @@
|
|||
<Ww>
|
||||
<count>14</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>sig_trans</ItemText>
|
||||
<ItemText>sig_trans,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>15</count>
|
||||
|
@ -257,7 +257,7 @@
|
|||
<DebugFlag>
|
||||
<trace>0</trace>
|
||||
<periodic>1</periodic>
|
||||
<aLwin>0</aLwin>
|
||||
<aLwin>1</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,7 +26,7 @@
|
|||
*
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Portions Copyright © 2016 STMicroelectronics International N.V. All rights reserved.
|
||||
* Portions Copyright <EFBFBD> 2016 STMicroelectronics International N.V. All rights reserved.
|
||||
* Portions Copyright (c) 2013 ARM LIMITED
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
Loading…
Reference in New Issue