forked from gary/BCU
2
0
Fork 0

高压堆叠融合wifi功能,成功,第一版

This commit is contained in:
Carl 2025-05-13 16:37:29 +08:00
parent 5dd97a6761
commit 2635b93a5a
19 changed files with 9515 additions and 7597 deletions

View File

@ -180,7 +180,19 @@ FaultLevel bms_get_min_fault_level(void)
return level1; return level1;
} }
uint32_t bms_get_total_alarm(uint16_t input)
{
FaultLevel level;
level = bms_get_max_fault_level() == kFaultLevel_First || bms_get_max_fault_level() == kFaultLevel_Second;
return level;
}
uint32_t bms_get_total_fault(uint16_t input)
{
FaultLevel level;
level = bms_get_max_fault_level() == kFaultLevel_Third;
return level;
}
uint8_t bms_get_fault_cur_rate(RunStatus status) uint8_t bms_get_fault_cur_rate(RunStatus status)
{ {

View File

@ -253,6 +253,10 @@ void bms_analyse_pwr_on_fault(RunStatus status, FaultArray *fault_array, uint32_
void bms_clear_fault_relay_off_bit(FaultCode idx); void bms_clear_fault_relay_off_bit(FaultCode idx);
void bms_clear_fault_relay_off_bit_by_status(RunStatus status, FaultCode idx); void bms_clear_fault_relay_off_bit_by_status(RunStatus status, FaultCode idx);
//总故障,总告警
uint32_t bms_get_total_alarm(uint16_t input);
uint32_t bms_get_total_fault(uint16_t input);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -5,6 +5,7 @@
* @copyright * @copyright
******************************************************************************/ ******************************************************************************/
#include "gpio_manager.h" #include "gpio_manager.h"
#include "stm32f4xx.h"
const GpioArray io_array[kGpioType_End] = const GpioArray io_array[kGpioType_End] =
{ {
@ -50,6 +51,9 @@ const GpioArray io_array[kGpioType_End] =
kGpioMode_Comm_Rx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 1), kGpioPort_A, kGpioPin_1 , //rs485A Rx(mcu uart1) kGpioMode_Comm_Rx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 1), kGpioPort_A, kGpioPin_1 , //rs485A Rx(mcu uart1)
kGpioMode_Comm_Tx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 0), kGpioPort_A, kGpioPin_0 , //rs485A Tx(mcu uart1) kGpioMode_Comm_Tx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 0), kGpioPort_A, kGpioPin_0 , //rs485A Tx(mcu uart1)
kGpioMode_Comm_Rx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 3), kGpioPort_A, kGpioPin_3, //Sim卡/wifi/ble Rx(mcu uart2)
kGpioMode_Comm_Tx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 2), kGpioPort_A, kGpioPin_2, //Sim卡/wifi/ble Tx(mcu uart2)
/*CAN枚举*/ /*CAN枚举*/
kGpioMode_Comm_Rx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 11), kGpioPort_A, kGpioPin_11 , //can1 rx kGpioMode_Comm_Rx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 11), kGpioPort_A, kGpioPin_11 , //can1 rx
kGpioMode_Comm_Tx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 12), kGpioPort_A, kGpioPin_12 , //can1 tx kGpioMode_Comm_Tx, kGpioStatus_Low, GPIO_PORT_PIN(kGpioPort_A, 12), kGpioPort_A, kGpioPin_12 , //can1 tx
@ -89,6 +93,34 @@ const GpioArray io_array[kGpioType_End] =
kGpioMode_Input_Floating, kGpioStatus_High, GPIO_PORT_PIN(kGpioPort_G, 15), kGpioPort_G, kGpioPin_15 , //W5500_INT kGpioMode_Input_Floating, kGpioStatus_High, GPIO_PORT_PIN(kGpioPort_G, 15), kGpioPort_G, kGpioPin_15 , //W5500_INT
}; };
//void drv_wireless_dma_init(void)
//{
// // 使能 DMA1 和 USART2 的时钟
// RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;
// RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
// // 配置 USART2 基本参数
// USART2->CR1 &= ~USART_CR1_UE; // 先禁用USART
// USART2->BRR = SystemCoreClock / 115200; // 设置波特率
// USART2->CR1 = USART_CR1_TE | USART_CR1_UE;
// // 配置 DMA1 Stream6 通道4 对应 USART2_TX
// DMA1_Stream6->CR &= ~DMA_SxCR_EN;
// while (DMA1_Stream6->CR & DMA_SxCR_EN); // 等待 DMA 关闭
// DMA1_Stream6->PAR = (uint32_t)&USART2->DR;
// DMA1_Stream6->M0AR = (uint32_t)dma_tx_buffer;
// DMA1_Stream6->NDTR = 0;
// DMA1_Stream6->CR = (4 << 25) | // 通道4
// DMA_SxCR_MINC | // 内存递增
// DMA_SxCR_DIR_0 | // 内存到外设
// DMA_SxCR_TCIE | // 传输完成中断
// DMA_SxCR_TEIE | // 建议添加传输错误中断
// (0 << 16); // 优先级
// NVIC_EnableIRQ(DMA1_Stream6_IRQn);
//}
void bms_init_gpio(void) void bms_init_gpio(void)
{ {
drv_gpio_init(io_array, kGpioType_End); drv_gpio_init(io_array, kGpioType_End);

View File

@ -57,6 +57,9 @@ typedef enum
kGpioType_Rs485_Ch3_Rx, kGpioType_Rs485_Ch3_Rx,
kGpioType_Rs485_Ch3_Tx, kGpioType_Rs485_Ch3_Tx,
kGpioType_WIRELESSUart_Rx, //Sim卡/wifi/ble
kGpioType_WIRELESSUart_Tx, //Sim卡/wifi/ble
/*CAN枚举*/ /*CAN枚举*/
kGpioType_Can_Ch1_Rx, kGpioType_Can_Ch1_Rx,
kGpioType_Can_Ch1_Tx, kGpioType_Can_Ch1_Tx,

View File

@ -17,6 +17,7 @@ const uint8_t tcp_server_task_name[W5500_MODBUS_NUM][14] =
void poll_1ms_task_init(void); void poll_1ms_task_init(void);
void poll_10ms_task_init(void); void poll_10ms_task_init(void);
void poll_mqtt_init(void);
bool is_first_run = false; bool is_first_run = false;
@ -49,9 +50,15 @@ void task_10ms_handler(uint32_t base_time)
#endif #endif
} }
void task_mqtt_handler(uint32_t base_time)
{
mqtt_publish_bms_data(base_time);
}
void bms_poll_bmu_handler(uint32_t base_time) void bms_poll_bmu_handler(uint32_t base_time)
{ {
bms_poll_bmu(base_time); bms_poll_bmu(base_time);
task_mqtt_handler(base_time);
} }
void task_100ms_handler(uint32_t base_time) void task_100ms_handler(uint32_t base_time)
@ -60,11 +67,12 @@ void task_100ms_handler(uint32_t base_time)
cout100ms++; cout100ms++;
bms_poll_iso(base_time); bms_poll_iso(base_time);
// bms_poll_adc(); THis was originally commented. // bms_poll_adc(); THis was originally commented.
bms_poll_adc(base_time); // bms_poll_adc(base_time);
bms_poll_statistic(base_time); bms_poll_statistic(base_time);
bms_poll_run_status(base_time); bms_poll_run_status(base_time);
bms_poll_sop(base_time); bms_poll_sop(base_time);
bms_poll_soh(base_time); bms_poll_soh(base_time);
// task_mqtt_handler(base_time);
is_first_run = true; is_first_run = true;
} }
@ -82,6 +90,8 @@ GLOBAL_TASK_VARS_CCM(modbus_rtu_task3, 8, 50, 5000, 400, NULL,
GLOBAL_TASK_VARS_CCM(ord_comm_can_task, 5, 100, 5000, 400, NULL, task_can1_handler, NULL); GLOBAL_TASK_VARS_CCM(ord_comm_can_task, 5, 100, 5000, 400, NULL, task_can1_handler, NULL);
GLOBAL_TASK_VARS_CCM(bms_poll_bmu_task, 9, 100, 5000, 400, bms_bmu_init, bms_poll_bmu_handler, NULL); GLOBAL_TASK_VARS_CCM(bms_poll_bmu_task, 9, 100, 5000, 400, bms_bmu_init, bms_poll_bmu_handler, NULL);
GLOBAL_TASK_VARS_CCM(bms_poll_mqtt_task, 9, 1000, 5000, 400, poll_mqtt_init, task_mqtt_handler, NULL);
#define BMU_FINISH_BIT (0u) #define BMU_FINISH_BIT (0u)
#define SIGNAL_FINISH_BIT (1u) #define SIGNAL_FINISH_BIT (1u)
@ -135,7 +145,7 @@ void poll_1ms_task_init(void)
KIT_SET_BIT_MASK_32(is_data_ok, SIGNAL_FINISH_BIT); KIT_SET_BIT_MASK_32(is_data_ok, SIGNAL_FINISH_BIT);
bsp_create_task(&ord_ctrl_task, (uint8_t *)"ctrl"); bsp_create_task(&ord_ctrl_task, (uint8_t *)"ctrl");
poll_mqtt_init();
} }
void poll_10ms_task_init(void) void poll_10ms_task_init(void)
@ -188,6 +198,25 @@ void poll_10ms_task_init(void)
*/ */
} }
void poll_mqtt_init(void)
{
static uint16_t qfc41d_init_count = 0;
while (drv_qfc41d_init() && qfc41d_init_count < 10)
{
drv_wdog_feed();
kit_time_dly_ms(100);
qfc41d_init_count++;
}
// // MQTT ?????
// while (drv_mqtt_init() && mqtt_init_count < 10)
// {
// drv_wdog_feed();
// kit_time_dly_ms(100);
// mqtt_init_count++;
// }
}
/***************************************************************************** /*****************************************************************************
* @brief ucosϵͳÖÐϻص÷ * @brief ucosϵͳÖÐϻص÷

View File

@ -10,15 +10,15 @@
<TargetName>stm32f407</TargetName> <TargetName>stm32f407</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pArmCC>5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7</pArmCC> <pArmCC>5050106::V5.05 update 1 (build 106)::ARMCC</pArmCC>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7</pCCUsed> <pCCUsed>5050106::V5.05 update 1 (build 106)::ARMCC</pCCUsed>
<uAC6>0</uAC6> <uAC6>0</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F407ZGTx</Device> <Device>STM32F407ZGTx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F4xx_DFP.3.0.0</PackID> <PackID>Keil.STM32F4xx_DFP.2.16.0</PackID>
<PackURL>https://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00020000) IRAM2(0x10000000,0x00010000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x00020000) IRAM2(0x10000000,0x00010000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile> <StartupFile></StartupFile>
@ -341,7 +341,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>STM32F40_41xxx,APP_START_ADDR = 0x08020000,UCOS2,BSE1B,ADS_8688_EN</Define> <Define>STM32F40_41xxx,APP_START_ADDR = 0x08020000,UCOS2,BSE1B,ADS_8688_EN</Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>..\app;..\..\..\library\bsp;..\..\..\library\core;..\..\..\library\kit;..\..\..\library\drv_peripheral;..\ord;..\..\..\library\drv_stm32f4xx;..\..\..\library\J1939;..\protocol;..\..\..\library\ucos\uC-OS2\Source;..\..\..\library\ucos\uC-OS2\Ports\ARM-Cortex-M\ARMv7-M\ARM;..\..\..\library\ucos\uC-OS2\Cfg\Template;..\..\..\library\ucos\uC-CPU\ARM-Cortex-M\ARMv7-M\ARM;..\..\..\library\ucos\uC-CPU\Cfg\Template;..\..\..\library\ucos\uC-CPU\Template;..\..\..\library\ucos\uC-CPU;..\..\..\library\ucos\uC-LIB;..\..\..\library\ucos\uC-LIB\Cfg\Template;..\..\..\library\ucos\uC-LIB\Ports\ARM-Cortex-M4\RealView;..\..\..\library\ucos;..\..\..\library\segger\Config;..\..\..\library\segger\Sample\uCOS-II;..\..\..\library\segger\Sample\uCOS-II\Config;..\..\..\library\segger\SEGGER;..\table</IncludePath> <IncludePath>..\app;..\..\..\library\bsp;..\..\..\library\core;..\..\..\library\kit;..\..\..\library\drv_peripheral;..\ord;..\..\..\library\drv_stm32f4xx;..\..\..\library\J1939;..\protocol;..\..\..\library\ucos\uC-OS2\Source;..\..\..\library\ucos\uC-OS2\Ports\ARM-Cortex-M\ARMv7-M\ARM;..\..\..\library\ucos\uC-OS2\Cfg\Template;..\..\..\library\ucos\uC-CPU\ARM-Cortex-M\ARMv7-M\ARM;..\..\..\library\ucos\uC-CPU\Cfg\Template;..\..\..\library\ucos\uC-CPU\Template;..\..\..\library\ucos\uC-CPU;..\..\..\library\ucos\uC-LIB;..\..\..\library\ucos\uC-LIB\Cfg\Template;..\..\..\library\ucos\uC-LIB\Ports\ARM-Cortex-M4\RealView;..\..\..\library\ucos;..\..\..\library\segger\Config;..\..\..\library\segger\Sample\uCOS-II;..\..\..\library\segger\Sample\uCOS-II\Config;..\..\..\library\segger\SEGGER;..\table;..\..\..\library\cjson</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@ -634,6 +634,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\library\drv_peripheral\drv_w5500.c</FilePath> <FilePath>..\..\..\library\drv_peripheral\drv_w5500.c</FilePath>
</File> </File>
<File>
<FileName>drv_eg25gminipice.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\library\drv_peripheral\drv_eg25gminipice.c</FilePath>
</File>
<File>
<FileName>drv_qfc41d.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\library\drv_peripheral\drv_qfc41d.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -1130,6 +1140,21 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\protocol\protocol_modbus_bcu.c</FilePath> <FilePath>..\protocol\protocol_modbus_bcu.c</FilePath>
</File> </File>
<File>
<FileName>protocol_mqtt_bcu.c</FileName>
<FileType>1</FileType>
<FilePath>..\protocol\protocol_mqtt_bcu.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Cjson</GroupName>
<Files>
<File>
<FileName>cJSON.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\library\cjson\cJSON.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
</Groups> </Groups>
@ -1693,6 +1718,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\library\drv_peripheral\drv_w5500.c</FilePath> <FilePath>..\..\..\library\drv_peripheral\drv_w5500.c</FilePath>
</File> </File>
<File>
<FileName>drv_eg25gminipice.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\library\drv_peripheral\drv_eg25gminipice.c</FilePath>
</File>
<File>
<FileName>drv_qfc41d.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\library\drv_peripheral\drv_qfc41d.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -2018,6 +2053,21 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\protocol\protocol_modbus_bcu.c</FilePath> <FilePath>..\protocol\protocol_modbus_bcu.c</FilePath>
</File> </File>
<File>
<FileName>protocol_mqtt_bcu.c</FileName>
<FileType>1</FileType>
<FilePath>..\protocol\protocol_mqtt_bcu.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Cjson</GroupName>
<Files>
<File>
<FileName>cJSON.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\library\cjson\cJSON.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
</Groups> </Groups>
@ -2037,4 +2087,13 @@
</files> </files>
</RTE> </RTE>
<LayerInfo>
<Layers>
<Layer>
<LayName>BCU_APP</LayName>
<LayPrjMark>1</LayPrjMark>
</Layer>
</Layers>
</LayerInfo>
</Project> </Project>

File diff suppressed because it is too large Load Diff

View File

@ -193,7 +193,7 @@ static uint32_t inter_modbus_count = 0,inter2_modbus_count = 0,inter3_modbus_cou
void modbus_rtu_inter_handler(uint32_t base_time) void modbus_rtu_inter_handler(uint32_t base_time)
{ {
inter_modbus_count++; inter_modbus_count++;
bsp_modbus_poll(modbus_rtu_array[kModbusIdx_Inter], true); //bsp_modbus_poll(modbus_rtu_array[kModbusIdx_Inter], true);
} }
@ -207,7 +207,7 @@ void modbus_rtu_extern_handler(uint32_t base_time)
void modbus_rtu_externII_handler(uint32_t base_time) void modbus_rtu_externII_handler(uint32_t base_time)
{ {
inter3_modbus_count++; inter3_modbus_count++;
bsp_modbus_poll(modbus_rtu_array[kModbusIdx_Exter2], true); // bsp_modbus_poll(modbus_rtu_array[kModbusIdx_Exter2], true);
} }
typedef void (* UintArgCall) (uint32_t arg); typedef void (* UintArgCall) (uint32_t arg);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,47 @@
/******************************************************************************
* @file protocol_mqtt_bcu.h
* @brief protocol_mqtt_bcu.h
* @version V1.0
* @author Gary
* @copyright
******************************************************************************/
#ifndef PROTOCOL_MQTT_BCU_H_
#define PROTOCOL_MQTT_BCU_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "cJSON.h"
#include "drv_qfc41d.h"
#include "drv_rtc.h"
typedef struct {
const char* key; // JSON 中的键,比如 "BCU_2"
uint8_t groupId; // mqtt因为json长度限制这里面用于分组传输,从0开始
uint16_t input; // get_val的入参用于获取key对应的数据
uint32_t (*get_val)(uint16_t); // 对应值的获取函数
} devPointMap;
typedef struct {
const char* key; // JSON 中的键,比如 "BCU_"后面不带数字数据后面通过BCU_pointId组合
uint16_t pointId; // 用于记录开始的测点号见bcu模型
uint16_t startCellIndex; // 开始的电压序号(入参)
uint16_t endCellIndex; // 结束的电压序号(入参)
uint32_t (*get_val)(uint16_t); // 对应值的获取函数
} devCellPointMap;
extern const devPointMap bms_points[];
extern const devCellPointMap bms_volt_points[];
extern const devCellPointMap bms_temp_points[];
void mqtt_publish_bms_data(uint32_t basetime);
#ifdef __cplusplus
}
#endif
#endif

