|
gizwits_cloud_receive(const unsigned char *pdata, unsigned short length)
{
// Get device status
if (length == 1 && pdata[0] == 0x02)
{
uint8 mcu_data[6];
mcu_data[0] = 0x03;
mcu_status_t * mcu_status;
mcu_status = (mcu_status_t *)(&mcu_data[1]);
mcu_status->on_off = local_mcu_status.on_off;
mcu_status->temperature = local_mcu_status.temperature;
mcu_status->mode = local_mcu_status.mode;
mcu_status->brightness = local_mcu_status.brightness;
mcu_status->color_r = local_mcu_status.color_r;
mcu_status->color_g = local_mcu_status.color_g;
mcu_status->color_b = local_mcu_status.color_b;
gizwits_cloud_send(mcu_data, sizeof(mcu_data) / sizeof(uint8));
gizwits_lan_tcp_server_dev2app(mcu_data, sizeof(mcu_data) / sizeof(uint8));
}
else if (length == 7 && pdata[0] == 0x01)
{
// attr_flags indicate that the corresponding bit is effective, 1 means effective, while 0 means not
// effective.From right to left order:
// bit0: settingSwitch
// bit1: settingC_Temperature
// bit2: settingmode
// bit3: settingBrightness
// bit4: settingColor_R
// bit5: settingColor_G
// bit6: settingColor_B
mcu_attr_flags_t *mcu_attr_flags = (mcu_attr_flags_t *)(&pdata[1]);
mcu_status_t * mcu_status;
mcu_status = (mcu_status_t *)(&pdata[2]);
if (mcu_attr_flags->setting_on_off)
{
local_mcu_status.on_off = mcu_status->on_off;
os_printf("setting_on_off:%d\r\n", mcu_status->on_off);
}
if (mcu_attr_flags->setting_temperature)
{
local_mcu_status.temperature = mcu_status->temperature;
os_printf("setting_temperature:%d\r\n", mcu_status->temperature);
}
if (mcu_attr_flags->setting_mode)
{
local_mcu_status.mode = mcu_status->mode;
os_printf("setting_mode:%d\r\n", mcu_status->mode);
}
if (mcu_attr_flags->setting_brightness)
{
local_mcu_status.brightness = mcu_status->brightness;
os_printf("setting_brightness:%d\r\n", mcu_status->brightness);
}
if (mcu_attr_flags->setting_color_r)
{
local_mcu_status.color_r = mcu_status->color_r;
os_printf("setting_color_r:%d\r\n", mcu_status->color_r);
}
if (mcu_attr_flags->setting_color_g)
{
local_mcu_status.color_g = mcu_status->color_g;
os_printf("setting_color_g:%d\r\n", mcu_status->color_g);
}
if (mcu_attr_flags->setting_color_b)
{
local_mcu_status.color_b = mcu_status->color_b;
os_printf("setting_color_b:%d\r\n", mcu_status->color_b);
}
gizwits_app_apply_settings();
gizwits_app_save();
uint8 mcu_data[6];
mcu_data[0] = 0x03;
mcu_status = (mcu_status_t *)(&mcu_data[1]);
mcu_status->on_off = local_mcu_status.on_off;
mcu_status->temperature = local_mcu_status.temperature;
mcu_status->mode = local_mcu_status.mode;
mcu_status->brightness = local_mcu_status.brightness;
mcu_status->color_r = local_mcu_status.color_r;
mcu_status->color_g = local_mcu_status.color_g;
mcu_status->color_b = local_mcu_status.color_b;
gizwits_lan_tcp_server_dev2app(mcu_data, sizeof(mcu_data) / sizeof(uint8));
}
}
谁能帮忙解释一下这段代码?开发板是安信可公司的机智云开发板
|
|