Compare commits

..

1 Commits

Author SHA1 Message Date
起床就犯困 fd6cf82bd3 完成部分对下数据接收,添加485发送后切换为读状态延时(未测试) 2025-03-06 10:12:57 +08:00
15 changed files with 8854 additions and 9047 deletions

View File

@ -86,7 +86,7 @@ void J1_SensorDataAnalysis(void)
/* 数据包 */ /* 数据包 */
send += 2; send += 2;
memcpy((char *)send, (char *)J1_485RxBuffer, J1_485RxBufferIndex); strlcpy((char *)send, (char *)J1_485RxBuffer, J1_485RxBufferIndex);
/* 结束标志 */ /* 结束标志 */
send += J1_485RxBufferIndex; send += J1_485RxBufferIndex;
@ -157,7 +157,7 @@ void J2_SensorDataAnalysis(void)
/* 数据包 */ /* 数据包 */
send += 2; send += 2;
memcpy((char *)send, (char *)J2_485RxBuffer, J2_485RxBufferIndex); strlcpy((char *)send, (char *)J2_485RxBuffer, J2_485RxBufferIndex);
/* 结束标志 */ /* 结束标志 */
send += J2_485RxBufferIndex; send += J2_485RxBufferIndex;
@ -227,7 +227,7 @@ void J3_SensorDataAnalysis(void)
/* 数据包 */ /* 数据包 */
send += 2; send += 2;
memcpy((char *)send, (char *)J3_485RxBuffer, J3_485RxBufferIndex); strlcpy((char *)send, (char *)J3_485RxBuffer, J3_485RxBufferIndex);
/* 结束标志 */ /* 结束标志 */
send += J3_485RxBufferIndex; send += J3_485RxBufferIndex;
@ -297,7 +297,7 @@ void J4_SensorDataAnalysis(void)
/* 数据包 */ /* 数据包 */
send += 2; send += 2;
memcpy((char *)send, (char *)J4_485RxBuffer, J4_485RxBufferIndex); strlcpy((char *)send, (char *)J4_485RxBuffer, J4_485RxBufferIndex);
/* 结束标志 */ /* 结束标志 */
send += J4_485RxBufferIndex; send += J4_485RxBufferIndex;
@ -367,7 +367,7 @@ void J5_0_SensorDataAnalysis(void)
/* 数据包 */ /* 数据包 */
send += 2; send += 2;
memcpy((char *)send, (char *)J5_0_485RxBuffer, J5_0_485RxBufferIndex + 1); strlcpy((char *)send, (char *)J5_0_485RxBuffer, J5_0_485RxBufferIndex);
/* 结束标志 */ /* 结束标志 */
send += J5_0_485RxBufferIndex; send += J5_0_485RxBufferIndex;

View File

