Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeBo committed Nov 16, 2018
2 parents ab4a9e9 + 2082895 commit cfe57fb
Show file tree
Hide file tree
Showing 7 changed files with 1,207 additions and 1,143 deletions.
276 changes: 149 additions & 127 deletions examples/ilopicaapp/ilopmain.c

Large diffs are not rendered by default.

209 changes: 105 additions & 104 deletions examples/iloprawapp/ilopmain.c
Original file line number Diff line number Diff line change
@@ -1,104 +1,105 @@
#include "alicloud_ilop.h"
#include "emh_api.h"
#include "main.h"
#include "mx_cli.h"
#include "mx_common.h"
#include "mx_debug.h"
#include "mx_hal.h"

static int awss_start = 0;
static int awss_press = 0;
static int reset = 0;

const emh_ilop_config_t ilop_config = {
.tls_thing = NULL,
.tls_len = 0,
.dm = EMH_ARG_ILOP_DM_RAW,
};

const ilop_device_key_t device_key = {
.product_key = "b1CcQqrXoVR",
.product_secret = "yOrZrmtDcHLgVOJc",
.device_name = "sPhDWW7vvaSyUfNBOvM9",
.device_secret = "R90glnJXJNAUsKGSRRudMdlhyvA12OEM",
};

static void awss_tast_loop(void)
{
if (awss_start == 1) {
ilop_awss_start();
awss_start = 0;
}
if (awss_press == 1) {
ilop_awss_press();
awss_press = 0;
}
if( reset == 1 )
{
ilop_restore();
reset = 0;
}
}

#ifdef MX_CLI_ENABLE
static void handle_aws_cmd(char* pwbuf, int blen, int argc, char** argv)
{
if (argc != 2)
return;

if (strcmp(argv[1], "start") == 0) {
awss_start = 1;
} else if (strcmp(argv[1], "press") == 0) {
awss_press = 1;
}
}

static void handle_reset_cmd(char* pwbuf, int blen, int argc, char** argv)
{
reset = 1;
}

static struct cli_command ilopcmds[] = {
{ "aws", "aws [start|press]", handle_aws_cmd },
{ "reset", "clean wifi module and ilop service", handle_reset_cmd },
};
#endif

void ilop_main(void)
{
mx_status err = kNoErr;

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

#ifdef MX_CLI_ENABLE
cli_register_commands(ilopcmds, sizeof(ilopcmds) / sizeof(struct cli_command));
#endif

/* ILOP service initialization */
err = ilop_init(&ilop_config);
if (err != kNoErr)
app_log("ilop init err");

/* Set the ILOP three tuple. If the module is pre burned, delete the function */
ilop_set_device_key(&device_key);

/* database initialization */
ilop_raw_attr_init(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_MAX);
ilop_raw_attr_init(ATTR_TYPE_EVENT, ILOP_EVENT_MAX);
ilop_raw_attr_init(ATTR_TYPE_SERVICE, ILOP_SERVICE_MAX);

event_register();
property_register_light();
property_register_wifi();
service_register();

while (1) {
ilop_runloop();
awss_tast_loop();
event_task_loop();
}

return;
}
#include "alicloud_ilop.h"
#include "emh_api.h"
#include "main.h"
#include "mx_cli.h"
#include "mx_common.h"
#include "mx_debug.h"
#include "mx_hal.h"

static int awss_start = 0;
static int awss_press = 0;
static int reset = 0;

const emh_ilop_config_t ilop_config = {
.tsl_thing = NULL,
.tsl_len = 0,
.dm = EMH_ARG_ILOP_DM_RAW,
.domain = EMH_ARG_ILOP_DOMAIN_SHANGHAI,
};

const ilop_device_key_t device_key = {
.product_key = "b1CcQqrXoVR",
.product_secret = "yOrZrmtDcHLgVOJc",
.device_name = "sPhDWW7vvaSyUfNBOvM9",
.device_secret = "R90glnJXJNAUsKGSRRudMdlhyvA12OEM",
};

static void awss_tast_loop(void)
{
if (awss_start == 1) {
ilop_awss_start();
awss_start = 0;
}
if (awss_press == 1) {
ilop_awss_press();
awss_press = 0;
}
if( reset == 1 )
{
ilop_restore();
reset = 0;
}
}

#ifdef MX_CLI_ENABLE
static void handle_aws_cmd(char* pwbuf, int blen, int argc, char** argv)
{
if (argc != 2)
return;

if (strcmp(argv[1], "start") == 0) {
awss_start = 1;
} else if (strcmp(argv[1], "press") == 0) {
awss_press = 1;
}
}

static void handle_reset_cmd(char* pwbuf, int blen, int argc, char** argv)
{
reset = 1;
}

static struct cli_command ilopcmds[] = {
{ "aws", "aws [start|press]", handle_aws_cmd },
{ "reset", "clean wifi module and ilop service", handle_reset_cmd },
};
#endif

void ilop_main(void)
{
mx_status err = kNoErr;

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

#ifdef MX_CLI_ENABLE
cli_register_commands(ilopcmds, sizeof(ilopcmds) / sizeof(struct cli_command));
#endif

/* ILOP service initialization */
err = ilop_init(&ilop_config);
if (err != kNoErr)
app_log("ilop init err");

/* Set the ILOP three tuple. If the module is pre burned, delete the function */
ilop_set_device_key(&device_key);

/* database initialization */
ilop_raw_attr_init(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_MAX);
ilop_raw_attr_init(ATTR_TYPE_EVENT, ILOP_EVENT_MAX);
ilop_raw_attr_init(ATTR_TYPE_SERVICE, ILOP_SERVICE_MAX);

event_register();
property_register_light();
property_register_wifi();
service_register();

while (1) {
ilop_runloop();
awss_tast_loop();
event_task_loop();
}

return;
}
Loading

0 comments on commit cfe57fb

Please sign in to comment.