适配新的通讯协议,取消不必要的 FF FC FF FF 后缀,优化pid相关逻辑

main
Zeng wei (曾威) 2 years ago
parent 3f6147d846
commit d0ede9ebe2

@ -137,11 +137,11 @@ void PID_Calc() // pid calc
rs485speed[4] = speed_count / 256;
rs485speed[5] = speed_count % 256;
RS485_3_Init(9600);
// RS485_3_Init(9600);
delay_xms(100);
RS485_3_Send_Data(rs485speed, 8);
// RS485_1_Send_Data_1(rs485speed, 8);
// RS485_3_Send_Data(rs485speed, 8);
RS485_1_Send_Data_1(rs485speed, 8);
delay_xms(200);
RS485_1_Init(9600);
// RS485_1_Init(9600);
// HC595_Send_Byte(gpio_state&=0xDB);// close compressor and heater &=1101 1011 0xDB
}

@ -480,12 +480,12 @@ void RS485_1_Send_Data_2(void)
sendbuf[32] = crc_num2;
// only when modify happen, then send
if (cmp_str(prev_sendbuf, sendbuf, 37) != 0) {
//if (cmp_str(prev_sendbuf, sendbuf, 37) != 0) {
RS485_1_Send_Data(sendbuf, 37);
cp_str_to_prev(prev_sendbuf, sendbuf, 37);
}
//}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -47,6 +47,8 @@ void SyncEnvironmentDataRequestTask(void *pvParameters);
int isZeros(u8 arr[]);
u8 RS485_RX_BUF_COPY[128] = {0};
u8 RS485_DATA_TMP[128] = {0};
u8 RS485_SUFFIX[4] = {0xFF, 0xFC, 0xFF, 0xFF};
u8 cnt_flag = 0, sub_flag = 0, pub_flag = 0;
u16 time = 0; // Record the time of pinging the server
char wet_temp[256]; // Cache area for subscription and publication of messages
@ -238,7 +240,6 @@ void Sensor_Communication_task(void *pvParameters)
if (RS485_RX_BUF_COPY[0] == 0x02 && RS485_RX_BUF_COPY[1] == 0x03 && CRC16_check(RS485_RX_BUF_COPY, 21) == 1)
{
// receive message from sensor
u8 temp_data[23] = {0};
for (int i=0;i<23;i++) {
temp_data[i] = RS485_RX_BUF_COPY[i];
@ -249,41 +250,52 @@ void Sensor_Communication_task(void *pvParameters)
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x01)
{
// batch update params in a stage
// total length: 22
// total length: 18
if (CRC16_check(RS485_RX_BUF_COPY, 16) == 1) {
Batch_synchronization(&n, RS485_RX_BUF_COPY);
Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // update param correspond to current stage
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 18);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 18, 22);
// RS485_1_Send_Data_1(RS485_DATA_TMP, 22);
}
RX_BUF_Transfer(0, 22);
RX_BUF_Transfer(0, 18);
}
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x03)
{
// update single environment param
// total length: 13
// total length: 9
if (CRC16_check(RS485_RX_BUF_COPY, 7) == 1) {
Analysis(&n, &i, RS485_RX_BUF_COPY);
Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // update param correspond to current stage
Write_Init();
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 9);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 9, 13);
RS485_1_Send_Data_1(RS485_DATA_TMP, 13);
}
RX_BUF_Transfer(0, 13);
RX_BUF_Transfer(0, 9);
}
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x04)
{
// change running stage
// total length: 10
// total length: 6
if (CRC16_check(RS485_RX_BUF_COPY, 4) == 1) {
int target_stage = RS485_RX_BUF_COPY[3];
RTC_synchronization_ins(2023, 9, 1, 0, 00, 00);
now_stage = target_stage;
store_stage = target_stage;
Write_Init();
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 6);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 6, 10);
RS485_1_Send_Data_1(RS485_DATA_TMP, 10);
delay_ms(10);
RS485_1_Send_Data_2(); // 上传参数
}
RX_BUF_Transfer(0, 10);
RX_BUF_Transfer(0, 6);
}
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x05)
{
// change pid params
// total length: 12
// total length: 8
if (CRC16_check(RS485_RX_BUF_COPY, 6) == 1) {
int param_index = RS485_RX_BUF_COPY[3];
switch(param_index) {
@ -304,8 +316,11 @@ void Sensor_Communication_task(void *pvParameters)
}
}
Write_Init();
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 8);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 8, 12);
RS485_1_Send_Data_1(RS485_DATA_TMP, 12);
}
RX_BUF_Transfer(0, 12);
RX_BUF_Transfer(0, 8);
}
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB1 && RS485_RX_BUF_COPY[2] == 0x11 && RS485_RX_BUF_COPY[15] == 0xFF && RS485_RX_BUF[16] == 0xFF)
{
@ -393,7 +408,7 @@ void process_sensor_data(u8 *data) {
diff = current_T - T;
if (diff < 0)
diff = -diff;
if (diff < 3 || current_T == 0) // 最近两次温差相差0.3℃,消除传感器感应出错的影响
if (diff < 100 || current_T == 0) // 最近两次温差相差10℃,消除传感器感应出错的影响
{
pid.set_tem = tem / 10.0;
pid.now_tem = T / 10.0;
@ -462,6 +477,8 @@ void process_hmi_btn_event(u8 page, u8 btn_index, u8 value) {
now_stage = target_stage;
store_stage = target_stage;
Write_Init();
delay_ms(10);
RS485_1_Send_Data_2(); // 上传参数
}
break;
}

Loading…
Cancel
Save