11.22:完善注释;提高代码的移植性;完善串口程序。

This commit is contained in:
2025-11-22 20:16:58 +08:00
parent 2891992946
commit 33e53ec469
32 changed files with 5308 additions and 266 deletions

View File

@@ -0,0 +1 @@
#include "ESP8266.h"

View File

@@ -0,0 +1,5 @@
#ifndef __ESP8266_H__
#define __ESP8266_H__
#endif

View File

@@ -0,0 +1,35 @@
#include "LED.h"
void vPc13LedInit(void)
{
RCC_APB2PeriphClockCmd(LED_PC13_GPIO_CLOCK,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LED_PC13_GPIO_PIN; //PC13
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_PC13_GPIO_PORT,&GPIO_InitStructure);
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
/* <20><><EFBFBD><EFBFBD>led<65>϶࣬<CFB6><E0A3AC><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>һ<EFBFBD><D2BB>LED_Set<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>ƣ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>񿪻<EFBFBD><F1BFAABB>ǹ<EFBFBD> */
void vPc13LedOn(void)
{
GPIO_ResetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
void vPc13LedOff(void)
{
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
/* ʵ<>ְ<EFBFBD>һ<EFBFBD><D2BB>Ϩ<EFBFBD><CFA8><EFBFBD><EFBFBD><EFBFBD>ٰ<EFBFBD>һ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>LED<45><44>״̬ȡ<CCAC><C8A1><EFBFBD><EFBFBD>ʵ<EFBFBD>ֵ<EFBFBD>ƽ<EFBFBD><C6BD>ת<EFBFBD><D7AA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD> */
void vPc13LedTurn(void)
{
if(GPIO_ReadOutputDataBit(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN) == 0)//<2F><><EFBFBD><EFBFBD>PA0<41><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>Ϊ0
{
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN); //<2F><>PA0<41><30>1
}else
{
GPIO_ResetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
}

View File

@@ -0,0 +1,18 @@
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ֹͷ<D6B9>ļ<EFBFBD><C4BC>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>if not define<6E><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD>һ<EFBFBD><D2BB> */
#ifndef __LED_H__
#define __LED_H__
#include "stm32f10x.h" // Device header
/* PC13LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define LED_PC13_GPIO_CLOCK RCC_APB2Periph_GPIOC
#define LED_PC13_GPIO_PORT GPIOC
#define LED_PC13_GPIO_PIN GPIO_Pin_13
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void vPc13LedInit(void);
void vPc13LedOn(void);
void vPc13LedOff(void);
void vPc13LedTurn(void);
#endif

View File

@@ -0,0 +1,195 @@
#include "LoRa.h"
void vLoRaConnectionPkt(uint8_t ucNodeId)
{
if (ucNodeId == xLoRaNode1Config.ucLoRaNode1Identifier)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaNode1Config, 3);
}
else if (ucNodeId == xLoRaNode2Config.ucLoRaNode2Identifier)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaNode2Config, 3);
}
else
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaGateConfig, 3);
}
}
/**
* @brief LoRa<52><61><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>hex<65><78><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><><D2B2>LoRa<52>ڶ<EFBFBD><DAB6><EFBFBD>ģʽ<C4A3><CABD>ִ<EFBFBD>нڵ<D0BD><DAB5><EFBFBD>ͨ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @note hex<65><78><EFBFBD>ݰ<EFBFBD><DDB0>ĸ<EFBFBD>ʽΪ<CABD>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD>
* @param None
* @retval None
*/
void vLoRaToGateIdPkt(uint8_t ucNodeId)
{
if (ucNodeId == xLoRaNode1Config.ucLoRaNode1Identifier)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaNode1Config.ucLoRaNode1Identifier, 1);
} else if (ucNodeId == xLoRaNode2Config.ucLoRaNode2Identifier)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaNode2Config.ucLoRaNode2Identifier, 1);
}
}
void vLoRaToGateSenIdPkt(uint8_t ucSensorId)
{
if (ucSensorId == xLoRaSensorID.ucIdDht11)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaSensorID.ucIdDht11, 1);
} else if (ucSensorId == xLoRaSensorID.ucIdMq2)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaSensorID.ucIdMq2, 1);
} else if (ucSensorId == xLoRaSensorID.ucIdFire)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaSensorID.ucIdFire, 1);
} else if (ucSensorId == xLoRaSensorID.ucIdLight)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaSensorID.ucIdLight, 1);
}
}
void vLoRaToGateExeIdPkt(uint8_t ucExeId)
{
if (ucExeId == xLoRaExecutorID.ucIdLed)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaExecutorID.ucIdLed, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdFan)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaExecutorID.ucIdFan, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdHumidifier)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaExecutorID.ucIdHumidifier, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdBuzzer)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaExecutorID.ucIdBuzzer, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdServo)
{
/* code */
vUsartSendArray(USART3, (uint8_t *)&xLoRaExecutorID.ucIdServo, 1);
}
}
eLoRaMsgRecStatus xLoRaMessageReceived(uint8_t *pucData)
{
switch (*pucData)
{
case 0xD1:
/* code */
return statusNode1;
case 0xD2:
return statusNode2;
case 0xFA:
return statusExeLed;
case 0xFB:
return statusExeFan;
case 0xFC:
return statusExeHumidifier;
case 0xFD:
return statusExeBuzzer;
case 0xFE:
return statusExeServo;
case 0x01:
return statusExeOn;
case 0x00:
return statusExeOff;
default:
return null;
}
}
eLoRaMsgRecStatus xLoRaMsgProcess(uint8_t ucDataRecNodeId, uint8_t ucDataRecExeId, uint8_t ucDataRecExeSta)
{
switch (xLoRaMessageReceived(&ucDataRecNodeId))
{
case statusNode1:
/* code */
while (xLoRaMessageReceived(&ucDataRecExeSta) == statusExeOn)
{
/* code */
if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeLed)
{
/* code */
return statusLedOn;
} else if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeFan)
{
/* code */
return statusFanOn;
} else if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeHumidifier)
{
/* code */
return statusHumidifierOn;
}
}
while (xLoRaMessageReceived(&ucDataRecExeSta) == statusExeOff)
{
/* code */
if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeLed)
{
/* code */
return statusLedOff;
} else if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeFan)
{
/* code */
return statusFanOff;
} else if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeHumidifier)
{
/* code */
return statusHumidifierOff;
}
}
case statusNode2:
while (xLoRaMessageReceived(&ucDataRecExeSta) == statusExeOn)
{
/* code */
if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeBuzzer)
{
/* code */
return statusBuzzerOn;
} else if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeServo)
{
/* code */
return statusServoOn;
}
}
while (xLoRaMessageReceived(&ucDataRecExeSta) == statusExeOff)
{
/* code */
if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeBuzzer)
{
/* code */
return statusBuzzerOff;
} else if (xLoRaMessageReceived(&ucDataRecExeId) == statusExeServo)
{
/* code */
return statusServoOff;
}
}
default:
return null;
}
}