@ -55,7 +55,6 @@ static void common_Task(void *pvParameters)
// } // }
uint16_t HeapSizeNum = 0; uint16_t HeapSizeNum = 0;
uint16_t LedNum = 0;
/* 用于绝对延时 */ /* 用于绝对延时 */
TickType_t xLastWakeTime; TickType_t xLastWakeTime;
@ -63,8 +62,6 @@ static void common_Task(void *pvParameters)
// 初始化 xLastWakeTime // 初始化 xLastWakeTime
xLastWakeTime = xTaskGetTickCount(); xLastWakeTime = xTaskGetTickCount();
while (1) { while (1) {
// uint8_t *Buff = (uint8_t *)pvPortMalloc(200); // uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
// if (Buff == NULL) { // if (Buff == NULL) {
@ -75,7 +72,7 @@ static void common_Task(void *pvParameters)
// queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff; // queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
// sendBuff->length = sizeof("hello world\n"); // sendBuff->length = sizeof("hello world\n");
// sendBuff->data = Buff + sizeof(queueUartSendInfo); // sendBuff->data = Buff + sizeof(queueUartSendInfo);
// memcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n")); // strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
// xQueueSend(upward_uart_Queue, &Buff, 10); // xQueueSend(upward_uart_Queue, &Buff, 10);
@ -94,7 +91,7 @@ static void common_Task(void *pvParameters)
// sendBuff->length = sizeof("hello world\n"); // sendBuff->length = sizeof("hello world\n");
// sendBuff->data = Buff + sizeof(queueTimeShareSendInfo); // sendBuff->data = Buff + sizeof(queueTimeShareSendInfo);
// sendBuff->connectPort = connectJ0; // sendBuff->connectPort = connectJ0;
// memcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n")); // strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
// xQueueSend(J5_0_485_Queue, &Buff, 10); // xQueueSend(J5_0_485_Queue, &Buff, 10);
@ -104,19 +101,12 @@ static void common_Task(void *pvParameters)
setWorkVoltage(getInVoltage()); setWorkVoltage(getInVoltage());
/* 当内存碎片过多时,后续可以在其中处理 */ /* 当内存碎片过多时,后续可以在其中处理 */
if (HeapSizeNum++ == 25) { if (HeapSizeNum == 25) {
HeapSizeNum = 0; HeapSizeNum = 0;
log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize()); log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
// log_info("getRs485State : %d\n", getRs485State(g_J5_0_usart3_handle));
// log_info("getUartSendState : %d\n", getUartSendState(g_J5_0_usart3_handle));
// log_info("getBUSIDLEFlag : %d\n", getBUSIDLEFlag(g_J5_0_usart3_handle));
}
if (LedNum++ == 3) {
LedNum = 0;
ledToggle();
} }
HeapSizeNum++;
vTaskDelayUntil(&xLastWakeTime, xFrequency); vTaskDelayUntil(&xLastWakeTime, xFrequency);
// vTaskDelay(200); // vTaskDelay(200);
} }
@ -209,8 +199,6 @@ void startApp(void)
Delay_Ms(1000); Delay_Ms(1000);
set_485_Read(); set_485_Read();
writePwrCtrlState(Android_PwrCtrl, GPIO_SET);
// writePwrCtrlState(J1_PwrCtrl, GPIO_SET);
/* create task */ /* create task */
xTaskCreate((TaskFunction_t )common_Task, xTaskCreate((TaskFunction_t )common_Task,

View File

@ -48,7 +48,7 @@ void readConfigParameter(void)
parameter.J2_485_Baud = 9600; parameter.J2_485_Baud = 9600;
parameter.J3_485_Baud = 9600; parameter.J3_485_Baud = 9600;
parameter.J4_485_Baud = 9600; parameter.J4_485_Baud = 9600;
parameter.J5_0_485_Baud = 115200; parameter.J5_0_485_Baud = 9600;
parameter.upWard_Uart_Baud = 115200; parameter.upWard_Uart_Baud = 115200;
} }
} }

View File

@ -158,7 +158,6 @@ void uartQueueSend(void)
if (!flag) { if (!flag) {
/* 延时三个系统节拍 */ /* 延时三个系统节拍 */
vTaskDelay(3); vTaskDelay(3);
log_info("getRs485State : %d\n", getRs485State(g_J5_0_usart3_handle));
} }
flag = 0; flag = 0;
} }

View File