3164
library/cjson/cJSON.c Normal file

File diff suppressed because it is too large Load Diff

306
library/cjson/cJSON.h Normal file
View File

@ -0,0 +1,306 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 18
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* Limits the length of circular references can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_CIRCULAR_LIMIT
#define CJSON_CIRCULAR_LIMIT 10000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable address area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
#define cJSON_SetBoolValue(object, boolValue) ( \
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
cJSON_Invalid\
)
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -50,7 +50,7 @@ __initial_sp
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h> ; </h>
Heap_Size EQU 0x00000400 Heap_Size EQU 0x00002000
AREA HEAP, NOINIT, READWRITE, ALIGN=3 AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base __heap_base

View File

@ -0,0 +1,181 @@
/******************************************************************************
* @file drv_eg25gminipice.c
* @brief drv_eg25gminipice.c drivers
* @version V1.0
* @author Gary
* @copyright
******************************************************************************/
#include "drv_eg25gminipice.h"
#define UART2_BAUDRATE 115200
#define MAX_RETRY 3
//4G实例化
static uint8_t sim_rec_buf[MAX_RECV_LEN] = {0};
LTE4G_STATIC_INIT(sim_item, 1, 0, 0, 1024,sim_rec_buf);
void drv_sim_push_data(Lte4GItem* item, uint8_t *buf, uint16_t len)
{
uint16_t i = 0;
if((item != NULL) && (item->buf_pos + len < item->buf_size))
{
for (i = 0; i < len; i++)
{
item->buf[item->buf_pos++] = buf[i];
}
}
}
void drv_uart2_Init(void)
{
RCC->APB1ENR |= RCC_APB1ENR_USART2EN; // 使能 USART2 时钟
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // 使能 GPIOA 时钟
GPIOA->MODER |= (2 << (2 * 2)) | (2 << (3 * 2)); // PA2(TX), PA3(RX) 复用模式
GPIOA->AFR[0] |= (7 << (2 * 4)) | (7 << (3 * 4)); // 复用 AF7 (USART2)
USART2->BRR = SystemCoreClock / UART2_BAUDRATE;
USART2->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; // 使能串口、发送和接收
}
void drv_uart2_sendbyte(char c)
{
while (!(USART2->SR & USART_SR_TXE)); // 等待发送完成
USART2->DR = c;
}
void drv_uart2_sendString(const char *str)
{
while (*str) {
drv_uart2_sendbyte(*str++);
}
}
void drv_send_at_cmd(const char *cmd, int delay_ms)
{
drv_uart2_sendString(cmd);
drv_uart2_sendString("\r\n"); // AT 指令以 "\r\n" 结尾
kit_time_dly_ms(30);
}
void drv_eg25g_init(void)
{
drv_send_at_cmd("AT", 500); // 1. 测试 AT 指令
drv_send_at_cmd("AT+CPIN?", 500); // 2. 查询 SIM 卡状态
drv_send_at_cmd("AT+COPS=0", 500); // 3. 让模块自动选择运营商
drv_send_at_cmd("AT+CEREG?", 1000); // 4. 查询 4G 注册状态
// drv_send_at_cmd("AT+CGDCONT=1,\"IP\",\"your_apn\"", 500); // 5. 设置 APN 如果支持自动识别则不需要设置apn
drv_send_at_cmd("AT+CGACT=1,1", 1000); // 6. 激活 PDP获取 IP
drv_send_at_cmd("AT+CGPADDR=1", 500); // 7. 查询分配的 IP 地址
}
// 发送 AT 指令并等待返回值,可用于此优化初始化函数
int drv_send_at_cmd2(const char *cmd, int delay_ms)
{
for (int i = 0; i < MAX_RETRY; i++) // 失败最多重试 MAX_RETRY 次
{
drv_uart2_sendString(cmd);
drv_uart2_sendString("\r\n"); // AT 指令以 "\r\n" 结尾
kit_time_dly_ms(30);
if (sim_item.buf_pos > 0 && strstr((const char*)sim_item.buf, "OK")) // 解析返回值
{
return 1; // 成功
}
}
return 0; // 失败
}
void drv_eg25g_init2(void)
{
if (!drv_send_at_cmd2("AT", 500)) return; // 1. 测试 AT 指令
if (!drv_send_at_cmd2("AT+CPIN?", 500)) return; // 2. 查询 SIM 卡状态
if (!drv_send_at_cmd2("AT+COPS=0", 500)) return; // 3. 让模块自动选择运营商
if (!drv_send_at_cmd2("AT+CEREG?", 1000)) return; // 4. 查询 4G 注册状态
if (!drv_send_at_cmd2("AT+CGDCONT=1,\"IP\",\"your_apn\"", 500)) return; // 5. 设置 APN
if (!drv_send_at_cmd2("AT+CGACT=1,1", 1000)) return; // 6. 激活 PDP获取 IP
if (!drv_send_at_cmd2("AT+CGPADDR=1", 500)) return; // 7. 查询分配的 IP 地址
}
#define MQTT_BROKER "47.120.14.45" // 你的 MQTT 服务器地址
#define MQTT_PORT 3011 // MQTT 端口
#define MQTT_CLIENT_ID "fc41d_client" // 客户端 ID
#define MQTT_USER "user" // MQTT 用户名
#define MQTT_PASSWORD "password" // MQTT 密码
#define MQTT_TOPIC "BCU01" // 订阅/发布的主题
#define MQTT_MESSAGE "Hello from FC41D!" // 发送的消息
#define WIFI_TIMEOUT 1000
// 连接 MQTT 服务器
uint8_t drv_mqtt_connect()
{
//1、设置 MQTT 协议的版本号为 V4
// snprintf(cmd, sizeof(cmd), "AT+QMTCFG=\"version\",1,4");
// if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set MQTT server!\r\n");
// return 1;
// }
//2、建立 MQTT 客户端与服务器之间的会话连接
char cmd[100] = {0};
snprintf(cmd, sizeof(cmd), "AT+QMTOPEN=0,\"%s\",%d",MQTT_BROKER,MQTT_PORT);
if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to set MQTT server!\r\n");
return 1;
}
//2、MQTT 客户端与服务器之间建立 MQTT 连接 AT+QMTCONN=<clientID>,<client_identity>,<username>,<password>
//snprintf(cmd, sizeof(cmd), "AT+QMTCONN=0,%s,%s,%s",MQTT_CLIENT_ID,MQTT_USER, MQTT_PASSWORD);
if (!drv_at_send_cmd("AT+QMTCONN=0,\"clientBCUwifi112233\"", "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to set MQTT client credentials!\r\n");
return 1;
}
// KIT_PRINTF("MQTT Connection Successful!\r\n");
return 0;
}
//void drv_mqtt_connect(void)
//{
//// drv_send_at_cmd("AT+QMTCFG=\"recv/mode\",0,0,1", 500);
// drv_send_at_cmd("AT+QMTOPEN=0,\"47.120.14.45\",3011", 5000);
// drv_send_at_cmd("AT+QMTCONN=0,\"clientBCUwifi01\"", 5000);
// drv_send_at_cmd("AT+QMTSUB=0,1,\"BCU01\",2", 5000);
//}
/*
void drv_mqtt_publish(const char *topic, const char *message)
{
char cmd[128];
sprintf(cmd, "AT+QMTPUB=0,0,0,0,\"%s\",\"%s\"", topic, message);
drv_send_at_cmd(cmd, 500);
}
*/
/*
int main(void) {
SystemInit();
drv_uart2_Init();
drv_eg25g_init();
drv_mqtt_connect();
while (1)
{
drv_mqtt_publish("sensor/data", "{\"temperature\":25.3}");
for (volatile int i = 0; i < 10000000; i++); // 发送间隔
}
}
*/

