Skip to content

Commit

Permalink
update,test Ok
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeBo committed Oct 21, 2018
1 parent 5296c91 commit 32f54d3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 59 deletions.
61 changes: 37 additions & 24 deletions examples/qlinkapp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const emh_qlink_config_t config = {
.product_info = {
.product_token = "38Szyd6i1240elbV",
.andlink_token = "wWppJIdROfQkcsMW",
.device_type = "30413",
.product_token = "PXmsE6kQmxEgc0e3",
.andlink_token = "ZxMo0zJvvZMWP3Az",
.device_type = "30531",
.format = EMH_ARG_QLINK_FORMAT_JSON,
},
.version_info = {
Expand All @@ -16,26 +16,30 @@ const emh_qlink_config_t config = {
void qlink_event_handler(qlink_event_t event)
{
switch (event) {
case QLINK_EVENT_WLAN_CONFIG_STARTED: {
app_log("Wi-Fi config....");
case QLINK_EVENT_WLAN_CONFIG_STARTED: {
app_log("Wi-Fi config....");
break;
}
case QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE: {
app_log("WiFi config in AP mode......");
break;
}
case QLINK_EVENT_WLAN_CONNECTED: {
app_log("Wi-Fi connected");
break;
}
case QLINK_EVENT_WLAN_DISCONNECTED: {
app_log("Wi-Fi disconnected");
break;
}
case QLINK_EVENT_CLOUD_CONNECTED: {
app_log("Cloud connected");
break;
}
case QLINK_EVENT_CLOUD_DISCONNECTED: {
app_log("Cloud disconnected");
break;
}
}
case QLINK_EVENT_WLAN_CONNECTED: {
app_log("Wi-Fi connected");
break;
}
case QLINK_EVENT_WLAN_DISCONNECTED: {
app_log("Wi-Fi disconnected");
break;
}
case QLINK_EVENT_CLOUD_CONNECTED: {
app_log("Cloud connected");
break;
}
case QLINK_EVENT_CLOUD_DISCONNECTED: {
app_log("Cloud disconnected");
break;
}
}
}

Expand All @@ -58,7 +62,7 @@ void emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg)

//factory

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

}

Expand All @@ -77,6 +81,7 @@ static void handle_raw_cmd(char* pwbuf, int blen, int argc, char** argv)

static void handle_user_cmd(char* pwbuf, int blen, int argc, char** argv)
{
app_log("enter handle_user_cmd()!");
if (argc != 2)
return;

Expand All @@ -96,19 +101,27 @@ struct cli_command qlinkcmds[] = {
void qlink_main(void)
{
mx_status err = kNoErr;
int nums = 0;

/* System initialization, ticker, stdio */
mx_hal_ms_ticker_init();
mx_hal_stdio_init();

#ifdef MX_CLI_ENABLE
app_log("open cli function");
cli_register_commands(qlinkcmds, sizeof(qlinkcmds) / sizeof(struct cli_command));
#endif

label_reinit:
/* qlink service initialization */
err = qlink_init(&config);
if (err != kNoErr)
if (err != kNoErr){
app_log("qlink init err");
if( nums<3 ){
nums++;
goto label_reinit;
}
}

while (1) {
qlink_runloop();
Expand Down
2 changes: 1 addition & 1 deletion examples/qlinkapp/user_qlink_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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


Expand Down
6 changes: 6 additions & 0 deletions src/cloud_qlink/cloud_qlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ MX_WEAK void qlink_event_handler(qlink_event_t event)
qlink_log("Wi-Fi config....");
break;
}
case QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE: {
qlink_log("WiFi config in AP mode......");
break;
}
case QLINK_EVENT_WLAN_CONNECTED: {
qlink_log("Wi-Fi connected");
break;
Expand Down Expand Up @@ -170,6 +174,8 @@ void emh_ev_wlan(emh_arg_wlan_ev_t event)
qlink_event_handler(QLINK_EVENT_WLAN_CONNECTED);
} else if (event == EMH_ARG_WLAN_EV_STA_DISCONNECTED) {
qlink_event_handler(QLINK_EVENT_WLAN_DISCONNECTED);
} else if (event == EMH_ARG_WLAN_EV_UAP_ESTABLISHED) {
qlink_event_handler(QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/cloud_qlink/cloud_qlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
/** Alicloud QLINK service events */
enum qlink_event_e {
QLINK_EVENT_WLAN_CONFIG_STARTED, /**< AWS service is started to set wlan and cloud. */
QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE,
QLINK_EVENT_WLAN_CONNECTED, /**< Device is connected to Wi-Fi access point. */
QLINK_EVENT_WLAN_DISCONNECTED, /**< Device is disconnected from Wi-Fi access point. */
QLINK_EVENT_CLOUD_CONNECTED, /**< Alicloud QLINK service is connected */
Expand Down
3 changes: 3 additions & 0 deletions src/helper/emhost/emh_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ mx_status emh_init(void)
#ifdef AT_SUPPORT_ALISDS
ATCmdParser_add_oob("+ALINKEVENT:", emh_alisds_event_handler);
#endif
#ifdef AT_SUPPORT_QLINK
ATCmdParser_add_oob("+QLINKEVENT:", emh_qlink_event_handler);
#endif
ATCmdParser_add_oob("+WEVENT:", emh_wlan_event_handler);
return kNoErr;
}
Expand Down
62 changes: 28 additions & 34 deletions src/helper/emhost/emh_qlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,48 @@ mx_status emh_qlink_config(const emh_qlink_config_t* config, bool force)
if( false==force )
{
/* Check product info*/
if (!(ATCmdParser_send("AT+ALINKPRODUCT?")
&& ATCmdParser_recv("+ALINKPRODUCT:%200[^\r]\r\n",args)
&& ATCmdParser_recv("OK\r\n"))) {
goto label_version;
if (ATCmdParser_send("AT+QLINKPRODUCT?")
&& ATCmdParser_recv("+QLINKPRODUCT:%200[^\r]\r\n",args)
&& ATCmdParser_recv("OK\r\n")) {
if (3 == ATCmdParser_analyse_args(args, arg_list, 3)) {
if ( !(strcmp(arg_list[0], config->product_info.product_token)
|| strcmp(arg_list[1], config->product_info.andlink_token)
|| strcmp(arg_list[2], config->product_info.device_type)) ){
goto label_version;
}
}
}
}

if (3 != ATCmdParser_analyse_args(args, arg_list, 3)) {
return kMalformedErr;
if (!(ATCmdParser_send("AT+QLINKPRODUCT=%s,%s,%s",
config->product_info.product_token, config->product_info.andlink_token,
config->product_info.device_type )
&& ATCmdParser_recv("OK\r\n"))) {
return kGeneralErr;
}

if (strcmp(arg_list[0], config->product_info.product_token)
|| strcmp(arg_list[1], config->product_info.andlink_token)
|| strcmp(arg_list[2], config->product_info.device_type)){

if (!(ATCmdParser_send("AT+ALINKPRODUCT=%s,%s,%s",
config->product_info.product_token, config->product_info.andlink_token,
config->product_info.device_type )
&& ATCmdParser_recv("OK\r\n"))) {
return kGeneralErr;
}
}

label_version:
if( false==force )
{
/* Check version info*/
if (!(ATCmdParser_send("AT+QLINKVERSION?")
if (ATCmdParser_send("AT+QLINKVERSION?")
&& ATCmdParser_recv("+QLINKVERSION:%40[^\r]\r\n",args)
&& ATCmdParser_recv("OK\r\n"))) {
return kReadErr;
&& ATCmdParser_recv("OK\r\n")) {
if (2 == ATCmdParser_analyse_args(args, arg_list, 2)) {
if (!(strcmp(arg_list[0], config->version_info.firmware_version)
|| strcmp(arg_list[1], config->version_info.software_version))){
return kNoErr;
}
}
}
}

if (2 != ATCmdParser_analyse_args(args, arg_list, 2)) {
return kMalformedErr;
}

if ((strcmp(arg_list[0], config->version_info.firmware_version)
|| strcmp(arg_list[1], config->version_info.software_version))){

if (!(ATCmdParser_send("AT+QLINKVERSION=%s,%s",
config->version_info.firmware_version, config->version_info.software_version )
&& ATCmdParser_recv("OK\r\n"))) {
return kGeneralErr;
}
if (!(ATCmdParser_send("AT+QLINKVERSION=%s,%s",
config->version_info.firmware_version, config->version_info.software_version )
&& ATCmdParser_recv("OK\r\n"))) {
return kGeneralErr;
}

return kNoErr;
}

Expand Down

0 comments on commit 32f54d3

Please sign in to comment.