char3下发,char4通知
This commit is contained in:
parent
55be46451e
commit
65d60c4c23
|
@ -172,5 +172,5 @@
|
|||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
|
||||
</cproject>
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//BSP/inc/bsp_valve.h=UTF-8
|
||||
encoding//BSP/src/bsp_valve.c=UTF-8
|
||||
encoding//common/letter-shell/extensions/log/log.h=UTF-8
|
||||
encoding//common/letter-shell/shell.c=UTF-8
|
||||
encoding//common/letter-shell/shell_cfg.h=UTF-8
|
||||
encoding//common/letter-shell/shell_port.c=UTF-8
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
"devinfoservice.h": "c",
|
||||
"ch59x_uart.h": "c",
|
||||
"bsp_uart.h": "c",
|
||||
"shell_port.h": "c"
|
||||
"shell_port.h": "c",
|
||||
"atomic": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"type_traits": "cpp"
|
||||
}
|
||||
}
|
||||
|
|
131
APP/peripheral.c
131
APP/peripheral.c
|
@ -19,6 +19,18 @@
|
|||
#include "gattprofile.h"
|
||||
#include "peripheral.h"
|
||||
|
||||
#include "bsp_valve.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#undef LOG_ENABLE
|
||||
#define LOG_ENABLE 1
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BSP_VALVE"
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
@ -440,7 +452,7 @@ uint16_t Peripheral_ProcessEvent(uint8_t task_id, uint16_t events)
|
|||
if(events & SBP_PHY_UPDATE_EVT)
|
||||
{
|
||||
// start phy update
|
||||
PRINT("PHY Update %x...\n", GAPRole_UpdatePHY(peripheralConnList.connHandle, 0,
|
||||
logDebug("PHY Update %x...\n", GAPRole_UpdatePHY(peripheralConnList.connHandle, 0,
|
||||
GAP_PHY_BIT_LE_2M, GAP_PHY_BIT_LE_2M, 0));
|
||||
|
||||
return (events ^ SBP_PHY_UPDATE_EVT);
|
||||
|
@ -472,7 +484,7 @@ static void Peripheral_ProcessGAPMsg(gapRoleEvent_t *pEvent)
|
|||
{
|
||||
case GAP_SCAN_REQUEST_EVENT:
|
||||
{
|
||||
PRINT("Receive scan req from %x %x %x %x %x %x ..\n", pEvent->scanReqEvt.scannerAddr[0],
|
||||
logDebug("Receive scan req from %x %x %x %x %x %x ..\n", pEvent->scanReqEvt.scannerAddr[0],
|
||||
pEvent->scanReqEvt.scannerAddr[1], pEvent->scanReqEvt.scannerAddr[2], pEvent->scanReqEvt.scannerAddr[3],
|
||||
pEvent->scanReqEvt.scannerAddr[4], pEvent->scanReqEvt.scannerAddr[5]);
|
||||
break;
|
||||
|
@ -480,7 +492,7 @@ static void Peripheral_ProcessGAPMsg(gapRoleEvent_t *pEvent)
|
|||
|
||||
case GAP_PHY_UPDATE_EVENT:
|
||||
{
|
||||
PRINT("Phy update Rx:%x Tx:%x ..\n", pEvent->linkPhyUpdate.connRxPHYS, pEvent->linkPhyUpdate.connTxPHYS);
|
||||
logDebug("Phy update Rx:%x Tx:%x ..\n", pEvent->linkPhyUpdate.connRxPHYS, pEvent->linkPhyUpdate.connTxPHYS);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -516,7 +528,7 @@ static void Peripheral_ProcessTMOSMsg(tmos_event_hdr_t *pMsg)
|
|||
if(pMsgEvent->method == ATT_MTU_UPDATED_EVENT)
|
||||
{
|
||||
peripheralMTU = pMsgEvent->msg.exchangeMTUReq.clientRxMTU;
|
||||
PRINT("mtu exchange: %d\n", pMsgEvent->msg.exchangeMTUReq.clientRxMTU);
|
||||
logDebug("mtu exchange: %d\n", pMsgEvent->msg.exchangeMTUReq.clientRxMTU);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -543,7 +555,7 @@ static void Peripheral_LinkEstablished(gapRoleEvent_t *pEvent)
|
|||
if(peripheralConnList.connHandle != GAP_CONNHANDLE_INIT)
|
||||
{
|
||||
GAPRole_TerminateLink(pEvent->linkCmpl.connectionHandle);
|
||||
PRINT("Connection max...\n");
|
||||
logDebug("Connection max...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -561,7 +573,7 @@ static void Peripheral_LinkEstablished(gapRoleEvent_t *pEvent)
|
|||
// Start read rssi
|
||||
tmos_start_task(Peripheral_TaskID, SBP_READ_RSSI_EVT, SBP_READ_RSSI_EVT_PERIOD);
|
||||
|
||||
PRINT("Conn %x - Int %x \n", event->connectionHandle, event->connInterval);
|
||||
logDebug("Conn %x - Int %x \n", event->connectionHandle, event->connInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -595,7 +607,7 @@ static void Peripheral_LinkTerminated(gapRoleEvent_t *pEvent)
|
|||
}
|
||||
else
|
||||
{
|
||||
PRINT("ERR..\n");
|
||||
logDebug("ERR..\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -611,7 +623,7 @@ static void Peripheral_LinkTerminated(gapRoleEvent_t *pEvent)
|
|||
*/
|
||||
static void peripheralRssiCB(uint16_t connHandle, int8_t rssi)
|
||||
{
|
||||
PRINT("RSSI -%d dB Conn %x \n", -rssi, connHandle);
|
||||
logDebug("RSSI -%d dB Conn %x \n", -rssi, connHandle);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
@ -635,12 +647,12 @@ static void peripheralParamUpdateCB(uint16_t connHandle, uint16_t connInterval,
|
|||
peripheralConnList.connSlaveLatency = connSlaveLatency;
|
||||
peripheralConnList.connTimeout = connTimeout;
|
||||
|
||||
PRINT("peripheralParamUpdateCB (connHandle)%x - (connInterval) %x- (connSlaveLatency) %x - (connTimeout) %x\n"
|
||||
logDebug("peripheralParamUpdateCB (connHandle)%x - (connInterval) %x- (connSlaveLatency) %x - (connTimeout) %x\n"
|
||||
, connHandle, connInterval, connSlaveLatency, connTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT("ERR..\n");
|
||||
logDebug("ERR..\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -658,19 +670,19 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
|
|||
switch(newState & GAPROLE_STATE_ADV_MASK)
|
||||
{
|
||||
case GAPROLE_STARTED:
|
||||
PRINT("Initialized..\n");
|
||||
logDebug("Initialized..\n");
|
||||
break;
|
||||
|
||||
case GAPROLE_ADVERTISING:
|
||||
if(pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT)
|
||||
{
|
||||
Peripheral_LinkTerminated(pEvent);
|
||||
PRINT("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
|
||||
PRINT("Advertising..\n");
|
||||
logDebug("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
|
||||
logDebug("Advertising..\n");
|
||||
}
|
||||
else if(pEvent->gap.opcode == GAP_MAKE_DISCOVERABLE_DONE_EVENT)
|
||||
{
|
||||
PRINT("Advertising..\n");
|
||||
logDebug("Advertising..\n");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -678,46 +690,46 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
|
|||
if(pEvent->gap.opcode == GAP_LINK_ESTABLISHED_EVENT)
|
||||
{
|
||||
Peripheral_LinkEstablished(pEvent);
|
||||
PRINT("Connected..\n");
|
||||
logDebug("Connected..\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case GAPROLE_CONNECTED_ADV:
|
||||
if(pEvent->gap.opcode == GAP_MAKE_DISCOVERABLE_DONE_EVENT)
|
||||
{
|
||||
PRINT("Connected Advertising..\n");
|
||||
logDebug("Connected Advertising..\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case GAPROLE_WAITING:
|
||||
if(pEvent->gap.opcode == GAP_END_DISCOVERABLE_DONE_EVENT)
|
||||
{
|
||||
PRINT("Waiting for advertising..\n");
|
||||
logDebug("Waiting for advertising..\n");
|
||||
}
|
||||
else if(pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT)
|
||||
{
|
||||
Peripheral_LinkTerminated(pEvent);
|
||||
PRINT("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
|
||||
logDebug("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
|
||||
}
|
||||
else if(pEvent->gap.opcode == GAP_LINK_ESTABLISHED_EVENT)
|
||||
{
|
||||
if(pEvent->gap.hdr.status != SUCCESS)
|
||||
{
|
||||
PRINT("Waiting for advertising..\n");
|
||||
logDebug("Waiting for advertising..\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT("Error..\n");
|
||||
logDebug("Error..\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT("Error..%x\n", pEvent->gap.opcode);
|
||||
logDebug("Error..%x\n", pEvent->gap.opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case GAPROLE_ERROR:
|
||||
PRINT("Error..\n");
|
||||
logDebug("Error..\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -741,12 +753,21 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
|
|||
*/
|
||||
static void performPeriodicTask(void)
|
||||
{
|
||||
static uint8_t counter = 0;
|
||||
uint8_t notiData[SIMPLEPROFILE_CHAR4_LEN] = {0x11, 0x22, 0x33, 0x44, 0};
|
||||
notiData[4] = counter;
|
||||
// peripheralChar4Notify(notiData, SIMPLEPROFILE_CHAR4_LEN);
|
||||
peripheralChar4Notify(notiData, 5);
|
||||
counter++;
|
||||
// static uint8_t counter = 0;
|
||||
// uint8_t notiData[SIMPLEPROFILE_CHAR4_LEN] = {0x11, 0x22, 0x33, 0x44, 0};
|
||||
// notiData[4] = counter;
|
||||
// // peripheralChar4Notify(notiData, SIMPLEPROFILE_CHAR4_LEN);
|
||||
// peripheralChar4Notify(notiData, 5);
|
||||
// counter++;
|
||||
TsRawFrameData RawData;
|
||||
static uint8_t humi;
|
||||
humi = 0;
|
||||
BSP_VALVE_Generate_Data(&RawData, 30, 25, humi++);
|
||||
if (humi > 99)
|
||||
{
|
||||
humi = 0;
|
||||
}
|
||||
peripheralChar4Notify(&RawData.buf[0], RawData.len);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
@ -764,7 +785,7 @@ static void peripheralChar4Notify(uint8_t *pValue, uint16_t len)
|
|||
attHandleValueNoti_t noti;
|
||||
if(len > (peripheralMTU - 3))
|
||||
{
|
||||
PRINT("Too large noti\n");
|
||||
logDebug("Too large noti\n");
|
||||
return;
|
||||
}
|
||||
noti.len = len;
|
||||
|
@ -779,6 +800,9 @@ static void peripheralChar4Notify(uint8_t *pValue, uint16_t len)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t newValue[SIMPLEPROFILE_CHAR3_LEN];
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simpleProfileChangeCB
|
||||
*
|
||||
|
@ -792,31 +816,66 @@ static void peripheralChar4Notify(uint8_t *pValue, uint16_t len)
|
|||
*/
|
||||
static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len)
|
||||
{
|
||||
TsRawFrameData RawData;
|
||||
switch(paramID)
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
{
|
||||
uint8_t newValue[SIMPLEPROFILE_CHAR1_LEN];
|
||||
tmos_memcpy(newValue, pValue, len);
|
||||
PRINT("profile ChangeCB CHAR1.. Start\n");
|
||||
logDebug("profile ChangeCB CHAR1.. Start\n");
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
{
|
||||
PRINT("%02x ", newValue[i]);
|
||||
logDebug("%02x ", newValue[i]);
|
||||
}
|
||||
PRINT("\n profile ChangeCB CHAR1.. End\n");
|
||||
logDebug("\n profile ChangeCB CHAR1.. End\n");
|
||||
break;
|
||||
}
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
{
|
||||
uint8_t newValue[SIMPLEPROFILE_CHAR3_LEN];
|
||||
tmos_memset(newValue, 0, sizeof(newValue));
|
||||
tmos_memcpy(newValue, pValue, len);
|
||||
PRINT("profile ChangeCB CHAR3.. Start\n");
|
||||
logDebug("profile ChangeCB CHAR3.. Start");
|
||||
// logHexDumpAll(newValue, len);
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
{
|
||||
PRINT("%02x ", newValue[i]);
|
||||
logDebug("%02x ", newValue[i]);
|
||||
}
|
||||
PRINT("\n profile ChangeCB CHAR3.. End\n");
|
||||
#if 1
|
||||
TsFrameData *HostFrameData = BSP_VAVLE_GetFrameData(newValue, len);
|
||||
if (HostFrameData != NULL)
|
||||
{
|
||||
logHexDumpAll(&HostFrameData->data[0], HostFrameData->len); // 数据段
|
||||
// HR_ProcessData(HostFrameData);
|
||||
switch (HostFrameData->cmd)
|
||||
{
|
||||
case kCmdCfg:
|
||||
// uint8_t data_buf[64] = {0};
|
||||
// tmos_memset(data_buf, 0, sizeof(data_buf));
|
||||
// 处理数据帧
|
||||
logDebug("kCmdCfg");
|
||||
break;
|
||||
case kCmdCloseVavle:
|
||||
logDebug("kCmdCloseVavle");
|
||||
BSP_VALVE_Generate_ValveResponse(&RawData, kCmdCloseVavle, 1);
|
||||
peripheralChar4Notify((uint8_t*)&RawData.buf[0], RawData.len);
|
||||
break;
|
||||
case kCmdOpenVavle:
|
||||
logDebug("kCmdOpenVavle");
|
||||
BSP_VALVE_Generate_ValveResponse(&RawData, kCmdOpenVavle, 1);
|
||||
peripheralChar4Notify((uint8_t*)&RawData.buf[0], RawData.len);
|
||||
break;
|
||||
default:
|
||||
logError("无效的命令");
|
||||
// logHexDumpAll(data, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
tmos_msg_deallocate((uint8_t*)HostFrameData);
|
||||
HostFrameData = NULL;
|
||||
#endif
|
||||
logDebug("profile ChangeCB CHAR3.. End");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,58 +56,58 @@ __attribute__((noinline)) void Main_Circulation()
|
|||
{
|
||||
// 12V_EN
|
||||
BOOST_EN;
|
||||
PRINT("BOOST_EN\n");
|
||||
logDebug("BOOST_EN\n");
|
||||
|
||||
// LED_R
|
||||
LED_R_ON;
|
||||
DelayMs(1000);
|
||||
PRINT("LED_R_ON\n");
|
||||
logDebug("LED_R_ON\n");
|
||||
|
||||
LED_ALL_OFF_DEINIT;
|
||||
DelayMs(1000);
|
||||
PRINT("LED_ALL_OFF_DEINIT\n");
|
||||
logDebug("LED_ALL_OFF_DEINIT\n");
|
||||
|
||||
// BEEP
|
||||
BEEP_ON;
|
||||
DelayMs(1000);
|
||||
PRINT("BEEP_ON\n");
|
||||
logDebug("BEEP_ON\n");
|
||||
BEEP_OFF_DEINIT;
|
||||
DelayMs(1000);
|
||||
PRINT("BEEP_OFF_DEINIT\n");
|
||||
logDebug("BEEP_OFF_DEINIT\n");
|
||||
|
||||
// LED_G
|
||||
LED_G_ON;
|
||||
DelayMs(1000);
|
||||
PRINT("LED_G_ON\n");
|
||||
logDebug("LED_G_ON\n");
|
||||
|
||||
LED_ALL_OFF_DEINIT;
|
||||
DelayMs(1000);
|
||||
PRINT("LED_ALL_OFF_DEINIT\n");
|
||||
logDebug("LED_ALL_OFF_DEINIT\n");
|
||||
|
||||
// LED_Y
|
||||
LED_Y_ON;
|
||||
DelayMs(1000);
|
||||
PRINT("LED_Y_ON\n");
|
||||
logDebug("LED_Y_ON\n");
|
||||
|
||||
LED_ALL_OFF_DEINIT;
|
||||
DelayMs(1000);
|
||||
PRINT("LED_ALL_OFF_DEINIT\n");
|
||||
logDebug("LED_ALL_OFF_DEINIT\n");
|
||||
|
||||
|
||||
PRINT("Delay 6s\n");
|
||||
logDebug("Delay 6s\n");
|
||||
|
||||
// EMV_CHARGE
|
||||
EMV_CHARGE_EN;
|
||||
PRINT("EMV_CHARGE_EN\n");
|
||||
logDebug("EMV_CHARGE_EN\n");
|
||||
|
||||
DelayMs(1000);
|
||||
|
||||
EMV_CHARGE_OFF_DEINIT;
|
||||
PRINT("EMV_CHARGE_OFF_DEINIT 500 ms\n");
|
||||
logDebug("EMV_CHARGE_OFF_DEINIT 500 ms\n");
|
||||
|
||||
// EMV_CTRL
|
||||
EMV_ON;
|
||||
PRINT("EMV_ON\n");
|
||||
logDebug("EMV_ON\n");
|
||||
DelayMs(100);
|
||||
|
||||
BOOST_OFF_DEINIT;
|
||||
|
@ -145,8 +145,8 @@ int main(void)
|
|||
// UART1_DefInit();
|
||||
|
||||
// ¸Ä³É1500000²¨ÌØÂÊÁË
|
||||
BSP_UART1_Init(1500000);
|
||||
// PRINT("Start @ChipID=%02X\n", R8_CHIP_ID);
|
||||
BSP_UART1_Init(460800);
|
||||
// logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
|
||||
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
|
||||
#endif
|
||||
|
||||
|
@ -161,14 +161,8 @@ int main(void)
|
|||
BSP_KEY_Init();
|
||||
|
||||
BSP_ADC_Init();
|
||||
|
||||
PRINT("%s\n", VER_LIB);
|
||||
// while (1)
|
||||
// {
|
||||
// DelayMs(1000);
|
||||
// }
|
||||
|
||||
CH59x_BLEInit();
|
||||
logDebug("%s\n", VER_LIB);
|
||||
HAL_Init();
|
||||
GAPRole_PeripheralInit();
|
||||
Peripheral_Init();
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-12 15:54:51
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2024-12-12 16:34:01
|
||||
* @FilePath : \BLE_TYQ_CH592F\BSP\inc\bsp_flash.h
|
||||
* @Description :
|
||||
*
|
||||
* Copyright (c) 2024 by yzy, All Rights Reserved.
|
||||
*/
|
||||
#ifndef __BSP_FLASH_H__
|
||||
#define __BSP_FLASH_H__
|
||||
|
||||
#include "CONFIG.h"
|
||||
|
||||
/*CH584具有data_flash和code flash两部分。 codeflash为448k dataflash为32k
|
||||
CodeFlash读操作是有硬件加扰的,也就是擦除后读不是全FF,而是四个固定字节的循环,DataFlash读操作没有硬件加扰
|
||||
CodeFlash和DataFlash都可以直接指针读数据(指针读经过硬件加扰)。
|
||||
0x00000000-0x0006FFFF 用户应用程序存储区 CodeFlash 448KB
|
||||
0x00070000-0x00077FFF 用户非易失数据存储区 DataFlash 32KB
|
||||
0x00078000-0x0007DFFF 系统引导程序存储区 BootLoader 24KB
|
||||
0x0007E000-0x0007FFFF 系统非易失配置信息存储区 InfoFlash 8KB
|
||||
*/
|
||||
|
||||
/*BLE蓝牙falsh写入注意地址是相对于dataflash的,而dataflash的起始地址是0x3FFF,所以传入的参数是0x3FFF+offset
|
||||
并且不要覆盖原有的参数
|
||||
https://www.cnblogs.com/JayWellsBlog/p/18223898
|
||||
|
||||
接口中的读/写buff缓存在ram中的地址,一定要4字节对齐,否则可能导致hardfault复位
|
||||
问题排查
|
||||
https://www.cnblogs.com/iot-fan/p/16053937.html
|
||||
*/
|
||||
|
||||
#define DATA_FALASH_START_ADDR (0X3FFF) // 传入的是相对地址,用对函数即可
|
||||
#define DATA_FLASH_PAGE_SIZE (256U)
|
||||
|
||||
#define FLASH_INFO_ADDR (DATA_FALASH_START_ADDR)
|
||||
#define FLASH_INFO_WRITE_FLAG_ADDR (DATA_FALASH_START_ADDR)
|
||||
|
||||
#define FLASH_INFO_WRITE_FLAG_VAL (0XAABBCCDD)
|
||||
#define FLASH_INFO_WRITE_FLAG_LEN (4U)
|
||||
|
||||
void BSP_FLASH_Init(void);
|
||||
|
||||
#endif // !__BSP_FLASH_H__
|
|
@ -5,7 +5,7 @@
|
|||
#include "CONFIG.h"
|
||||
|
||||
#define UART1_RX_BUFFER_LENGTH 64U
|
||||
#define UART1_TX_BUFFER_LENGTH 128U
|
||||
#define UART1_TX_BUFFER_LENGTH 1024U
|
||||
|
||||
void BSP_UART1_Init(uint32_t baudrate);
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-12 15:55:38
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2024-12-12 19:08:06
|
||||
* @FilePath : \BLE_TYQ_CH592F\BSP\inc\bsp_valve.h
|
||||
* @Description :
|
||||
*
|
||||
* Copyright (c) 2024 by yzy, All Rights Reserved.
|
||||
*/
|
||||
#ifndef __BSP_VALVE_H__
|
||||
#define __BSP_VALVE_H__
|
||||
|
||||
#include "CONFIG.h"
|
||||
|
||||
#define FRAME_HEADER 0xAA
|
||||
#define FRAME_TAIL 0x55
|
||||
|
||||
// 0xAA CMD/DATA/ DATA_LEN (DATA) checksum 0x55
|
||||
|
||||
typedef enum
|
||||
{
|
||||
kCmdCfg = 0X01,
|
||||
kCmdCloseVavle,
|
||||
kCmdOpenVavle,
|
||||
kCmdData,
|
||||
} TeFrameCmd;
|
||||
|
||||
// typedef enum
|
||||
// {
|
||||
|
||||
// } TeCmdIndex;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
TeFrameCmd cmd; // CMD/DATA
|
||||
uint8_t len; // DATA_LEN
|
||||
// TsValveData data;
|
||||
uint8_t data[];
|
||||
} TsFrameData;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint8_t len;
|
||||
uint8_t buf[128];
|
||||
} TsRawFrameData;
|
||||
|
||||
// 阀门类型
|
||||
typedef enum
|
||||
{
|
||||
kTyq = 0X01,
|
||||
kZbf,
|
||||
kDcf,
|
||||
} TeVavleType;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint8_t type; // 阀门类型
|
||||
|
||||
uint8_t bat; // 1B 电池电压 30=3V,18=1.8V
|
||||
int8_t temp; // 1B 阀门温度 有符号整数 25 ℃
|
||||
uint8_t hum; // 1B 阀门湿度 %RH
|
||||
|
||||
// uint8_t status; // 1B 阀门工作状态 超欠压、过流
|
||||
// uint8_t connct_status; // 1B 阀门连接状态 (电磁阀BLE控制盒) 0=未连接 1=已连接
|
||||
// uint8_t switch_status; // 1B 阀门开关状态 0=未知 1=关闭 2=关闭过,未按按键恢复 3=关闭过,按下了恢复键 4=打开
|
||||
|
||||
// uint32_t in_pressure; // 4B 阀门入口压力 Pa
|
||||
// uint32_t out_pressure; // 4B 阀门出口压力 Pa
|
||||
// uint32_t atm_pressure; // 4B 阀门大气压力 Pa
|
||||
} TsValveData;
|
||||
|
||||
uint8_t CheckSum(const uint8_t *data, size_t len);
|
||||
|
||||
void BSP_VAVLE_Init(void);
|
||||
|
||||
TsFrameData* BSP_VAVLE_GetFrameData(uint8_t *data, uint16_t len);
|
||||
|
||||
void BSP_VALVE_Generate_Data(TsRawFrameData *pRawData, uint8_t bat, int8_t temp, uint8_t hum);
|
||||
void BSP_VALVE_Generate_ValveResponse(TsRawFrameData *pRawData, TeFrameCmd cmd, uint8_t status);
|
||||
|
||||
#endif // ! __BSP_VALVE_H__
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-12 15:54:57
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2024-12-12 16:47:22
|
||||
* @FilePath : \BLE_TYQ_CH592F\BSP\src\bsp_flash.c
|
||||
* @Description :
|
||||
*
|
||||
* Copyright (c) 2024 by yzy, All Rights Reserved.
|
||||
*/
|
||||
#include "bsp_flash.h"
|
||||
#include "CONFIG.h"
|
||||
#include "string.h"
|
||||
#include "bsp_valve.h"
|
||||
|
||||
#undef LOG_ENABLE
|
||||
#define LOG_ENABLE 1
|
||||
|
||||
#include "log.h"
|
||||
|
||||
|
||||
void Flash_ErasePage_ReadCfgInfo(uint8_t *page_buf)
|
||||
{
|
||||
EEPROM_READ(FLASH_INFO_ADDR, page_buf, DATA_FLASH_PAGE_SIZE);
|
||||
EEPROM_ERASE(FLASH_INFO_ADDR, DATA_FLASH_PAGE_SIZE);
|
||||
}
|
||||
|
||||
int Flash_Write_CfgInfo(uint8_t *page_buf)
|
||||
{
|
||||
EEPROM_WRITE(FLASH_INFO_ADDR, page_buf, DATA_FLASH_PAGE_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BSP_FLASH_Init(void)
|
||||
{
|
||||
uint32_t flash_write_flag = 0;
|
||||
EEPROM_READ(FLASH_INFO_WRITE_FLAG_ADDR, &flash_write_flag, FLASH_INFO_WRITE_FLAG_LEN);
|
||||
// 判断是否需要初始化
|
||||
if (flash_write_flag != FLASH_INFO_WRITE_FLAG_VAL) // 用以防止刷掉写入的数据
|
||||
{
|
||||
flash_write_flag = FLASH_INFO_WRITE_FLAG_VAL;
|
||||
// 擦除数据
|
||||
EEPROM_ERASE(FLASH_INFO_ADDR, DATA_FLASH_PAGE_SIZE); // 擦除待写区
|
||||
EEPROM_WRITE(FLASH_INFO_WRITE_FLAG_ADDR, &flash_write_flag, FLASH_INFO_WRITE_FLAG_LEN);
|
||||
|
||||
logWarning("First Init flash_write_flag:%d", flash_write_flag);
|
||||
}
|
||||
logDebug("BSP_FLASH_Init");
|
||||
}
|
|
@ -67,7 +67,7 @@ void BSP_UART1_Init(uint32_t baudrate)
|
|||
|
||||
/* 配置串口1:先配置IO口模式,再配置串口 */
|
||||
GPIOA_SetBits(bTXD1);
|
||||
GPIOB_ModeCfg(bRXD1, GPIO_ModeIN_PU); // RXD-配置上拉输入
|
||||
// GPIOB_ModeCfg(bRXD1, GPIO_ModeIN_PU); // RXD-配置上拉输入
|
||||
GPIOA_ModeCfg(bTXD1, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
|
||||
// UART1_DefInit();
|
||||
{
|
||||
|
@ -77,10 +77,11 @@ void BSP_UART1_Init(uint32_t baudrate)
|
|||
R8_UART1_IER = RB_IER_TXD_EN;
|
||||
R8_UART1_DIV = 1;
|
||||
}
|
||||
UART1_ByteTrigCfg(UART_1BYTE_TRIG);
|
||||
// UART1_ByteTrigCfg(UART_1BYTE_TRIG);
|
||||
// 中断方式接收数据
|
||||
UART1_INTCfg(ENABLE, RB_IER_LINE_STAT | RB_IER_RECV_RDY);
|
||||
PFIC_EnableIRQ(UART1_IRQn);
|
||||
// UART1_INTCfg(ENABLE, RB_IER_LINE_STAT | RB_IER_RECV_RDY);
|
||||
// UART1_INTCfg(ENABLE, RB_IER_LINE_STAT | RB_IER_RECV_RDY);
|
||||
// PFIC_EnableIRQ(UART1_IRQn);
|
||||
|
||||
UART1_FifoInit();
|
||||
|
||||
|
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* @Author: mbw
|
||||
* @Date: 2024-12-09 11:40:10
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2024-12-11 15:43:47
|
||||
* @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\src\bsp_valve.c
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
*/
|
||||
#include "bsp_valve.h"
|
||||
#include "bsp_flash.h"
|
||||
#include "bsp_uart.h"
|
||||
|
||||
#include "bsp_beep_led_emv.h"
|
||||
// 0xAA CMD/DATA/ DATA_LEN (DATA) checksum 0x55
|
||||
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#undef LOG_ENABLE
|
||||
#define LOG_ENABLE 0
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BSP_VALVE"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description: 从帧起始符开始到校验码之前所有字节的和的模256,即各字节不计超过255的溢出值的二进制算术和。
|
||||
* @param {uint8_t} *data
|
||||
* @param {uint16_t} len
|
||||
* @return {*}
|
||||
*/
|
||||
uint8_t CheckSum(const uint8_t *data, size_t len)
|
||||
{
|
||||
uint8_t sum = 0;
|
||||
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
sum += data[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @description: 从接收缓冲区中获取一帧有效数据
|
||||
* @param {TsFrameData} *pFrameData 主机帧
|
||||
* @param {uint8_t} *p_src 接收缓冲区
|
||||
* @param {uint16_t} src_len 接收缓冲区长度
|
||||
* @return {*}
|
||||
*/
|
||||
TsFrameData *HR_GetFrameData(const uint8_t *p_src, const uint8_t src_len)
|
||||
{
|
||||
uint8_t data_field_len = 0;
|
||||
uint8_t check_sum = 0;
|
||||
|
||||
TsFrameData *get_buffer = NULL;
|
||||
|
||||
for (uint8_t i = 0; i < src_len; i++)
|
||||
{
|
||||
// 找帧头
|
||||
if (p_src[i] == FRAME_HEADER)
|
||||
{
|
||||
// 找数据长度
|
||||
data_field_len = p_src[i + 2];
|
||||
// 找帧尾
|
||||
if (p_src[i + 2 + data_field_len + 2] == FRAME_TAIL)
|
||||
{
|
||||
check_sum = CheckSum(&p_src[i], (3 + data_field_len));
|
||||
|
||||
if (p_src[i + 2 + data_field_len + 1] == check_sum)
|
||||
{
|
||||
get_buffer = (TsFrameData *)tmos_msg_allocate(sizeof(TsFrameData) + sizeof(uint8_t) * data_field_len);
|
||||
if (get_buffer == NULL)
|
||||
{
|
||||
logError("tmos_msg_allocate fail");
|
||||
return NULL;
|
||||
}
|
||||
get_buffer->cmd = p_src[i + 1];
|
||||
get_buffer->len = data_field_len;
|
||||
|
||||
if (data_field_len > 0)
|
||||
{
|
||||
tmos_memcmp(get_buffer->data, &p_src[i + 4], data_field_len);
|
||||
}
|
||||
logDebug("HR_GetDataFrame Success!");
|
||||
|
||||
return get_buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logError("HR_GetDataFrame Fail!");
|
||||
|
||||
return get_buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
TsFrameData* BSP_VAVLE_GetFrameData(uint8_t *data, uint16_t len)
|
||||
{
|
||||
int ret = 0;
|
||||
uint16_t index = 0;
|
||||
|
||||
TsFrameData *get_buffer = NULL;
|
||||
// 解析接收到的数据帧,先寻找AA开头,然后再找AA下一个字节,其代表了数据长度,然后找到代表长度的值的长度的下一位,其为校验码,校验码后为结束码0x55,
|
||||
// 如果数据正确,则提取数据,不正确,则不处理
|
||||
if (len < 4)
|
||||
{ // 至少需要 4 个字节:起始码、长度、校验码、结束码
|
||||
logError("数据帧长度不足");
|
||||
logHexDumpAll(data, len);
|
||||
// return 1;
|
||||
}
|
||||
while (index < len && data[index] != FRAME_HEADER) // 寻找起始码 0xAA
|
||||
{
|
||||
index++;
|
||||
}
|
||||
if (index >= len - 3) // 不够空间容纳长度、校验码和结束码
|
||||
{
|
||||
logError("数据帧起始码错误");
|
||||
logHexDumpAll(data, len);
|
||||
// return 2;
|
||||
}
|
||||
uint16_t data_len = data[index + 2]; // 读取数据长度
|
||||
if (index + 3 + data_len + 1 >= len) // 检查数据长度是否合理 数据长度 + 校验码 + 结束码
|
||||
{
|
||||
logError("数据帧长度错误");
|
||||
logHexDumpAll(data, len);
|
||||
// return 3;
|
||||
}
|
||||
|
||||
uint8_t check_sum = data[index + 3 + data_len]; // 读取校验码
|
||||
uint8_t calculated_sum = CheckSum(&data[index], data_len + 3); // 计算校验码
|
||||
if (check_sum != calculated_sum)
|
||||
{
|
||||
logError("数据帧校验码错误 check_sum = %02X, calculated_sum = %02X", check_sum, calculated_sum);
|
||||
logHexDumpAll(data, len);
|
||||
// return 4;
|
||||
}
|
||||
if (data[index + 3 + data_len + 1] != FRAME_TAIL) // 检查结束码
|
||||
{
|
||||
logError("数据帧结束码错误");
|
||||
logHexDumpAll(data, len);
|
||||
// return 5;
|
||||
}
|
||||
logDebug("数据帧校验通过");
|
||||
|
||||
get_buffer = (TsFrameData *)tmos_msg_allocate(sizeof(TsFrameData) + sizeof(uint8_t) * data_len);
|
||||
if (get_buffer == NULL)
|
||||
{
|
||||
logError("tmos_msg_allocate fail");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
get_buffer->cmd = data[index + 1];
|
||||
get_buffer->len = data_len;
|
||||
// get_buffer->data = data;
|
||||
|
||||
if (data_len > 0)
|
||||
{
|
||||
tmos_memcpy(get_buffer->data, &data[index + 3], data_len);
|
||||
return get_buffer;
|
||||
}
|
||||
|
||||
// //有效数据长度
|
||||
// size_t data_len = (data_len + 5);
|
||||
// //到这一步说明数据没问题,将接收到的数据通过中心任务发送出去
|
||||
// uint8_t *p_data;
|
||||
// p_data = tmos_msg_allocate(data_len);
|
||||
// if (p_data)
|
||||
// {
|
||||
// tmos_memcpy(p_data, data, data_len);
|
||||
// tmos_msg_send(BtRxTaskId, p_data);
|
||||
// tmos_start_task(BtRxTaskId, SYS_EVENT_MSG, 0);
|
||||
// }
|
||||
}
|
||||
|
||||
uint8_t _GenerateRawFrame(TsRawFrameData *pRawData, uint8_t cmd, const uint8_t *p_src, uint8_t src_len)
|
||||
{
|
||||
// 0xAA CMD/DATA/ DATA_LEN (DATA) checksum 0x55
|
||||
pRawData->len = src_len + 5;
|
||||
|
||||
tmos_memset(pRawData->buf, 0, sizeof(pRawData->buf));
|
||||
|
||||
pRawData->buf[0] = FRAME_HEADER;
|
||||
pRawData->buf[1] = cmd;
|
||||
pRawData->buf[2] = src_len;
|
||||
|
||||
tmos_memcpy(&pRawData->buf[3], p_src, src_len);
|
||||
|
||||
// 从帧起始符开始到校验码之前所有字节的和的模256
|
||||
// ,即各字节不计超过255的溢出值的二进制算术和。
|
||||
pRawData->buf[pRawData->len - 2] = CheckSum(&pRawData->buf[0], pRawData->len - 2);
|
||||
pRawData->buf[pRawData->len - 1] = FRAME_TAIL;
|
||||
|
||||
logHexDumpAll(&pRawData->buf[0], pRawData->len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BSP_VALVE_Generate_Data(TsRawFrameData *pRawData, uint8_t bat, int8_t temp, uint8_t hum)
|
||||
{
|
||||
TsValveData ValveData;
|
||||
|
||||
ValveData.type = kTyq; // 阀门类型
|
||||
ValveData.bat = bat; // 电池电压 30=3V,18=1.8V
|
||||
ValveData.temp = temp; // 阀门温度 有符号整数 25 ℃
|
||||
ValveData.hum = hum; // 阀门湿度 %RH
|
||||
|
||||
_GenerateRawFrame(pRawData, kCmdData, (uint8_t*)&ValveData, sizeof(ValveData));
|
||||
logHexDumpAll(&pRawData->buf[0], pRawData->len);
|
||||
}
|
||||
|
||||
void BSP_VALVE_Generate_ValveResponse(TsRawFrameData *pRawData, TeFrameCmd cmd, uint8_t status)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
data = status;
|
||||
_GenerateRawFrame(pRawData, cmd, &data, 1);
|
||||
logHexDumpAll(&pRawData->buf[0], pRawData->len);
|
||||
}
|
||||
|
||||
void BSP_CloseValve(void)
|
||||
{
|
||||
// EMV_CHARGE
|
||||
EMV_CHARGE_EN;
|
||||
logDebug("EMV_CHARGE_EN");
|
||||
|
||||
DelayMs(1000);
|
||||
|
||||
EMV_CHARGE_OFF_DEINIT;
|
||||
logDebug("EMV_CHARGE_OFF_DEINIT 500 ms");
|
||||
|
||||
// EMV_CTRL
|
||||
EMV_ON;
|
||||
logDebug("EMV_ON\n");
|
||||
DelayMs(100);
|
||||
}
|
||||
|
||||
void BSP_VAVLE_Init(void)
|
||||
{
|
||||
|
||||
logInfo("BSP_Valve_Init");
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
* @brief log
|
||||
* @version 1.0.0
|
||||
* @date 2020-07-30
|
||||
*
|
||||
*
|
||||
* @copyright (c) 2020 Letter
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef __LOG_H__
|
||||
#define __LOG_H__
|
||||
|
@ -90,7 +90,7 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* @brief 日志级别定义
|
||||
*
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ typedef enum
|
|||
LOG_ERROR = 1, /**< 错误 */
|
||||
LOG_WRANING = 2, /**< 警告 */
|
||||
LOG_INFO = 3, /**< 消息 */
|
||||
LOG_DEBUG = 4, /**< 调试 */
|
||||
logDebugEBUG = 4, /**< 调试 */
|
||||
LOG_VERBOSE = 5, /**< 冗余 */
|
||||
LOG_ALL = 6, /**< 所有日志 */
|
||||
} LogLevel;
|
||||
|
@ -106,14 +106,14 @@ typedef enum
|
|||
|
||||
/**
|
||||
* @brief log对象定义
|
||||
*
|
||||
*
|
||||
*/
|
||||
typedef struct log_def
|
||||
{
|
||||
void (*write)(char *, short); /**< 写buffer */
|
||||
char active; /**< 是否激活 */
|
||||
LogLevel level; /**< 日志级别 */
|
||||
#if LOG_USING_LOCK == 1
|
||||
#if LOG_USING_LOCK == 1
|
||||
int (*lock)(struct log_def *); /**< log 加锁 */
|
||||
int (*unlock)(struct log_def *); /**< log 解锁 */
|
||||
#endif /** LOG_USING_LOCK == 1 */
|
||||
|
@ -124,7 +124,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief log打印(自动换行)
|
||||
*
|
||||
*
|
||||
* @param fmt 格式
|
||||
* @param ... 参数
|
||||
*/
|
||||
|
@ -134,7 +134,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 日志格式化输出
|
||||
*
|
||||
*
|
||||
* @param text 消息文本
|
||||
* @param level 日志级别
|
||||
* @param fmt 格式
|
||||
|
@ -147,7 +147,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 错误log输出
|
||||
*
|
||||
*
|
||||
* @param fmt 格式
|
||||
* @param ... 参数
|
||||
*/
|
||||
|
@ -156,7 +156,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 警告log输出
|
||||
*
|
||||
*
|
||||
* @param fmt 格式
|
||||
* @param ... 参数
|
||||
*/
|
||||
|
@ -165,7 +165,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 信息log输出
|
||||
*
|
||||
*
|
||||
* @param fmt 格式
|
||||
* @param ... 参数
|
||||
*/
|
||||
|
@ -174,16 +174,16 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 调试log输出
|
||||
*
|
||||
*
|
||||
* @param fmt 格式
|
||||
* @param ... 参数
|
||||
*/
|
||||
#define logDebug(fmt, ...) \
|
||||
logFormat(DEBUG_TEXT, LOG_DEBUG, fmt, ##__VA_ARGS__)
|
||||
logFormat(DEBUG_TEXT, logDebugEBUG, fmt, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief 冗余log输出
|
||||
*
|
||||
*
|
||||
* @param fmt 格式
|
||||
* @param ... 参数
|
||||
*/
|
||||
|
@ -192,7 +192,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 断言
|
||||
*
|
||||
*
|
||||
* @param expr 表达式
|
||||
* @param action 断言失败操作
|
||||
*/
|
||||
|
@ -204,7 +204,7 @@ typedef struct log_def
|
|||
|
||||
/**
|
||||
* @brief 16进制输出到所有终端
|
||||
*
|
||||
*
|
||||
* @param base 内存基址
|
||||
* @param length 长度
|
||||
*/
|
||||
|
|
|
@ -51,7 +51,7 @@ log是一个用于嵌入式系统的日志打印工具,可以为日志定义
|
|||
Log uartLog = {
|
||||
.write = uartLogWrite,
|
||||
.active = true,
|
||||
.level = LOG_DEBUG
|
||||
.level = logDebugEBUG
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -191,7 +191,7 @@ log工具可以结合letter shell的尾行模式,实现log和shell共用一个
|
|||
Log uartLog = {
|
||||
.write = uartLogWrite,
|
||||
.active = true,
|
||||
.level = LOG_DEBUG
|
||||
.level = logDebugEBUG
|
||||
};
|
||||
```
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "shell.h"
|
||||
|
||||
#define SHELL_BUF_LENGTH 128
|
||||
#define SHELL_BUF_LENGTH 1024
|
||||
|
||||
extern Shell shell;
|
||||
|
||||
|
|
Loading…
Reference in New Issue