Skip to content

Commit

Permalink
local cloud tested ok
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhibo committed Oct 25, 2018
1 parent 8545854 commit 52e7c0a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"aliosStudio.sdkPath": "/Users/miaogs/.aos/AliOS-Things"
"aliosStudio.sdkPath": "/Users/miaogs/.aos/AliOS-Things",
"files.associations": {
"emh_api.h": "c",
"atcmdparser.h": "c"
}
}
39 changes: 29 additions & 10 deletions examples/qlinkapp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,26 @@ void emh_ev_qlink_get_local_attrs(emh_qlink_msg_t* msg)

}

void emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg)
int emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg)
{
app_log("set attrs");
app_log("data is :%s len is :%d", msg->data, msg->len);

//unbind

//reset

//factory

//set data, if this field also need to be upload, this function return 1, otherwise 0 will be returned.

//REBOOT, reboot device
if( 0==strncmp(msg->data, "REBOOT", msg->len ) )
{
app_log("please reboot device.");
}else if( 0==strncmp(msg->data, "FACTORY", msg->len) ) //FACTOR, restore factory settings and clear all parameters of then system.
{
app_log("please restore device.");
}else if( 0==strncmp(msg->data, "UNBIND", msg->len) ) //UNBIND
{
app_log("this device has already bend unbinded");
}else //set data, if this field also need to be upload, this function return 1, otherwise 0 will be returned.
{
app_log("data is :%s len is :%d", msg->data, msg->len);
// return 1;
}
return 0;
}

#ifdef MX_CLI_ENABLE
Expand Down Expand Up @@ -111,10 +118,22 @@ static void handle_reboot_cmd(char* pwbuf, int blen, int argc, char** argv)

}

static void handle_send_cmd(char* pwbuf, int blen, int argc, char** argv)
{
if (argc != 3)
{
app_log("input param error!!!");
return;
}

emh_qlink_send_json_to_cloud( QLINK_EVENT_TYPE_INFORM, *argv[2], strlen(*argv[2]) );
}

struct cli_command qlinkcmds[] = {
{ "raw", "raw [start|stop]", handle_raw_cmd },
{ "user", "start|stop", handle_user_cmd },
{ "reboot", "reboot", handle_reboot_cmd },
{ "send", "send <type>", handle_send_cmd },
};
#endif

Expand Down
8 changes: 6 additions & 2 deletions examples/qlinkapp/user_qlink_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

#define app_log(M, ...) MX_LOG(APP_DEBUG, "APP", M, ##__VA_ARGS__)

// #define MX_CLI_ENABLE 1
#define APP_DEBUG MX_DEBUG_ON
#define APP_DEBUG MX_DEBUG_ON

#define QLINK_EVENT_TYPE_INFORM "Inform" //send data initiate
#define QLINK_EVENT_TYPE_FILE "File"
#define QLINK_EVENT_TYPE_PARAMCHANGE "ParamChange" //send data after triggering by hand
#define QLINK_EVENT_TYPE_DATA "Data" //send data as a response


void qlink_main(void);
Expand Down
2 changes: 1 addition & 1 deletion src/cloud_qlink/cloud_qlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ MX_WEAK void emh_ev_qlink_get_local_attrs(emh_qlink_msg_t* msg)
qlink_log("please redeclare this function in application!!!");
}

MX_WEAK void emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg)
MX_WEAK int emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/helper/emhost/emh_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ MX_WEAK void emh_ev_qlink_get_local_attrs(emh_qlink_msg_t* attrs);
*
* @return none
*/
MX_WEAK void emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg);
MX_WEAK int emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg);

/** @}*/
/** @}*/
Expand Down
22 changes: 20 additions & 2 deletions src/helper/emhost/emh_qlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ mx_status emh_qlink_send_json_to_cloud( char *type, uint8_t *data, uint32_t len
return kGeneralErr;
}

mx_status emh_qlink_send_data_to_uart( int res )
{
if ( ATCmdParser_send("AT+QLINKPARAM=%d", res)
&& ATCmdParser_recv("OK\r\n")) {
return kNoErr;
}
return kGeneralErr;
}

void emh_qlink_event_handler(void)
{
mx_status err = kNoErr;
Expand Down Expand Up @@ -184,7 +193,15 @@ void emh_qlink_event_handler(void)
msg.data = data;
msg.format = EMH_ARG_QLINK_FORMAT_JSON;
msg.len = count;
emh_ev_qlink_set_local_attrs(&msg);

int res = 0;
res = emh_ev_qlink_set_local_attrs(&msg);
if( NULL!=strstr(msg.data, "data") )
{
printf("ready to send back data\r\n");
emh_qlink_send_data_to_uart(res);
}
printf("after sending back data\r\n");
free(data);
}
/* QLINK device === json value===> server */
Expand All @@ -194,10 +211,11 @@ void emh_qlink_event_handler(void)
int32_t count;
require_action(ATCmdParser_recv("%d,", &count), exit, err = kMalformedErr);

uint8_t *data = malloc(count);
uint8_t *data = malloc(count+1);
require_action(data, exit, err = kNoMemoryErr);
require_action(ATCmdParser_read((char *)data, count) == count, exit, err = kTimeoutErr);

*(data+count) = 0x00;
msg.data = data;
msg.format = EMH_ARG_QLINK_FORMAT_JSON;
msg.len = count;
Expand Down

0 comments on commit 52e7c0a

Please sign in to comment.