View File

@ -0,0 +1,61 @@
/******************************************************************************
* @file drv_eg25gminipice.h
* @brief drv_eg25gminipice drivers
* @version V1.0
* @author Gary
* @copyright
******************************************************************************/
#ifndef DRV_EG25GMINIPICE_H_
#define DRV_EG25GMINIPICE_H_
#include "drv_gpio.h"
#include "stm32f4xx.h"
#include "bsp_task.h"
#include "kit_time.h"
#include "kit_data.h"
#include "kit_debug.h"
#include "ucos_ii.h"
#include "string.h"
#define MAX_RECV_LEN 1024
//¶¨ÒåÄ£×é4G½á¹¹
typedef struct _Lte4GItem
{
uint8_t addr;
uint8_t comm_dev;
uint16_t buf_pos;
uint16_t buf_size;
uint8_t *buf;
} Lte4GItem;
#define LTE4G_STATIC_INIT(_name, _addr, _comm_dev, _buf_pos, _buf_size,_recv) \
Lte4GItem _name = \
{ \
(_addr), \
(_comm_dev), \
(_buf_pos),\
(_buf_size),\
(_recv),\
}
extern Lte4GItem sim_item;
void drv_uart2_Init(void);
void drv_uart2_sendbyte(char c);
void drv_uart2_sendString(const char *str);
void drv_send_at_cmd(const char *cmd, int delay_ms);
void drv_eg25g_init(void);
uint8_t drv_mqtt_connect();
//void drv_mqtt_publish(const char *topic, const char *message);
void drv_sim_push_data(Lte4GItem* item, uint8_t *buf, uint16_t len);
#endif //DRV_EG25GMINIPICE_H_