@ -300,7 +300,6 @@ uint16_t ReadRegisterPort9_Power(void *pMsg)
uint16_t WriteRegisterPort1_Power(void *pMsg) uint16_t WriteRegisterPort1_Power(void *pMsg)
{ {
writePwrCtrlState(J1_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg)); writePwrCtrlState(J1_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
log_info("state %d\n", (uint8_t)(*(uint16_t *)pMsg));
return 0; return 0;
} }
@ -476,14 +475,14 @@ uint8_t analysisFunctionCodeGW(void)
} }
} }
// if (gw485RxBufferIndex >= 5 && gw485RxBuffer[2] == SL_Function_Code_Write_Register) { if (gw485RxBufferIndex >= 5 && gw485RxBuffer[2] == SL_Function_Code_Write_Register) {
// /* дÈë¼Ä´æÆ÷ÆðʼµØÖ· */ /* дÈë¼Ä´æÆ÷ÆðʼµØÖ· */
// uint16_t startResAddr = ((gw485RxBuffer[3] << 8) | gw485RxBuffer[4]); uint16_t startResAddr = ((gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
// if (startResAddr < maxStartWriteResAddr) { if (startResAddr < maxStartWriteResAddr) {
// state = writeRegStartAddressGW; state = writeRegStartAddressGW;
// return TRUE; return TRUE;
// } }
// } }
/* 解析配置文件下发帧数 */ /* 解析配置文件下发帧数 */
if ((gw485RxBufferIndex >= 5) && (gw485RxBuffer[2] == SL_Function_Code_Distribution_Profile)) { if ((gw485RxBufferIndex >= 5) && (gw485RxBuffer[2] == SL_Function_Code_Distribution_Profile)) {
@ -523,17 +522,16 @@ uint8_t analysisFunctionCodeGW(void)
#define ReadRegStartAddressGWMaxLen 7 #define ReadRegStartAddressGWMaxLen 7
uint8_t analysisReadRegStartAddressGW(void) uint8_t analysisReadRegStartAddressGW(void)
{ {
if (gw485RxBufferIndex >= ReadRegStartAddressGWMaxLen) { if (gw485RxBufferIndex >= 7) {
/* 读取寄存器起始地址 */ /* 读取寄存器起始地址 */
uint16_t resAddrLen = ((gw485RxBuffer[5] << 8) | gw485RxBuffer[6]); uint16_t resAddrLen = ((gw485RxBuffer[5] << 8) | gw485RxBuffer[6]);
if (resAddrLen < maxReadResAddrLen) { if (resAddrLen < maxReadResAddrLen) {
state = readRegStartNumberGW; state = readRegStartNumberGW;
return TRUE; return TRUE;
} }
log_error("resAddrLen : %d \n", resAddrLen);
} }
if (gw485RxBufferIndex < ReadRegStartAddressGWMaxLen) { if (gw485RxBufferIndex < functionCodeGWMaxLen) {
return FALSE; return FALSE;
} }
state = wait; state = wait;
@ -582,7 +580,7 @@ uint8_t analysisCrcCheckBitGW(void)
/* 结束标志校验校验 */ /* 结束标志校验校验 */
if (gw485RxBufferIndex == frameLength) { if (gw485RxBufferIndex == frameLength) {
if (gw485RxBuffer[frameLength - 1] == 0x16) { if (gw485RxBuffer[frameLength - 1] == 0x16) {
state = endFlagGW; state = endFlagSL;
return TRUE; return TRUE;
} }
} }
@ -641,7 +639,7 @@ uint8_t analysisWriteRegStartAddressGW(void)
uint16_t resAddrLen = ((gw485RxBuffer[5] << 8) | gw485RxBuffer[6]); uint16_t resAddrLen = ((gw485RxBuffer[5] << 8) | gw485RxBuffer[6]);
if (resAddrLen < maxReadResAddrLen) { if (resAddrLen < maxReadResAddrLen) {
frameLength = 10 + 2 * resAddrLen; frameLength = 10 + 2 * resAddrLen;
state = writeRegStartNumberGW; state = readRegStartNumberGW;
return TRUE; return TRUE;
} }
} }
@ -667,14 +665,12 @@ uint8_t analysisWriteRegStartNumberGW(void)
/* crc校验 */ /* crc校验 */
if (gw485RxBufferIndex >= WriteRegStartNumberGWMaxLen) { if (gw485RxBufferIndex >= WriteRegStartNumberGWMaxLen) {
uint16_t tempCrc = 0; uint16_t tempCrc = 0;
tempCrc = ((uint16_t)gw485RxBuffer[frameLength - 3] << 8) | (uint16_t)gw485RxBuffer[frameLength - 2]; tempCrc = (gw485RxBuffer[frameLength - 3] << 8) | gw485RxBuffer[frameLength - 2];
if (tempCrc == checkModebusCrc(gw485RxBuffer, frameLength - 3)) { if (tempCrc == checkModebusCrc(gw485RxBuffer, frameLength - 3)) {
state = crcCheckBitGW; state = crcCheckBitGW;
return TRUE; return TRUE;
} }
// log_error("tempCrc : %x \n", tempCrc);
// log_error("checkModebusCrc : %x \n", checkModebusCrc(gw485RxBuffer, frameLength - 3));
} }
if (gw485RxBufferIndex < WriteRegStartNumberGWMaxLen) { if (gw485RxBufferIndex < WriteRegStartNumberGWMaxLen) {
@ -883,20 +879,19 @@ uint8_t analysisEndFlagSL(void)
if (gw485RxBuffer[2] > 0 && gw485RxBuffer[2] < 5) { if (gw485RxBuffer[2] > 0 && gw485RxBuffer[2] < 5) {
Buff = (uint8_t *)pvPortMalloc(tempLen + queueUartSendInfoSize); Buff = (uint8_t *)pvPortMalloc(tempLen + queueUartSendInfoSize);
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff; queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
sendBuff->length = tempLen; sendBuff->length = tempLen + 1;
sendBuff->data = Buff + queueUartSendInfoSize; sendBuff->data = Buff + queueUartSendInfoSize;
memcpy((char *)sendBuff->data, (char *)&gw485RxBuffer[5], tempLen); strlcpy((char *)sendBuff->data, (char *)&gw485RxBuffer[5], tempLen + 1);
} }
else { else {
Buff = (uint8_t *)pvPortMalloc(tempLen + queueTimeShareSendInfoSize); Buff = (uint8_t *)pvPortMalloc(tempLen + queueTimeShareSendInfoSize);
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff; queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
sendBuff->length = tempLen; sendBuff->length = tempLen + 1;
sendBuff->data = Buff + queueTimeShareSendInfoSize; sendBuff->data = Buff + queueTimeShareSendInfoSize;
memcpy((char *)sendBuff->data, (char *)&gw485RxBuffer[5], tempLen); strlcpy((char *)sendBuff->data, (char *)&gw485RxBuffer[5], tempLen + 1);
// printf("\n\n\n\n\n%s\n", (char *)gw485RxBuffer);
// printf("%s\n%d\n\n\n\n\n\n", sendBuff->data, tempLen);
} }
/* 通过不同的端口将数据发送到不同的地方 */ /* 通过不同的端口将数据发送到不同的地方 */
if (gw485RxBuffer[2] == 1) { if (gw485RxBuffer[2] == 1) {
if (uxQueueSpacesAvailable(J1_485_Queue)) { if (uxQueueSpacesAvailable(J1_485_Queue)) {
@ -1034,7 +1029,6 @@ void GW_MsgProcFunc_Read_Register(device_handle device,uint8_t *buff, uint16_t b
if (xPortGetFreeHeapSize() < tempLen + 1024) { if (xPortGetFreeHeapSize() < tempLen + 1024) {
return; return;
} }
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen); uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff; queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
sendBuff->length = 8 + 2 * Register_Number_16; sendBuff->length = 8 + 2 * Register_Number_16;
@ -1098,7 +1092,7 @@ void GW_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t Ms
/* 将指令中的数据读取出来 */ /* 将指令中的数据读取出来 */
uint16_t content[maxWriteResAddrLen] = {0}; uint16_t content[maxWriteResAddrLen] = {0};
for (uint16_t var = 0; var < Register_Number; var++) { for (uint16_t var = 0; var < Register_Number; var++) {
content[var] = gw485RxBuffer[7 + 2 * var] << 8 | gw485RxBuffer[7 + 2 * var + 1]; content[var] = gw485RxBuffer[14 + 2 * var] << 8 | gw485RxBuffer[14 + 2 * var + 1];
} }
/* 将数据写入到寄存器中 */ /* 将数据写入到寄存器中 */

View File

@ -28,6 +28,5 @@ void writePwrCtrlState(uint8_t type, uint8_t State);
uint8_t readPwrCtrlState(uint8_t type); uint8_t readPwrCtrlState(uint8_t type);
void startResetAndroidModule(void); void startResetAndroidModule(void);
void stopResetAndroidModule(void); void stopResetAndroidModule(void);
void ledToggle(void);
#endif #endif

View File

@ -106,14 +106,3 @@ void stopResetAndroidModule(void)
{ {
HD_GPIO_Write(GPIO_PwrKey_GPIO_PROT, GPIO_PwrKey_GPIO_PIN, GPIO_RESET); HD_GPIO_Write(GPIO_PwrKey_GPIO_PROT, GPIO_PwrKey_GPIO_PIN, GPIO_RESET);
} }
/**
* @brief ·­×ªLEDµÆµçƽ
* @param
* @retval
*/
void ledToggle(void)
{
HD_GPIO_Write(LED_GPIO_PROT, LED_GPIO_PIN
, !(HD_OutputGPIO_Read(LED_GPIO_PROT, LED_GPIO_PIN)));
}

View File

@ -876,7 +876,7 @@ void setBUSIDLEFlag(device_handle device, uint8_t state)
// } // }
// } // }
if (state != 0 && state != 1) { if (state != 0 || state != 1) {
return; return;
} }

View File

@ -35,10 +35,6 @@
#define WDI_GPIO_PROT GPIOC #define WDI_GPIO_PROT GPIOC
#define WDI_GPIO_PIN GPIO_Pin_13 #define WDI_GPIO_PIN GPIO_Pin_13
/* LED多신 */
#define LED_GPIO_PROT GPIOB
#define LED_GPIO_PIN GPIO_Pin_8
#define GPIOTypeDef GPIO_TypeDef #define GPIOTypeDef GPIO_TypeDef
#define GPIOPin uint16_t #define GPIOPin uint16_t
@ -55,5 +51,4 @@ void HD_GPIO_Write(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin, BitOperation BitVal);
uint8_t HD_InputGPIO_Read(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin); uint8_t HD_InputGPIO_Read(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin);
uint8_t HD_OutputGPIO_Read(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin); uint8_t HD_OutputGPIO_Read(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin);
#endif #endif

View File

@ -58,12 +58,6 @@ void HD_GPIO_Init(void)
GPIO_InitStructure.GPIO_Pin = WDI_GPIO_PIN; GPIO_InitStructure.GPIO_Pin = WDI_GPIO_PIN;
GPIO_Init(WDI_GPIO_PROT, &GPIO_InitStructure); GPIO_Init(WDI_GPIO_PROT, &GPIO_InitStructure);
GPIO_WriteBit(WDI_GPIO_PROT, WDI_GPIO_PIN, Bit_SET); GPIO_WriteBit(WDI_GPIO_PROT, WDI_GPIO_PIN, Bit_SET);
/* LEDÒý½Å */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = LED_GPIO_PIN;
GPIO_Init(LED_GPIO_PROT, &GPIO_InitStructure);
GPIO_WriteBit(LED_GPIO_PROT, LED_GPIO_PIN, Bit_SET);
} }
/** /**

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -117,22 +117,3 @@ uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
## 测试指令
#### 查询端口0电源数据
>53 4C 00 00 11 53 4C 11 11 11 11 11 11 11 30 01 00 00 0C 23 68 16 17
#### 查询端口1倾角传感器数据
> 53 4C 01 00 09 4A 59 09 00 02 01 01 05 b5 17
#### 打开端口1电源
>47 57 10 00 03 00 01 00 01 18 9C 16
#### 查看端口1电源
>47 57 30 00 03 00 01 27 50 16