#define TASK1_STK_SIZE 1024void task1(void *arg);osThreadDef(task1, osPriorityNormal, 1, TASK1_STK_SIZE);#define TASK2_STK_SIZE 1024void task2(void *arg);osThreadDef(task2, osPriorityNormal, 1, TASK2_STK_SIZE);#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u#define TASK3_STK_SIZE 512void task3(void *arg);#endifvoid task1(void *arg){#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u osThreadId task_dyn_created; osThreadDynamicDef(task3, osPriorityNormal, 1, TASK3_STK_SIZE); task_dyn_created = osThreadCreate(osThread(task3), NULL);int count = 0;#endifwhile (1) {printf("###I am task1\r\n"); osDelay(2000);#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0uif (count++ == 3) {printf("###I am task1, kill the task3(dynamic created)\r\n"); osThreadTerminate(task_dyn_created); }#endif }}void task2(void *arg){while (1) {#if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0uk_err_t rc;int depth; rc = tos_task_stack_draught_depth(K_NULL, &depth);printf("%d %d\n", rc, depth);#endifprintf("***I am task2\r\n"); osDelay(1000); }}#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0uvoid task3(void *arg){while (1) {printf("$I am task3(dynamic created)\r\n"); osDelay(2000); }}#endifvoid application_entry(void *arg){printf("***I am task\r\n"); osThreadCreate(osThread(task1), NULL); // Create task1 osThreadCreate(osThread(task2), NULL); // Create task2}
{
"version": "1.0",
"properties": [
{
"id": "power_switch",
"name": "电灯开关",
"desc": "控制电灯开灭",
"required": true,
"mode": "rw",
"define": {
"type": "bool",
"mapping": {
"0": "关",
"1": "开"
}
}
},
{
"id": "brightness",
"name": "亮度",
"desc": "灯光亮度",
"mode": "rw",
"define": {
"type": "int",
"unit": "%",
"step": "1",
"min": "0",
"max": "100",
"start": "1"
}
},
{
"id": "color",
"name": "颜色",
"desc": "灯光颜色",
"mode": "rw",
"define": {
"type": "enum",
"mapping": {
"0": "Red",
"1": "Green",
"2": "Blue"
}
}
},
{
"id": "color_temp",
"name": "色温",
"desc": "灯光冷暖",
"mode": "rw",
"define": {
"type": "int",
"min": "0",
"max": "100",
"start": "0",
"step": "10",
"unit": "%"
}
},
{
"id": "name",
"name": "灯位置名称",
"desc": "灯位置名称:书房、客厅等",
"mode": "rw",
"required": false,
"define": {
"type": "string",
"min": "0",
"max": "64"
}
}
],
"events": [
{
"id": "status_report",
"name": "DeviceStatus",
"desc": "Report the device status",
"type": "info",
"required": false,
"params": [
{
"id": "status",
"name": "running_state",
"desc": "Report current device running state",
"define": {
"type": "bool",
"mapping": {
"0": "normal",
"1": "fault"
}
}
},
{
"id": "message",
"name": "Message",
"desc": "Some extra message",
"define": {
"type": "string",
"min": "0",
"max": "64"
}
}
]
},
{
"id": "low_voltage",
"name": "LowVoltage",
"desc": "Alert for device voltage is low",
"type": "alert",
"required": false,
"params": [
{
"id": "voltage",
"name": "Voltage",
"desc": "Current voltage",
"define": {
"type": "float",
"unit": "V",
"step": "1",
"min": "0.0",
"max": "24.0",
"start": "1"
}
}
]
},
{
"id": "hardware_fault",
"name": "Hardware_fault",
"desc": "Report hardware fault",
"type": "fault",
"required": false,
"params": [
{
"id": "name",
"name": "Name",
"desc": "Name like: memory,tf card, censors ...",
"define": {
"type": "string",
"min": "0",
"max": "64"
}
},
{
"id": "error_code",
"name": "Error_Code",
"desc": "Error code for fault",
"define": {
"type": "int",
"unit": "",
"step": "1",
"min": "0",
"max": "2000",
"start": "1"
}
}
]
}
],
"actions": [
{
"id": "light_blink",
"name": "行为测试",
"desc": "",
"input": [
{
"id": "time",
"name": "time",
"define": {
"type": "int",
"min": "0",
"max": "100",
"start": "0",
"step": "1",
"unit": ""
}
},
{
"id": "color",
"name": "color",
"define": {
"type": "enum",
"mapping": {
"0": "red",
"1": "yellow"
}
}
},
{
"id": "total_time",
"name": "total_time",
"define": {
"type": "int",
"min": "0",
"max": "100",
"start": "100",
"step": "1",
"unit": ""
}
},
{
"id": "switch",
"name": "switch",
"define": {
"type": "bool",
"mapping": {
"0": "关",
"1": "开"
}
}
}
],
"output": [
{
"id": "err_code",
"name": "err_code",
"define": {
"type": "bool",
"mapping": {
"0": "ok",
"1": "error"
}
}
}
],
"required": false
}
],
"profile": {
"ProductId": "4JE4PTXVC7",
"CategoryId": "141"
}
}
D:\TencentOS-tiny\board\TencentOS_tiny_EVB_MX_Plus\KEIL\qcloud_iot_explorer_sdk_data_template
static void light_change_brightness(TYPE_DEF_TEMPLATE_INT brightness)
{
// 作为demo,这里用oled屏字符显示来模拟灯颜色的切换
// 这里应该由用户实现硬件操作代码,来改变智能灯的颜色
// 此处demo,在开发板显示屏上显示具体的颜色
char brightness_str[12];
snprintf(brightness_str, sizeof(brightness_str), "%d", brightness);
brightness_str[sizeof(brightness_str) - 1] = '\0';
OLED_ShowString(0, 2, (uint8_t *)brightness_str, 8);
}
static void light_power_on(void)
{
// 作为demo,这里用oled屏字符显示来模拟灯颜色的切换
OLED_Clear();
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9, GPIO_PIN_SET);
}
static void light_power_off(void)
{
// 作为demo,这里用oled屏字符显示来模拟灯颜色的切换
char *info = "light off";
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9, GPIO_PIN_RESET);
OLED_Clear();
OLED_ShowString(0, 0, (uint8_t *)info, 16);
}
void deal_down_stream_user_logic(void *client, ProductDataDefine * pData)
{
Log_d("someting about your own product logic wait to be done");
/////////////////////////////////////////////////////////////////////////////////////
char *color_name;
/* 灯光颜色 */
switch (sg_ProductData.m_color) {
case 0:
color_name = " RED ";
break;
case 1:
color_name = "GREEN";
break;
case 2:
color_name = "BLUE";
break;
}
if (sg_ProductData.m_power_switch == 1) {
/* 灯光开启式,按照控制参数展示 */
light_power_on();
light_change_color(color_name);
light_change_brightness(sg_ProductData.m_brightness);
} else {
/* 灯光关闭展示 */
light_power_off();
}
}