View File

@ -0,0 +1,344 @@
/******************************************************************************
* @file drv_qfc41d.c
* @brief drv_qfc41d driver
* @version V1.0
* @author Gary
* @copyright
******************************************************************************/
#include "drv_qfc41d.h"
uint8_t rev_buff[QFC41D_MAX_RECV_SIZE] = {0};
uint8_t send_buff[QFC41D_MAX_SEND_SIZE] = {0};
char wifiName[40] = "BLUESUNESS", wifiPassWord[40] = "bluesun009", bleName[40] = "bsm1";
char cmd[1000] = {0}; //降低栈空间使用
//定义
WifiBleItem qfc41dItem = {
.dev = QFC41D_UART_PORT,
.buf_pos = 0,
.buf_size = QFC41D_MAX_RECV_SIZE,
.buf = rev_buff,
.sendCall = NULL,
};
static void drv_qfc41d_push_data(WifiBleItem* item, uint8_t *buf, uint16_t len)
{
uint16_t i = 0;
if((item != NULL) && (item->buf_pos + len < item->buf_size))
{
item->buf[item->buf_pos++] = buf[i];
// 处理换行符,表示一条完整的 AT 指令返回
if (buf[i] == '\n')
{
item->buf[item->buf_pos] = '\0'; // 添加结束符
item->buf_pos = 0; // 重置索引,准备下一条数据
}
}
}
static void drv_qf41d_uart_rx_it_call(kit_ret_e res, void *data)
{
OS_TRACE_ISR_ENTER();
drv_qfc41d_push_data(&qfc41dItem, data, 1);
OS_TRACE_ISR_EXIT();
}
// 发送单个字符
void drv_wireless_send_char(char c)
{
while (!(USART2->SR & USART_SR_TXE)); // 等待发送缓冲区空
USART2->DR = c;
}
// 发送字符串
void drv_wireless_send_string(const char *str)
{
while (*str)
{
drv_wireless_send_char(*str++);
}
drv_wireless_send_char('\r'); // 发送 CR
drv_wireless_send_char('\n'); // 发送 LF
}
// 发送 AT 指令并等待返回值
int drv_at_send_cmd(const char *cmd, const char *response, uint32_t timeout)
{
memset(qfc41dItem.buf, 0, QFC41D_MAX_RECV_SIZE);
qfc41dItem.buf_pos = 0; // 清空接收缓冲区索引
drv_wireless_send_string(cmd);
uint32_t start_time = kit_time_get_tick(); // 获取当前时间
while (kit_time_get_tick() - start_time < timeout)
{
if (strstr((char *)qfc41dItem.buf, response))
{
return 1; // 成功匹配返回值
}
}
return 0; // 超时未收到期望数据
}
static uint8_t drv_wifi_init()
{
// 1. 设置模组波特率
/*
if (!drv_at_send_cmd(QFC41D_SET_BATE, "OK", WIFI_TIMEOUT))
{
KIT_PRINTF("WiFi Module not responding!\r\n");
return 1 ;
}
*/
// 2. 测试 AT 指令
if (!drv_at_send_cmd("AT", "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("WiFi Module not responding!\r\n");
return 1 ;
}
if (!drv_at_send_cmd("AT+QSTASTOP", "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to set WiFi mode!\r\n");
return 1;
}
if (!drv_at_send_cmd("AT+QSOFTAPSTOP", "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to set WiFi mode!\r\n");
return 1;
}
// if (!drv_at_send_cmd("AT+QSTAAPINFO=BLUESUNESS,bluesun009", "OK", WIFI_CONNECT_TIMEOUT))
// {
// KIT_PRINTF("Failed to set WiFi mode!\r\n");
// return 1;
// }
// kit_time_dly_ms(2000);
// if (!drv_at_send_cmd("AT+QSTAAPINFO=BLUESUNESS,bluesun009", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set WiFi mode!\r\n");
// return 1;
// }
// 3. 设置 Wi-Fi 为 DHCP使能
// if (!drv_at_send_cmd(QFC41D_SET_DHCP_ENABLE, "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set WiFi mode!\r\n");
// return 1;
// }
// 4. 连接 Wi-Fi
// snprintf(cmd, sizeof(cmd), "AT+QSTAAPINFODEF=%s,%s", wifiName, wifiPassWord);
// if (!drv_at_send_cmd(cmd, "WIFI CONNECTED", WIFI_TIMEOUT * 2))
// {
// KIT_PRINTF("Failed to connect to WiFi!\r\n");
// //return 1; //错误不返回-防止影响主任务执行
// }
// // 5. 获取 IP 地址
// if (!drv_at_send_cmd("AT+QGETIP=station", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to get IP address!\r\n");
// //return 1; //错误不返回-防止影响主任务执行
// }
// KIT_PRINTF("WiFi Initialization Successful!\r\n");
return 0;
}
static uint8_t drv_ble_init()
{
// 1. 初始化,蓝牙作为服务器
// if (!drv_at_send_cmd("AT+QBLEINIT=3", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to power off BLE!\r\n");
// return 1;
// }
//
// // 2. 设置蓝牙名称
// snprintf(cmd, sizeof(cmd), "AT+QBLENAME=%s", bleName);
// if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set BLE name!\r\n");
// return 1;
// }
// // 3. 设置广播参数
// if (!drv_at_send_cmd("AT+QBLEADVPARAM=2048,2048", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to enable BLE!\r\n");
// return 1;
// }
//
// // 4. 设置广播数据
// if (!drv_at_send_cmd("AT+QBLEADVDATA=06094643343144", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to enable BLE!\r\n");
// return 1;
// }
// // 5. 创建服务
// if (!drv_at_send_cmd("AT+QBLEGATTSSRV=FFF0", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set BLE role!\r\n");
// return 1;
// }
//
// // 6. 创建特征值
// if (!drv_at_send_cmd("AT+QBLEGATTSSRV=FFF1", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set BLE role!\r\n");
// return 1;
// }
// // 7. 开始广播
// if (!drv_at_send_cmd("AT+QBLEADVSTART", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to start BLE advertising!\r\n");
// return 1;
// }
// KIT_PRINTF("BLE Initialization Successful!\r\n");
if (!drv_at_send_cmd("AT+QBLEINIT=3", "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to set BLE role!\r\n");
return 1;
}
//设置wifi名称必须以BSM开头后缀可以加sn码
if (!drv_at_send_cmd("AT+QBLENAME=BSM112233", "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to start BLE advertising!\r\n");
return 1;
}
return 0;
}
uint8_t drv_qfc41d_init(void)
{
//初始化串口
drv_uart_init((UartDev)qfc41dItem.dev, 115200, 0 | UART_CFG_STOP_BIT_1, kGpioType_WIRELESSUart_Tx, kGpioType_WIRELESSUart_Rx);
USART2->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE | USART_CR1_UE;
//设置接收回调函数
drv_uart_set_interrupt(QFC41D_UART_PORT, kUartInterrupt_Rx, APP_CFG_INT_PRIO_UART2_RX, drv_qf41d_uart_rx_it_call);//#define SIM_UART_PORT kUartDev_2
//初始化wifi
// if(drv_wifi_init() != 0)
// {
// return 1;
// }
//初始化蓝牙BLE
if (drv_ble_init() != 0)
{
return 1;
}
return 0;
}
#define MQTT_BROKER "47.120.14.45" // 你的 MQTT 服务器地址
#define MQTT_PORT 3011 // MQTT 端口
#define MQTT_CLIENT_ID "fc41d_client" // 客户端 ID
#define MQTT_USER "user" // MQTT 用户名
#define MQTT_PASSWORD "password" // MQTT 密码
#define MQTT_TOPIC "BCU01" // 订阅/发布的主题
#define MQTT_MESSAGE "Hello from FC41D!" // 发送的消息
// 连接 MQTT 服务器
//uint8_t drv_mqtt_connect()
//{
//
// //1、设置 MQTT 协议的版本号为 V4
//// snprintf(cmd, sizeof(cmd), "AT+QMTCFG=\"version\",1,4");
//// if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
//// {
//// KIT_PRINTF("Failed to set MQTT server!\r\n");
//// return 1;
//// }
//
// //2、建立 MQTT 客户端与服务器之间的会话连接
// snprintf(cmd, sizeof(cmd), "AT+QMTOPEN=0,\"%s\",%d",MQTT_BROKER,MQTT_PORT);
// if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set MQTT server!\r\n");
// return 1;
// }
//
// //2、MQTT 客户端与服务器之间建立 MQTT 连接 AT+QMTCONN=<clientID>,<client_identity>,<username>,<password>
// //snprintf(cmd, sizeof(cmd), "AT+QMTCONN=0,%s,%s,%s",MQTT_CLIENT_ID,MQTT_USER, MQTT_PASSWORD);
// if (!drv_at_send_cmd("AT+QMTCONN=0,\"clientBCUwifi03\"", "OK", WIFI_TIMEOUT))
// {
// KIT_PRINTF("Failed to set MQTT client credentials!\r\n");
// return 1;
// }
// KIT_PRINTF("MQTT Connection Successful!\r\n");
// return 0;
//}
// 订阅 MQTT 主题
static uint8_t drv_mqtt_subscribe()
{
snprintf(cmd, sizeof(cmd), "AT+MQTTSUB=0,1,\"%s\",2", MQTT_TOPIC);
drv_wireless_send_string(cmd);
return 0;
}
// 发布 MQTT 消息
/*
* AT+QMTPUB=<clientID>,<msgID>,<QoS>,<retain>,<topic>,<payload_len gth>,<payload>
* length 0~1500
* str mqtt传输的json串
*/
uint8_t drv_mqtt_publish(char* str,uint16_t length)
{
snprintf(cmd, sizeof(cmd), "AT+QMTPUB=0,1,2,0,%s,%d,%s",MQTT_TOPIC, length, str);
if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
{
// KIT_PRINTF("Failed to publish message!\r\n");
return 1;
}
// KIT_PRINTF("MQTT Message Published Successfully!\r\n");
return 0;
}
uint8_t drv_mqtt_publish_no_respose(char* str,uint16_t length)
{
// snprintf(cmd, sizeof(cmd), "AT+QMTPUB=0,1,2,0,%s,%d,%s",MQTT_TOPIC, length, str);
snprintf(cmd, sizeof(cmd), "AT+QMTPUB=0,1,2,0,\"%s\",%d,\"%s\"", MQTT_TOPIC, length, str);
drv_wireless_send_string(cmd); // 未使用DMA
// drv_wireless_send_string_dma(cmd); // 使用DMA
return 0;
}
// MQTT 初始化
//uint8_t drv_mqtt_init()
//{
// if (drv_mqtt_connect() != 0)
// {
// return 1;
// }
// if (drv_mqtt_subscribe() != 0)
// {
// return 1;
// }
// return 0;
//}

View File

@ -0,0 +1,72 @@
/******************************************************************************
* @file drv_qfc41d.h
* @brief drv_qfc41d.h
* @version V1.0
* @author Gary
* @copyright
******************************************************************************/
#ifndef DRV_QFC41D_H_
#define DRV_QFC41D_H_
#include <stdio.h>
#include <stdint.h>
#include <stm32f4xx.h>
#include <string.h>
#include "drv_uart.h"
#include "kit_macro.h"
#include "ucos_ii.h"
#include "gpio_manager.h"
#include "kit_time.h"
#include "kit_debug.h"
#define QFC41D_UART_PORT kUartDev_2
#define QFC41D_MAX_SEND_SIZE 2048
#define QFC41D_MAX_RECV_SIZE 200
#define WIFI_TIMEOUT 1000
#define WIFI_CONNECT_TIMEOUT 10000
#define QFC41D_RESTART_CMD "AT+QRST"
#define QFC41D_PING_CMD "AT+QPING=<IP>"
#define QFC41D_LOW_POWER_MODE "AT+QLOWPOWER"
#define QFC41D_GET_MACK_ADDR "AT+QWLMAC"
#define QFC41D_GET_WIFISTA_STATUS "AT+QSTAST"
#define QFC41D_SET_DHCP_ENABLE "AT+QSTADHCPDEF=1"
//该命令用于设置串口波特率:AT+QSETBAND=<baud_rate>[,<save>] <baud_rate> 整型,串口波特率。<save>省略该参数则保存波特率。0:不保存波特率 1:保存波特率
#define QFC41D_SET_BATE "AT+QSETBAND=115200,1"
/* 下面命令用于模块作为外围设备时发送 GATT 数据
* AT+QBLEGATTSNTFY=<UUID>[,<hex_lngth>],<data>
* <UUID> UUID 2 16
* <hex_length> 使<data> <data> 123456 0x123456
* <data> GATT
*/
#define QFC41D_BLE_INIT "AT+QBLEINIT=2"
typedef void (*FC41DSendCall)(UartDev dev, uint8_t *buf, uint16_t len);
typedef struct
{
uint8_t dev;
uint16_t buf_pos;
uint16_t buf_size;
uint8_t *buf;
FC41DSendCall sendCall;
}WifiBleItem;
uint8_t drv_qfc41d_init(void);
// MQTT 初始化
uint8_t drv_mqtt_init();
// 发布 MQTT 消息
uint8_t drv_mqtt_publish(char* str,uint16_t length);
uint8_t drv_mqtt_publish_no_respose(char* str,uint16_t length);
#endif //DRV_QFC41D_H_

View File

@ -25,6 +25,8 @@
#define DMA_STREAM3_IT_ERR ((uint32_t)0x03400000) #define DMA_STREAM3_IT_ERR ((uint32_t)0x03400000)
#define DMA_STREAM3_IT_FLAG ((uint32_t)0x0F400000) #define DMA_STREAM3_IT_FLAG ((uint32_t)0x0F400000)
extern uint8_t dma_tx_busy;
typedef enum typedef enum
{ {
kDmaIdx_0, kDmaIdx_0,
@ -274,6 +276,20 @@ void DMA1_Stream5_IRQHandler(void)
{ {
} }
//void DMA1_Stream6_IRQHandler(void)
//{
// if (DMA1->HISR & DMA_HISR_TCIF6) {
// DMA1->HIFCR |= DMA_HIFCR_CTCIF6;
// dma_tx_busy = 0;
// USART2->CR3 &= ~USART_CR3_DMAT; // 传输完成后关闭DMA请求
// }
// else if (DMA1->HISR & DMA_HISR_TEIF6) {
// DMA1->HIFCR |= DMA_HIFCR_CTEIF6;
// dma_tx_busy = 0;
// }
//}
void DMA1_Channel6_IRQHandler(void) void DMA1_Channel6_IRQHandler(void)
{ {
} }

View File

@ -9,6 +9,16 @@ extern "C"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
/***************************ÖжÏÓÅÏȼ¶*********************/
#define APP_CFG_INT_PRIO_PWR_OFF 0u
#define APP_CFG_INT_PRIO_CAN1_RX 1u
#define APP_CFG_INT_PRIO_CAN1_TX 2u
#define APP_CFG_INT_PRIO_CAN2_RX 3u
#define APP_CFG_INT_PRIO_CAN2_TX 4u
#define APP_CFG_INT_PRIO_SYSTICK 5u
#define APP_CFG_INT_PRIO_UART2_RX 6u
typedef enum typedef enum
{ {
kKit_Ret_Ok = 0x00, kKit_Ret_Ok = 0x00,