|
|
|
|
@ -4,10 +4,10 @@
|
|
|
|
|
#include "Relays.h"
|
|
|
|
|
#include "myfreertos.h"
|
|
|
|
|
|
|
|
|
|
u8 prev_sendbuf[53] = {0xEE, 0xB5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 sendbuf[53] = {0xEE, 0xB5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 prev_sendbuf[62] = {0xEE, 0xB5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 sendbuf[62] = {0xEE, 0xB5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 sendbuf_crc[20] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
|
extern u8 global_buffer[64];
|
|
|
|
|
@ -48,6 +48,7 @@ extern int T;
|
|
|
|
|
extern int H;
|
|
|
|
|
extern int C;
|
|
|
|
|
extern PID pid;
|
|
|
|
|
extern u8 lights[9];
|
|
|
|
|
// extern u16 RED_LIGHT;
|
|
|
|
|
// extern u16 WHITE_LIGHT;
|
|
|
|
|
// extern u16 BLUE_LIGHT;
|
|
|
|
|
@ -280,7 +281,7 @@ void RS485_2_Init(u32 bound)
|
|
|
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
|
|
|
|
|
|
|
|
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
|
|
|
|
USART_Cmd(USART1, ENABLE);
|
|
|
|
|
USART_Cmd(USART1, ENABLE);
|
|
|
|
|
|
|
|
|
|
RS485_2_TX_EN = 0;
|
|
|
|
|
}
|
|
|
|
|
@ -356,11 +357,33 @@ void RS485_1_Send_Data(u8 *buf, u8 len)
|
|
|
|
|
|
|
|
|
|
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
|
|
|
|
|
;
|
|
|
|
|
// RS485_RX_CNT = 0;
|
|
|
|
|
|
|
|
|
|
RS485_1_TX_EN = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* send data to Serial 2
|
|
|
|
|
*/
|
|
|
|
|
void RS485_2_Send_Data(u8 *buf, u8 len)
|
|
|
|
|
{
|
|
|
|
|
u8 t;
|
|
|
|
|
|
|
|
|
|
RS485_2_TX_EN = 1;
|
|
|
|
|
|
|
|
|
|
for (t = 0; t < len; t++)
|
|
|
|
|
{
|
|
|
|
|
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
|
|
|
|
|
;
|
|
|
|
|
USART_SendData(USART1, buf[t]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
|
|
|
|
|
;
|
|
|
|
|
// RS485_RX_CNT = 0;
|
|
|
|
|
|
|
|
|
|
RS485_2_TX_EN = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RS485_1_Send_Data_1(u8 *buf, u8 len)
|
|
|
|
|
{
|
|
|
|
|
u8 t;
|
|
|
|
|
@ -394,10 +417,10 @@ void RS485_1_Upload_Params(void)
|
|
|
|
|
sendbuf[1] = 0xB5;
|
|
|
|
|
sendbuf[2] = 0x05;
|
|
|
|
|
|
|
|
|
|
sendbuf[49] = 0xFF;
|
|
|
|
|
sendbuf[50] = 0xFC;
|
|
|
|
|
sendbuf[51] = 0xFF;
|
|
|
|
|
sendbuf[52] = 0xFF;
|
|
|
|
|
sendbuf[58] = 0xFF;
|
|
|
|
|
sendbuf[59] = 0xFC;
|
|
|
|
|
sendbuf[60] = 0xFF;
|
|
|
|
|
sendbuf[61] = 0xFF;
|
|
|
|
|
|
|
|
|
|
if (T <= 1000 && T >= -1000)
|
|
|
|
|
{
|
|
|
|
|
@ -501,23 +524,27 @@ void RS485_1_Upload_Params(void)
|
|
|
|
|
sendbuf[44] = (int)(pid.out_tem * 10) % 256;
|
|
|
|
|
sendbuf[45] = (int)(pid.out_humidity * 10) / 256;
|
|
|
|
|
sendbuf[46] = (int)(pid.out_humidity * 10) % 256;
|
|
|
|
|
// light
|
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
|
sendbuf[47 + i] = lights[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bufcut_Init(sendbuf_crc, sendbuf, 3, 31);
|
|
|
|
|
// GetCRC16(sendbuf_crc, 28, &crc_num1, &crc_num2);
|
|
|
|
|
|
|
|
|
|
GetCRC16(sendbuf, 47, &crc_num1, &crc_num2);
|
|
|
|
|
sendbuf[47] = crc_num1;
|
|
|
|
|
sendbuf[48] = crc_num2;
|
|
|
|
|
GetCRC16(sendbuf, 56, &crc_num1, &crc_num2);
|
|
|
|
|
sendbuf[56] = crc_num1;
|
|
|
|
|
sendbuf[57] = crc_num2;
|
|
|
|
|
|
|
|
|
|
// u8 tmpabc[] = {0xAA, 0xBB, 0xCC};
|
|
|
|
|
// RS485_1_Send_Data(tmpabc, 3);
|
|
|
|
|
// only when modify happen, then send
|
|
|
|
|
// if (cmp_str(prev_sendbuf, sendbuf, 49) != 0) {
|
|
|
|
|
|
|
|
|
|
RS485_1_Send_Data(sendbuf, 53);
|
|
|
|
|
RS485_1_Send_Data(sendbuf, 62);
|
|
|
|
|
vTaskDelay(100);
|
|
|
|
|
cp_str_to_prev(prev_sendbuf, sendbuf, 53);
|
|
|
|
|
cp_str_to_prev(prev_sendbuf, sendbuf, 62);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|