Improve readability of codes in farm ai demo
Adjust the indentation of codes.
This commit is contained in:
@@ -20,11 +20,13 @@ static int str_to_hex(const char *bufin, int len, char *bufout)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned char tmp2 = 0x0;
|
||||
unsigned int tmp = 0;
|
||||
unsigned char tmp = 0x0;
|
||||
|
||||
if (NULL == bufin || len <= 0 || NULL == bufout)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < len; i = i+2)
|
||||
{
|
||||
tmp2 = bufin[i];
|
||||
@@ -34,6 +36,7 @@ static int str_to_hex(const char *bufin, int len, char *bufout)
|
||||
bufout[i/2] =(tmp2<<4)|(tmp&0x0F);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +51,7 @@ int mq_dev_report(void)
|
||||
pub_opt.id = 0;
|
||||
pub_opt.topic = MQTT_PUBLISH_TOPIC;
|
||||
|
||||
// {"motor":0,"light":1,"temperature":22.22,"humidity":55.55,"light_intensity":100.00}
|
||||
//{"motor":0,"light":1,"temperature":22.22,"humidity":55.55,"light_intensity":100.00}
|
||||
root = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(root, "motor",E53_IA1_Data.MotorMode);
|
||||
cJSON_AddNumberToObject(root, "light",E53_IA1_Data.LightMode);
|
||||
@@ -67,6 +70,7 @@ int mq_dev_report(void)
|
||||
}
|
||||
tos_mmheap_free(data);
|
||||
cJSON_Delete(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -79,6 +83,7 @@ int parse_dev_cmd(uint8_t *data)
|
||||
int motor;
|
||||
int light;
|
||||
char *str;
|
||||
|
||||
printf("parse_dev_cmd...\n");
|
||||
if(cjson == NULL){
|
||||
printf("json pack into cjson error...");
|
||||
@@ -87,6 +92,7 @@ int parse_dev_cmd(uint8_t *data)
|
||||
else{
|
||||
cJSON_Print(cjson);
|
||||
}
|
||||
|
||||
cjsonret = NULL;
|
||||
cjsonret = cJSON_GetObjectItem(cjson,"motor");
|
||||
if(cjsonret!=NULL)
|
||||
@@ -95,14 +101,17 @@ int parse_dev_cmd(uint8_t *data)
|
||||
motor=cjsonret->valueint;
|
||||
printf("motor=%d\n",motor);
|
||||
if(motor==1)
|
||||
{//power on relay
|
||||
{
|
||||
//power on relay
|
||||
motor_control(1);
|
||||
}
|
||||
else if(motor==0)
|
||||
{//power off relay
|
||||
{
|
||||
//power off relay
|
||||
motor_control(0);
|
||||
}
|
||||
}
|
||||
|
||||
cjsonret = NULL;
|
||||
cjsonret = cJSON_GetObjectItem(cjson,"light");
|
||||
if(cjsonret!=NULL)
|
||||
@@ -112,11 +121,13 @@ int parse_dev_cmd(uint8_t *data)
|
||||
//打印输出
|
||||
printf("light=%d\n",light);
|
||||
if(light==1)
|
||||
{//power on relay
|
||||
{
|
||||
//power on relay
|
||||
light_control(1);
|
||||
}
|
||||
else if(light==0)
|
||||
{//power off relay
|
||||
{
|
||||
//power off relay
|
||||
light_control(0);
|
||||
}
|
||||
}
|
||||
@@ -137,10 +148,12 @@ int parse_dev_cmd(uint8_t *data)
|
||||
}
|
||||
//delete cjson
|
||||
cJSON_Delete(cjson);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mq_dev_receiv(void){
|
||||
int mq_dev_receiv(void)
|
||||
{
|
||||
static int count = 1;
|
||||
uint8_t read_data[100];
|
||||
int read_len;
|
||||
@@ -160,12 +173,13 @@ int mq_dev_receiv(void){
|
||||
parse_dev_cmd(read_data);
|
||||
}
|
||||
count++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mq_dev_subscribe(void){
|
||||
int mq_dev_subscribe(void)
|
||||
{
|
||||
mqtt_sub_opt_t sub_opt;
|
||||
|
||||
sub_opt.count = 1;
|
||||
sub_opt.dup = 0;
|
||||
sub_opt.id = 1;
|
||||
@@ -176,6 +190,7 @@ int mq_dev_subscribe(void){
|
||||
if (tos_mqtt_subscribe(sock_id, &sub_opt) != 0) {
|
||||
printf("subscribe failed!!!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
void ai_demo(void)
|
||||
@@ -205,15 +220,18 @@ void ai_demo(void)
|
||||
}
|
||||
}
|
||||
|
||||
void sensor_read(void){
|
||||
while(1){
|
||||
void sensor_read(void)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
E53_IA1_Read_Data();
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
#define welcomspeak "欢迎TOS"
|
||||
void speaker(char *str){
|
||||
void speaker(char *str)
|
||||
{
|
||||
uint8_t data[100];
|
||||
int16_t len=0;
|
||||
|
||||
@@ -244,4 +262,3 @@ void application_entry(void *arg)
|
||||
tos_task_delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user