示例#1
0
static void handle_model_cmd(char *pwbuf, int blen, int argc, char **argv)
{
    #define MAX_MODEL_LENGTH 30
    char model[MAX_MODEL_LENGTH] = "light";
    int  model_len = sizeof(model);
    aos_kv_get("model", model, &model_len);

    if (argc == 1) {
        aos_cli_printf("Usage: model light/gateway. Model is currently %s\r\n", model);
        return;
    }

    if (strcmp(argv[1], "gateway") == 0) {
        if (strcmp(model, argv[1])) {
            aos_kv_del("alink");
            aos_kv_set("model", "gateway", sizeof("gateway"), 1);
            aos_cli_printf("Swith model to gateway, please reboot\r\n");
        } else {
            aos_cli_printf("Current model is already gateway\r\n");
        }
    } else {
        if (strcmp(model, argv[1])) {
            aos_kv_del("alink");
            aos_kv_set("model", "light", sizeof("light"), 1);
            aos_cli_printf("Swith model to light, please reboot\r\n");
        } else {
            aos_cli_printf("Current model is already light\r\n");
        }
    }
}
示例#2
0
static void clear_kv_and_reboot()
{
    aos_kv_del(NETMGR_WIFI_KEY);
    LOG("KV cleared, will reboot now.");
    aos_reboot();
}
示例#3
0
文件: linkwan_at.c 项目: wosayttn/aos
void process_linkwan_at(void)
{
    bool ret = false;
    int value;
    MibRequestConfirm_t mibReq;
    LoRaMacStatus_t status;
    uint8_t length;
    uint8_t buf[16];

    if (atcmd_index == 0 || atcmd[atcmd_index] != '\0') {
        return;
    }
    if (strncmp(atcmd, LORA_AT_HELP, strlen(LORA_AT_HELP)) == 0) {
        snprintf(atcmd, ATCMD_SIZE, "\r\n%s\r\n", LORA_AT_HELP);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_RM);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_APPEUI);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_APPKEY);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_DEUI);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_DR);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_ADR);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_CLASS);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_SCANMASK);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_CFM);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_CFMTRIALS);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_JOIN);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_TX);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_RX);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_DCS);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_TXSIZE);
        linkwan_serial_output(atcmd, strlen(atcmd));
        snprintf(atcmd, ATCMD_SIZE, "%s\r\n", LORA_AT_LINKCHK);
        linkwan_serial_output(atcmd, strlen(atcmd));
        return;
    } else if (strncmp(atcmd, LORA_AT_APPEUI, strlen(LORA_AT_APPEUI)) == 0) {
        if (atcmd_index == strlen(LORA_AT_APPEUI)) {
            uint8_t *eui = get_lora_app_eui();
            ret = true;
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s %02x%02x%02x%02x%02x%02x%02x%02x\r\n", \
                     LORA_AT_APPEUI, eui[0], eui[1], eui[2], eui[3], eui[4], eui[5], eui[6], eui[7]);
        } else if (atcmd_index == (strlen(LORA_AT_APPEUI) + 16)) {
            length = hex2bin(&atcmd[strlen(LORA_AT_APPEUI)], buf, 8);
            if (length == 8) {
                ret = set_lora_app_eui(buf);
                if (ret == true) {
                    snprintf(atcmd, ATCMD_SIZE, "\r\n%s %02x%02x%02x%02x%02x%02x%02x%02x\r\n", \
                             LORA_AT_APPEUI, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
                }
            }
        }
        if (ret == false) {
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s ERROR\r\n", LORA_AT_APPEUI);
        }
    } else if (strncmp(atcmd, LORA_AT_APPKEY, strlen(LORA_AT_APPKEY)) == 0) {
        if (atcmd_index == strlen(LORA_AT_APPKEY)) {
            uint8_t *key = get_lora_app_key();
            ret = true;
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\r\n", \
                     LORA_AT_APPKEY, key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7],
                     key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15]);
        } else if (atcmd_index == (strlen(LORA_AT_APPKEY) + 32)) {
            length = hex2bin(&atcmd[strlen(LORA_AT_APPKEY)], buf, 16);
            if (length == 16) {
                ret = set_lora_app_key(buf);
                if (ret == true) {
                    snprintf(atcmd, ATCMD_SIZE, "\r\n%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\r\n", \
                             LORA_AT_APPKEY, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
                             buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
                }
            }
        }
        if (ret == false) {
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s ERROR\r\n", LORA_AT_APPKEY);
        }
    } else if (strncmp(atcmd, LORA_AT_DEUI, strlen(LORA_AT_DEUI)) == 0) {
        if (atcmd_index == strlen(LORA_AT_DEUI)) {
            uint8_t *eui = get_lora_dev_eui();
            ret = true;
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s %02x%02x%02x%02x%02x%02x%02x%02x\r\n", \
                     LORA_AT_DEUI, eui[0], eui[1], eui[2], eui[3], eui[4], eui[5], eui[6], eui[7]);
        } else if (atcmd_index == (strlen(LORA_AT_DEUI) + 16)) {
            length = hex2bin(&atcmd[strlen(LORA_AT_DEUI)], buf, 8);
            if (length == 8) {
                ret = set_lora_dev_eui(buf);
                if (ret == true) {
                    snprintf(atcmd, ATCMD_SIZE, "\r\n%s %02x%02x%02x%02x%02x%02x%02x%02x\r\n", \
                             LORA_AT_DEUI, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
                }
            }
        }
        if (ret == false) {
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s ERROR\r\n", LORA_AT_DEUI);
        }
    } else if (strncmp(atcmd, LORA_AT_RM, strlen(LORA_AT_RM)) == 0) {
        aos_kv_del("lora");
        aos_kv_del("lora_dev");
        ret = true;
        snprintf(atcmd, ATCMD_SIZE, "\r\n%s OK\r\n", LORA_AT_RM);
    } else if (strncmp(atcmd, LORA_AT_DR, strlen(LORA_AT_DR)) == 0) {
        int8_t datarate;
        if (atcmd_index == strlen(LORA_AT_DR)) {
            ret = true;
            datarate = get_lora_tx_datarate();
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s %d\r\n", LORA_AT_DR, datarate);
        } else if (atcmd_index == (strlen(LORA_AT_DR) + 1)) {
            datarate = strtol(atcmd + strlen(LORA_AT_DR), NULL, 0);
            ret = set_lora_tx_datarate(datarate);
            if (ret == true) {
                snprintf(atcmd, ATCMD_SIZE, "\r\n%s %d\r\n", LORA_AT_DR, datarate);
            }
        }
        if (ret == false) {
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s ERROR\r\n", LORA_AT_DR);
        }
    } else if (strncmp(atcmd, LORA_AT_ADR, strlen(LORA_AT_ADR)) == 0) {
        int adr;
        if (atcmd_index == strlen(LORA_AT_ADR)) {
            ret = true;
            adr = get_lora_adr();
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s %d\r\n", LORA_AT_ADR, adr);
        } else if (atcmd_index == (strlen(LORA_AT_ADR) + 1)) {
            adr = strtol(atcmd + strlen(LORA_AT_ADR), NULL, 0);
            ret = set_lora_adr(adr);
            if (ret == true) {
                snprintf(atcmd, ATCMD_SIZE, "\r\n%s %d\r\n", LORA_AT_ADR, adr);
            }
        }
        if (ret == false) {
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s ERROR\r\n", LORA_AT_ADR);
        }
    } else if (strncmp(atcmd, LORA_AT_CLASS, strlen(LORA_AT_CLASS)) == 0) {
        int8_t class;
        if (atcmd_index == strlen(LORA_AT_CLASS)) {
            ret = true;
            class = get_lora_class();
            snprintf(atcmd, ATCMD_SIZE, "\r\n%s %d\r\n", LORA_AT_CLASS, class);
        } else if (atcmd_index == (strlen(LORA_AT_CLASS) + 1)) {
示例#4
0
文件: be_osal_fs.c 项目: wosayttn/aos
int be_osal_kv_delete(const char *key)
{
	return aos_kv_del(key);
}