|
|
|
|
@ -4,10 +4,10 @@
|
|
|
|
|
#include "Relays.h"
|
|
|
|
|
#include "myfreertos.h"
|
|
|
|
|
|
|
|
|
|
u8 prev_sendbuf[41] = {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, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 sendbuf[41] = {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, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 prev_sendbuf[49] = {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, 0xFF, 0xFC, 0xFF, 0xFF};
|
|
|
|
|
u8 sendbuf[49] = {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, 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];
|
|
|
|
|
@ -384,10 +384,10 @@ void RS485_1_Send_Data_2(void)
|
|
|
|
|
sendbuf[1] = 0xB5;
|
|
|
|
|
sendbuf[2] = 0x05;
|
|
|
|
|
|
|
|
|
|
sendbuf[37] = 0xFF;
|
|
|
|
|
sendbuf[38] = 0xFC;
|
|
|
|
|
sendbuf[39] = 0xFF;
|
|
|
|
|
sendbuf[40] = 0xFF;
|
|
|
|
|
sendbuf[45] = 0xFF;
|
|
|
|
|
sendbuf[46] = 0xFC;
|
|
|
|
|
sendbuf[47] = 0xFF;
|
|
|
|
|
sendbuf[48] = 0xFF;
|
|
|
|
|
// u8 a;
|
|
|
|
|
if (T <= 1000 && T >= -1000)
|
|
|
|
|
{
|
|
|
|
|
@ -430,87 +430,60 @@ void RS485_1_Send_Data_2(void)
|
|
|
|
|
sendbuf[10] = blue_light2;
|
|
|
|
|
sendbuf[11] = white_light1;
|
|
|
|
|
sendbuf[12] = white_light2;
|
|
|
|
|
if (C <= 5000)
|
|
|
|
|
{
|
|
|
|
|
CO2_1 = (C & 0xFF00) >> 8;
|
|
|
|
|
CO2_1 = C & 0x00FF;
|
|
|
|
|
}
|
|
|
|
|
sendbuf[13] = CO2_1;
|
|
|
|
|
sendbuf[14] = CO2_2;
|
|
|
|
|
if (now_stage > 0 && now_stage < 7 && total[3 + 18 * (now_stage - 1)] < 24 && total[4 + 18 * (now_stage - 1)] < 60 && chour < 24 && cminute < 60)
|
|
|
|
|
{
|
|
|
|
|
sendbuf[15] = now_stage; // current state
|
|
|
|
|
sendbuf[16] = total[3 + 18 * (now_stage - 1)]; // stage hour
|
|
|
|
|
sendbuf[17] = total[4 + 18 * (now_stage - 1)]; // stage minute
|
|
|
|
|
sendbuf[18] = chour; // run hour
|
|
|
|
|
sendbuf[19] = cminute; // run minute
|
|
|
|
|
}
|
|
|
|
|
// now_stage = 1;
|
|
|
|
|
sendbuf[15] = now_stage; // current state
|
|
|
|
|
sendbuf[16] = total[3 + 18 * (now_stage - 1)]; // stage hour
|
|
|
|
|
sendbuf[17] = total[4 + 18 * (now_stage - 1)]; // stage minute
|
|
|
|
|
sendbuf[18] = chour; // run hour
|
|
|
|
|
sendbuf[19] = cminute; // run minute
|
|
|
|
|
sendbuf[20] = hot_clod_flag; // hot clod state
|
|
|
|
|
sendbuf[21] = humidity_flag; // humidity state
|
|
|
|
|
sendbuf[22] = ALARM; // ALARM state
|
|
|
|
|
|
|
|
|
|
// sendbuf[23] = (int)pid.Kp / 256; // Kp 110
|
|
|
|
|
// sendbuf[24] = (int)pid.Kp % 256; // Kp 110
|
|
|
|
|
// sendbuf[25] = ((int)(pid.Ki * 100000)) / 256; // Ti 0.001
|
|
|
|
|
// sendbuf[26] = ((int)(pid.Ki * 100000)) % 256; // Ti 0.001
|
|
|
|
|
// sendbuf[27] = (int)pid.Kd / 256; // Td 340
|
|
|
|
|
// sendbuf[28] = (int)pid.Kd % 256; // Td 340
|
|
|
|
|
|
|
|
|
|
// TODO::temp
|
|
|
|
|
sendbuf[23] = (int)(-pid.SEk) / 256; // SEk
|
|
|
|
|
sendbuf[24] = (int)(-pid.SEk) % 256;
|
|
|
|
|
sendbuf[25] = (int)pid.Ki / 256; // compressor speed
|
|
|
|
|
sendbuf[26] = (int)pid.Ki % 256;
|
|
|
|
|
sendbuf[27] = (int)pid.Kd / 256; // heater percent
|
|
|
|
|
sendbuf[28] = (int)pid.Kd % 256;
|
|
|
|
|
|
|
|
|
|
// num = (((pid.OUT * 350) / pid.pwmcycle) - 1);
|
|
|
|
|
|
|
|
|
|
int out1 = pid.OUT;
|
|
|
|
|
// speed count
|
|
|
|
|
int speed_count = out1 / 200.0 * (6000 - 1500) + 1500;
|
|
|
|
|
if (speed_count > 6000)
|
|
|
|
|
{
|
|
|
|
|
speed_count = 6000;
|
|
|
|
|
}
|
|
|
|
|
sendbuf[29] = (speed_count) / 256;
|
|
|
|
|
sendbuf[30] = (speed_count) % 256;
|
|
|
|
|
// sendbuf[29] = ((int)(pid.OUT * 1000)) / 256;
|
|
|
|
|
// sendbuf[30] = ((int)(pid.OUT * 1000)) % 256;
|
|
|
|
|
// if (C <= 5000)
|
|
|
|
|
// {
|
|
|
|
|
// CO2_1 = (C & 0xFF00) >> 8;
|
|
|
|
|
// CO2_1 = C & 0x00FF;
|
|
|
|
|
// }
|
|
|
|
|
sendbuf[13] = (C & 0xFF00) >> 8;
|
|
|
|
|
sendbuf[14] = C & 0x00FF;
|
|
|
|
|
sendbuf[15] = 0; // current state
|
|
|
|
|
sendbuf[16] = now_stage; // current state
|
|
|
|
|
sendbuf[17] = total[3 + 18 * (now_stage - 1)]; // stage hour
|
|
|
|
|
sendbuf[18] = total[4 + 18 * (now_stage - 1)]; // stage minute
|
|
|
|
|
sendbuf[19] = chour; // run hour
|
|
|
|
|
sendbuf[20] = cminute; // run minute
|
|
|
|
|
sendbuf[21] = 0; // hot clod state
|
|
|
|
|
sendbuf[22] = hot_clod_flag; // hot clod state
|
|
|
|
|
sendbuf[23] = 0; // humidity state
|
|
|
|
|
sendbuf[24] = humidity_flag; // humidity state
|
|
|
|
|
sendbuf[25] = 0; // ALARM state
|
|
|
|
|
sendbuf[26] = ALARM; // ALARM state
|
|
|
|
|
|
|
|
|
|
sendbuf[27] = (int)pid.hp / 256; // Kp 110
|
|
|
|
|
sendbuf[28] = (int)pid.hp % 256; // Kp 110
|
|
|
|
|
sendbuf[29] = ((int)(pid.hi * 100000)) / 256; // Ti 0.001
|
|
|
|
|
sendbuf[30] = ((int)(pid.hi * 100000)) % 256; // Ti 0.001
|
|
|
|
|
sendbuf[31] = (int)pid.hd / 256; // Td 340
|
|
|
|
|
sendbuf[32] = (int)pid.hd % 256; // Td 340
|
|
|
|
|
sendbuf[33] = pid.h_percent / 256; // h_percent
|
|
|
|
|
sendbuf[34] = pid.h_percent % 256; // h_percent
|
|
|
|
|
|
|
|
|
|
sendbuf[35] = (int)pid.cp / 256; // Kp 110
|
|
|
|
|
sendbuf[36] = (int)pid.cp % 256; // Kp 110
|
|
|
|
|
sendbuf[37] = ((int)(pid.ci * 100000)) / 256; // Ti 0.001
|
|
|
|
|
sendbuf[38] = ((int)(pid.ci * 100000)) % 256; // Ti 0.001
|
|
|
|
|
sendbuf[39] = (int)pid.cd / 256; // Td 340
|
|
|
|
|
sendbuf[40] = (int)pid.cd % 256; // Td 340
|
|
|
|
|
sendbuf[41] = pid.c_speed / 256; // h_percent
|
|
|
|
|
sendbuf[42] = pid.c_speed % 256; // h_percent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bufcut_Init(sendbuf_crc, sendbuf, 3, 31);
|
|
|
|
|
// GetCRC16(sendbuf_crc, 28, &crc_num1, &crc_num2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tem_offset_10times = (int)(pid.tem_offset * 10);
|
|
|
|
|
|
|
|
|
|
if (tem_offset_10times < 0) {
|
|
|
|
|
tem_offset_10times = (~(tem_offset_10times - 1)) & 0xFFFF;
|
|
|
|
|
}
|
|
|
|
|
sendbuf[31] = tem_offset_10times / 256; // tem offset
|
|
|
|
|
sendbuf[32] = tem_offset_10times % 256;
|
|
|
|
|
|
|
|
|
|
sendbuf[33] = ((int)(pid.tem_threshold * 10)) / 256; // tem threshold
|
|
|
|
|
sendbuf[34] = ((int)(pid.tem_threshold * 10)) % 256;
|
|
|
|
|
|
|
|
|
|
GetCRC16(sendbuf, 35, &crc_num1, &crc_num2);
|
|
|
|
|
sendbuf[35] = crc_num1;
|
|
|
|
|
sendbuf[36] = crc_num2;
|
|
|
|
|
GetCRC16(sendbuf, 43, &crc_num1, &crc_num2);
|
|
|
|
|
sendbuf[43] = crc_num1;
|
|
|
|
|
sendbuf[44] = 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, 41) != 0) {
|
|
|
|
|
if (cmp_str(prev_sendbuf, sendbuf, 49) != 0) {
|
|
|
|
|
|
|
|
|
|
RS485_1_Send_Data(sendbuf, 41);
|
|
|
|
|
RS485_1_Send_Data(sendbuf, 49);
|
|
|
|
|
|
|
|
|
|
cp_str_to_prev(prev_sendbuf, sendbuf, 41);
|
|
|
|
|
cp_str_to_prev(prev_sendbuf, sendbuf, 49);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|