Improve readability of codes in farm ai demo

Adjust the indentation of codes.
This commit is contained in:
David Lin
2020-02-24 21:46:01 +08:00
committed by GitHub
parent a86a9c18f8
commit ddb8268cb7

View File

@@ -20,11 +20,13 @@ static int str_to_hex(const char *bufin, int len, char *bufout)
{ {
int i = 0; int i = 0;
unsigned char tmp2 = 0x0; unsigned char tmp2 = 0x0;
unsigned int tmp = 0; unsigned char tmp = 0x0;
if (NULL == bufin || len <= 0 || NULL == bufout) if (NULL == bufin || len <= 0 || NULL == bufout)
{ {
return -1; return -1;
} }
for(i = 0; i < len; i = i+2) for(i = 0; i < len; i = i+2)
{ {
tmp2 = bufin[i]; 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); bufout[i/2] =(tmp2<<4)|(tmp&0x0F);
} }
return 0; return 0;
} }
@@ -67,6 +70,7 @@ int mq_dev_report(void)
} }
tos_mmheap_free(data); tos_mmheap_free(data);
cJSON_Delete(root); cJSON_Delete(root);
return 0; return 0;
} }
@@ -79,6 +83,7 @@ int parse_dev_cmd(uint8_t *data)
int motor; int motor;
int light; int light;
char *str; char *str;
printf("parse_dev_cmd...\n"); printf("parse_dev_cmd...\n");
if(cjson == NULL){ if(cjson == NULL){
printf("json pack into cjson error..."); printf("json pack into cjson error...");
@@ -87,6 +92,7 @@ int parse_dev_cmd(uint8_t *data)
else{ else{
cJSON_Print(cjson); cJSON_Print(cjson);
} }
cjsonret = NULL; cjsonret = NULL;
cjsonret = cJSON_GetObjectItem(cjson,"motor"); cjsonret = cJSON_GetObjectItem(cjson,"motor");
if(cjsonret!=NULL) if(cjsonret!=NULL)
@@ -95,14 +101,17 @@ int parse_dev_cmd(uint8_t *data)
motor=cjsonret->valueint; motor=cjsonret->valueint;
printf("motor=%d\n",motor); printf("motor=%d\n",motor);
if(motor==1) if(motor==1)
{//power on relay {
//power on relay
motor_control(1); motor_control(1);
} }
else if(motor==0) else if(motor==0)
{//power off relay {
//power off relay
motor_control(0); motor_control(0);
} }
} }
cjsonret = NULL; cjsonret = NULL;
cjsonret = cJSON_GetObjectItem(cjson,"light"); cjsonret = cJSON_GetObjectItem(cjson,"light");
if(cjsonret!=NULL) if(cjsonret!=NULL)
@@ -112,11 +121,13 @@ int parse_dev_cmd(uint8_t *data)
//打印输出 //打印输出
printf("light=%d\n",light); printf("light=%d\n",light);
if(light==1) if(light==1)
{//power on relay {
//power on relay
light_control(1); light_control(1);
} }
else if(light==0) else if(light==0)
{//power off relay {
//power off relay
light_control(0); light_control(0);
} }
} }
@@ -137,10 +148,12 @@ int parse_dev_cmd(uint8_t *data)
} }
//delete cjson //delete cjson
cJSON_Delete(cjson); cJSON_Delete(cjson);
return 0; return 0;
} }
int mq_dev_receiv(void){ int mq_dev_receiv(void)
{
static int count = 1; static int count = 1;
uint8_t read_data[100]; uint8_t read_data[100];
int read_len; int read_len;
@@ -160,12 +173,13 @@ int mq_dev_receiv(void){
parse_dev_cmd(read_data); parse_dev_cmd(read_data);
} }
count++; count++;
return 0; return 0;
} }
int mq_dev_subscribe(void){ int mq_dev_subscribe(void)
{
mqtt_sub_opt_t sub_opt; mqtt_sub_opt_t sub_opt;
sub_opt.count = 1; sub_opt.count = 1;
sub_opt.dup = 0; sub_opt.dup = 0;
sub_opt.id = 1; sub_opt.id = 1;
@@ -176,6 +190,7 @@ int mq_dev_subscribe(void){
if (tos_mqtt_subscribe(sock_id, &sub_opt) != 0) { if (tos_mqtt_subscribe(sock_id, &sub_opt) != 0) {
printf("subscribe failed!!!\n"); printf("subscribe failed!!!\n");
} }
return 0; return 0;
} }
void ai_demo(void) void ai_demo(void)
@@ -205,15 +220,18 @@ void ai_demo(void)
} }
} }
void sensor_read(void){ void sensor_read(void)
while(1){ {
while(1)
{
E53_IA1_Read_Data(); E53_IA1_Read_Data();
osDelay(100); osDelay(100);
} }
} }
#define welcomspeak "欢迎TOS" #define welcomspeak "欢迎TOS"
void speaker(char *str){ void speaker(char *str)
{
uint8_t data[100]; uint8_t data[100];
int16_t len=0; int16_t len=0;
@@ -244,4 +262,3 @@ void application_entry(void *arg)
tos_task_delay(1000); tos_task_delay(1000);
} }
} }