11.22:完善注释;提高代码的移植性;完善串口程序。
This commit is contained in:
195
STM32/Gateway_Node/Drivers/LoRa.c
Normal file
195
STM32/Gateway_Node/Drivers/LoRa.c
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user