|
|
|
|
@ -33,6 +33,10 @@ void Host_Computer_Communication(void);
|
|
|
|
|
// 60seconds delay
|
|
|
|
|
#define SYNC_ENVIRONMENT_DATA_REQUEST_PERIOD pdMS_TO_TICKS(60000)
|
|
|
|
|
|
|
|
|
|
// 2seconds delay
|
|
|
|
|
#define MAIN_TASK_PERIOD pdMS_TO_TICKS(1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sensor data request: 02 03
|
|
|
|
|
*/
|
|
|
|
|
@ -215,37 +219,17 @@ void Sensor_Communication_task(void *pvParameters)
|
|
|
|
|
// time=0;
|
|
|
|
|
// pingMqtt(MQTT_SOCK);
|
|
|
|
|
// }
|
|
|
|
|
now_stage = timelong_Compare(); //
|
|
|
|
|
// printf("%d %d\r\n",chour,cminute);
|
|
|
|
|
now_stage = timelong_Compare();
|
|
|
|
|
Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // ¸üжÔÓ¦½×¶ÎºÅµÄ²ÎÊý
|
|
|
|
|
// printf("current stage: %d\r\n",now_stage);
|
|
|
|
|
|
|
|
|
|
// RS485_1_Send_Data_1(rs485buf, 8); //(RS485_RX_CNT=0Òѱ»×¢ÊÍ)
|
|
|
|
|
// delay_xms(50);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // RX_BUF_Printf(128);
|
|
|
|
|
// if (sync_cnt <= 0)
|
|
|
|
|
// {
|
|
|
|
|
// RS485_1_Send_Data_3();
|
|
|
|
|
// sync_cnt = 10;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// sync_cnt--;
|
|
|
|
|
// }
|
|
|
|
|
delay_xms(50);
|
|
|
|
|
// RX_BUF_Printf(128);
|
|
|
|
|
// if (RS485_RX_CNT == 0) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
bufcut_Init(RS485_RX_BUF_COPY, RS485_RX_BUF, 0, 128);
|
|
|
|
|
u8 c = 0;
|
|
|
|
|
RS485_RX_CNT = 0;
|
|
|
|
|
while (isAllZeros(RS485_RX_BUF_COPY, 128) == 0)
|
|
|
|
|
// while (RS485_RX_CNT > 0)
|
|
|
|
|
{
|
|
|
|
|
// bufcut_Init(RS485_RX_BUF_COPY, RS485_RX_BUF, 0, 128);
|
|
|
|
|
{
|
|
|
|
|
if (RS485_RX_BUF_COPY[0] == 0x02 && RS485_RX_BUF_COPY[1] == 0x03 && CRC16_check(RS485_RX_BUF_COPY, 21) == 1)
|
|
|
|
|
{
|
|
|
|
|
c++;
|
|
|
|
|
@ -267,8 +251,12 @@ void Sensor_Communication_task(void *pvParameters)
|
|
|
|
|
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);
|
|
|
|
|
RS485_DATA_TMP[18] = 0xFF;
|
|
|
|
|
RS485_DATA_TMP[19] = 0xFC;
|
|
|
|
|
RS485_DATA_TMP[20] = 0xFF;
|
|
|
|
|
RS485_DATA_TMP[21] = 0xFF;
|
|
|
|
|
// bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 18, 22);
|
|
|
|
|
RS485_1_Send_Data_1(RS485_DATA_TMP, 22);
|
|
|
|
|
// }
|
|
|
|
|
RX_BUF_Transfer(0, 18);
|
|
|
|
|
}
|
|
|
|
|
@ -344,7 +332,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);
|
|
|
|
|
// bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 8, 12);
|
|
|
|
|
RS485_DATA_TMP[8] = 0xFF;
|
|
|
|
|
RS485_DATA_TMP[9] = 0xFC;
|
|
|
|
|
RS485_DATA_TMP[10] = 0xFF;
|
|
|
|
|
RS485_DATA_TMP[11] = 0xFF;
|
|
|
|
|
RS485_1_Send_Data_1(RS485_DATA_TMP, 12);
|
|
|
|
|
RX_BUF_Transfer(0, 8);
|
|
|
|
|
}
|
|
|
|
|
@ -382,16 +374,16 @@ void Sensor_Communication_task(void *pvParameters)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (red <= 1000 && blue <= 1000)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
PWM_SetCompare1((red / 100.0 * 3.5 + 28)); // J9
|
|
|
|
|
PWM_SetCompare2((blue / 100.0 * 3.5 + 28)); // J11
|
|
|
|
|
PWM_SetCompare4((white / 100.0 * 3.5 + 28)); // J10
|
|
|
|
|
}
|
|
|
|
|
// if (red <= 1000 && blue <= 1000)
|
|
|
|
|
// {
|
|
|
|
|
// PWM_SetCompare1((red / 100.0 * 3.5 + 28)); // J9
|
|
|
|
|
// PWM_SetCompare2((blue / 100.0 * 3.5 + 28)); // J11
|
|
|
|
|
// PWM_SetCompare4((white / 100.0 * 3.5 + 28)); // J10
|
|
|
|
|
// }
|
|
|
|
|
RS485_RX_CNT = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vTaskDelay(MAIN_TASK_PERIOD);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|