View File

@@ -0,0 +1,151 @@
#ifndef __LORA_H__
#define __LORA_H__
//#include "USART3.h"
#include "USART.h"
// #define LORA_MODE
/* LoRa<52>ľ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD> */
#define LORA_MODE_INIT 1
#define LORA_GPIO_PIN_TX GPIO_Pin_10
#define LORA_GPIO_PIN_RX GPIO_Pin_11
#define LORA_GPIO_PIN_ATK_AUX GPIO_Pin_4 //PA4
#define LORA_GPIO_PIN_ATK_MD0 GPIO_Pin_3 //PB3
#define LORA_GATE_ADDR_HIGH 0x03
#define LORA_GATE_ADDR_LOW 0xE9
#define LORA_GATE_CHANNEL 0x17
#define LORA_NODE1_ADDR_HIGH 0x03
#define LORA_NODE1_ADDR_LOW 0xEA
#define LORA_NODE1_CHANNEL 0x17
#define LORA_NODE1_IDENTIFIER 0xD1
#define LORA_NODE2_ADDR_HIGH 0x03
#define LORA_NODE2_ADDR_LOW 0xEB
#define LORA_NODE2_CHANNEL 0x17
#define LORA_NODE2_IDENTIFIER 0xD2
#define LORA_SENSOR_DHT11 0xEA
#define LORA_SENSOR_MQ2 0xEB
#define LORA_SENSOR_LIGHT 0xEC
#define LORA_SENSOR_FIRE 0xED
#define LORA_EXECUTOR_LED 0xFA
#define LORA_EXECUTOR_FAN 0xFB
#define LORA_EXECUTOR_HUMIDIFIER 0xFC
#define LORA_EXECUTOR_BUZZER 0xFD
#define LORA_EXECUTOR_SERVO 0xFE
#define LORA_EXECUTOR_COMMAND_ON 0x01
#define LORA_EXECUTOR_COMMAND_OFF 0x00
/* LoRa<52><61>ֲ<EFBFBD><D6B2> */
typedef enum {
statusGatawayNode = 1,
statusNode1,
statusNode2,
statusExeLed,
statusExeFan,
statusExeHumidifier,
statusExeBuzzer,
statusExeServo,
statusExeOn,
statusExeOff,
statusLedOn,
statusLedOff,
statusFanOn,
statusFanOff,
statusHumidifierOn,
statusHumidifierOff,
statusBuzzerOn,
statusBuzzerOff,
statusServoOn,
statusServoOff,
null
}eLoRaMsgRecStatus;
typedef struct {
uint8_t ucLoRaGateAddrHigh;
uint8_t ucLoRaGateAddrLow;
uint8_t ucLoRaGateChannel;
} LoRaGateConfig_t;
typedef struct {
uint8_t ucLoRaNode1AddrHigh;
uint8_t ucLoRaNode1AddrLow;
uint8_t ucLoRaNode1Channel;
uint8_t ucLoRaNode1Identifier;
} LoRaNode1Config_t;
typedef struct {
uint8_t ucLoRaNode2AddrHigh;
uint8_t ucLoRaNode2AddrLow;
uint8_t ucLoRaNode2Channel;
uint8_t ucLoRaNode2Identifier;
} LoRaNode2Config_t;
typedef struct {
uint8_t ucIdDht11;
uint8_t ucIdMq2;
uint8_t ucIdLight;
uint8_t ucIdFire;
} LoRaSensorID_t;
typedef struct {
uint8_t ucIdLed;
uint8_t ucIdFan;
uint8_t ucIdHumidifier;
uint8_t ucIdBuzzer;
uint8_t ucIdServo;
} LoRaExecutorID_t;
typedef struct {
uint8_t ucCommandOn;
uint8_t ucCommandOff;
} LoRaExecutorCmd_t;
static LoRaGateConfig_t xLoRaGateConfig = {
.ucLoRaGateAddrHigh = LORA_GATE_ADDR_HIGH,
.ucLoRaGateAddrLow = LORA_GATE_ADDR_LOW,
.ucLoRaGateChannel = LORA_GATE_CHANNEL
};
static LoRaNode1Config_t xLoRaNode1Config = {
.ucLoRaNode1AddrHigh = LORA_NODE1_ADDR_HIGH,
.ucLoRaNode1AddrLow = LORA_NODE1_ADDR_LOW,
.ucLoRaNode1Channel = LORA_NODE1_CHANNEL,
.ucLoRaNode1Identifier = LORA_NODE1_IDENTIFIER,
};
static LoRaNode2Config_t xLoRaNode2Config = {
.ucLoRaNode2AddrHigh = LORA_NODE2_ADDR_HIGH,
.ucLoRaNode2AddrLow = LORA_NODE2_ADDR_LOW,
.ucLoRaNode2Channel = LORA_NODE2_CHANNEL,
.ucLoRaNode2Identifier = LORA_NODE2_IDENTIFIER
};
static LoRaSensorID_t xLoRaSensorID = {
.ucIdDht11 = LORA_SENSOR_DHT11,
.ucIdMq2 = LORA_SENSOR_MQ2,
.ucIdLight = LORA_SENSOR_LIGHT,
.ucIdFire = LORA_SENSOR_FIRE
};
static LoRaExecutorID_t xLoRaExecutorID = {
.ucIdLed = LORA_EXECUTOR_LED,
.ucIdFan = LORA_EXECUTOR_FAN,
.ucIdHumidifier = LORA_EXECUTOR_HUMIDIFIER,
.ucIdBuzzer = LORA_EXECUTOR_BUZZER,
.ucIdServo = LORA_EXECUTOR_SERVO
};
static LoRaExecutorCmd_t xLoRaExecutorCommand = {
.ucCommandOn = LORA_EXECUTOR_COMMAND_ON,
.ucCommandOff = LORA_EXECUTOR_COMMAND_OFF,
};
void vLoRaConnectionPkt(uint8_t ucNodeId);
void vLoRaToGateIdPkt(uint8_t ucNodeId);
void vLoRaToGateSenIdPkt(uint8_t ucSensorId);
void vLoRaToGateExeIdPkt(uint8_t ucExecutorId);
eLoRaMsgRecStatus xLoRaMessageReceived(uint8_t *pucData);
eLoRaMsgRecStatus xLoRaMsgProcess(uint8_t ucDataRecNodeId, uint8_t ucDataRecExeId, uint8_t ucDataRecExeSta);
#endif