USED void PlatformStandbyButtonClickedCallback(void)
{
    system_log_trace();
    mico_Context_t* context = NULL;

    context = mico_system_context_get( );
    require( context, exit );

    mico_system_power_perform( context, eState_Standby );

exit:
    return;
}
USED void PlatformEasyLinkButtonLongPressedCallback(void)
{
    system_log_trace();
    mico_Context_t* context = NULL;

    context = mico_system_context_get( );
    require( context, exit );

    mico_system_context_restore( context );

    mico_system_power_perform( context, eState_Software_Reset );

exit:
    return;
}
OSStatus mico_system_power_perform( mico_Context_t* const in_context, mico_system_state_t new_state )
{
    OSStatus err = kNoErr;
    mico_Context_t* context = NULL;

    context = mico_system_context_get( );
    require_action( context, exit, err = kNotPreparedErr );

    in_context->micoStatus.current_sys_state = new_state;
    require( in_context->micoStatus.sys_state_change_sem, exit);
    mico_rtos_set_semaphore( &in_context->micoStatus.sys_state_change_sem );

exit:
    return err;
}
示例#4
0
OSStatus HKPairInfoRemove(char * name)
{
  uint32_t i;
  OSStatus err = kNotFoundErr;

  pair_list_in_flash_t *pairList = &app_context->appConfig->pairList;

  for(i=0; i < MaxPairRecord; i++){
    if(strncmp(pairList->pairInfo[i].controllerName, name, 64) == 0){
      pairList->pairInfo[i].controllerName[0] = 0x0; //Clear the controller name record
      err = mico_system_context_update( mico_system_context_get() );
      break;
    }
  }

  return err;
}
USED void PlatformEasyLinkButtonClickedCallback(void)
{
    system_log_trace();
    mico_Context_t* context = NULL;

    context = mico_system_context_get( );
    require( context, exit );

    if(context->flashContentInRam.micoSystemConfig.easyLinkByPass != EASYLINK_BYPASS_NO) {
        context->flashContentInRam.micoSystemConfig.easyLinkByPass = EASYLINK_BYPASS_NO;
        needs_update = true;
    }

    if(context->flashContentInRam.micoSystemConfig.configured == allConfigured) {
        context->flashContentInRam.micoSystemConfig.configured = wLanUnConfigured;
        needs_update = true;
    }

    mico_system_power_perform( context, eState_Software_Reset );

exit:
    return;
}
示例#6
0
void mico_system_delegate_config_will_start( void )
{
  config_delegate_log_trace();
#ifdef USE_MiCOKit_EXT
  char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'};
#endif
  
  mico_Context_t* mico_context = mico_system_context_get();
  
  /*Led trigger*/
  mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL, _led_EL_Timeout_handler, NULL);
  mico_start_timer(&_Led_EL_timer);
#ifdef USE_MiCOKit_EXT
  memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1);
  snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", (uint8_t*)"Config...       ");
  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)oled_show_line);
  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, (uint8_t*)"  Awaiting      ");
  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, (uint8_t*)"    ssid/key    ");
#endif
  
  //mico_context->appStatus.noOTACheckOnSystemStart = true;
  return;
}
示例#7
0
OSStatus HKPairInfoInsert(char controllerIdentifier[64], uint8_t controllerLTPK[32], bool admin)
{
  OSStatus err = kNoErr;
  pair_list_in_flash_t        *pairList = &app_context->appConfig->pairList;
  uint32_t i;
  
  /* Looking for controller pair record */
  for(i=0; i < MaxPairRecord; i++){
    if(strncmp(pairList->pairInfo[i].controllerName, controllerIdentifier, 64)==0)
      break;
  }

  /* This is a new record, find a empty slot */
  if(i == MaxPairRecord){
    for(i=0; i < MaxPairRecord; i++){
      if(pairList->pairInfo[i].controllerName[0] == 0x0)
      break;
    }
  }
  
  /* No empty slot for new record */
  require_action(i < MaxPairRecord, exit, err = kNoSpaceErr);

  /* Write pair info to flash */
  strcpy(pairList->pairInfo[i].controllerName, controllerIdentifier);
  memcpy(pairList->pairInfo[i].controllerLTPK, controllerLTPK, 32);
  if(admin)
    pairList->pairInfo[i].permission = pairList->pairInfo[i].permission|0x00000001;
  else
    pairList->pairInfo[i].permission = pairList->pairInfo[i].permission&0xFFFFFFFE;

  mico_system_context_update( mico_system_context_get() );

exit: 
  return err;
}
示例#8
0
const char *mico_get_mac_addr()
{
  mico_Context_t *context = mico_system_context_get();
  return context->micoStatus.mac;
}
示例#9
0
int mico_start_alink(void)
{
  const uint8_t *cid;
  uint8_t cid_len = 0;
  mico_Context_t *context = mico_system_context_get();
  application_config_t *app_config = context->user_config_data;

  int ret = -1;
  cid = mico_generate_cid( &cid_len );
  memset(&alink_config, 0, sizeof(struct alink_config));
  struct device_info* dev = (struct device_info*) malloc(sizeof(struct device_info));

  memset(dev, 0, sizeof(struct device_info));
  strcpy(dev->key, ALINK_KEY);
  strcpy(dev->secret, ALINK_SECRET);

  sprintf(dev->name, "%s(%c%c%c%c)",DEV_NAME,
          context->micoStatus.mac[12], context->micoStatus.mac[13],
          context->micoStatus.mac[15], context->micoStatus.mac[16]);

  strcpy(dev->model, DEV_MODEL);
  strcpy(dev->manufacturer, DEV_MANUFACTURE);

  strcpy(dev->type, DEV_TYPE);
  strcpy(dev->category, DEV_CATEGORY);
  strcpy(dev->sn, DEV_SN);
  snprintf(dev->version, STR_NAME_LEN, "%d", FIRMWARE_REVISION_NUM);
  memcpy(dev->mac, mico_get_mac_addr(), 18);
  memcpy(dev->cid, cid, Min(cid_len, STR_CID_LEN) );

  custom_log("WSF", "dev->mac %s", dev->mac);
  custom_log("WSF", "dev->cid %s", dev->cid);
#ifdef ALINK_RAWDATA
	custom_log("WSF", "ALINK RAWDATA !!!");
#else
  dev->dev_callback[ACB_GET_DEVICE_STATUS] = device_status_get;
  dev->dev_callback[ACB_SET_DEVICE_STATUS] = device_command_execute;
#endif
  dev->sys_callback[ALINK_FUNC_SERVER_STATUS] = alink_network_callback;
  alink_set_callback(ALINK_FUNC_AVAILABLE_MEMORY, get_available_memory);

#ifdef DEBUG
  alink_set_loglevel(ALINK_LL_NONE);
#else
  alink_set_loglevel(ALINK_LL_NONE);
#endif

  memset(&alink_config, 0, sizeof(struct alink_config));
#ifdef SANDBOX
  sandbox_setting();
#endif
  if( app_config->resetflag == 1) {
    alink_config.factory_reset = 1;
  }

  alink_set_config(&alink_config);

#ifdef ALINK_RAWDATA
  alink_start_rawdata(dev, alink_uart_get, alink_uart_put);
#else
	alink_start(dev);  
#endif

  alink_wait_connect(NULL,-1); 

  free((void*)dev);

  return ret;
}
static int web_send_result_page(httpd_request_t *req)
{
  OSStatus err = kNoErr;
  bool para_succ = false;
  int buf_size = 512;
  char *buf;
  char value_ssid[maxSsidLen];
  char value_pass[maxKeyLen];
  mico_Context_t* context = NULL;
  
  context = mico_system_context_get( );
  
  buf = malloc(buf_size);
  
  err = httpd_get_data(req, buf, buf_size);
  require_noerr( err, Save_Out );
  
  err = httpd_get_tag_from_post_data(buf, "SSID", value_ssid, maxSsidLen);
  require_noerr( err, Save_Out );
  
  if(!strncmp(value_ssid, "\0", 1))
    goto Save_Out;
  
  strncpy(context->flashContentInRam.micoSystemConfig.ssid, value_ssid, maxSsidLen);
  
  err = httpd_get_tag_from_post_data(buf, "PASS", value_pass, maxKeyLen);
  require_noerr( err, Save_Out );
  
  strncpy(context->flashContentInRam.micoSystemConfig.key, value_pass, maxKeyLen);
  strncpy(context->flashContentInRam.micoSystemConfig.user_key, value_pass, maxKeyLen);
  context->flashContentInRam.micoSystemConfig.keyLength = strlen(context->flashContentInRam.micoSystemConfig.key);
  context->flashContentInRam.micoSystemConfig.user_keyLength = strlen(context->flashContentInRam.micoSystemConfig.key);
  
  context->flashContentInRam.micoSystemConfig.channel = 0;
  memset(context->flashContentInRam.micoSystemConfig.bssid, 0x0, 6);
  context->flashContentInRam.micoSystemConfig.security = SECURITY_TYPE_AUTO;
  context->flashContentInRam.micoSystemConfig.dhcpEnable = true;
  
  para_succ = true;
  
Save_Out:
  
  if(para_succ == true)
  {
    err = httpd_send_all_header(req, HTTP_RES_200, sizeof(wifisuccess), HTTP_CONTENT_HTML_STR);
    require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisuccess headers.") );
    
    err = httpd_send_body(req->sock, wifisuccess, sizeof(wifisuccess));
    require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisuccess body.") );
    
    context->flashContentInRam.micoSystemConfig.configured = allConfigured;
    
    mico_system_context_update(context);
    
    mico_system_power_perform( context, eState_Software_Reset );
  }
  else
  {
    err = httpd_send_all_header(req, HTTP_RES_200, sizeof(wififail), HTTP_CONTENT_HTML_STR);
    require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wififail headers.") );
    
    err = httpd_send_body(req->sock, wififail, sizeof(wififail));
    require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wififail body.") );    
  }
  
exit:  
  if(buf) free(buf);
  return err; 
}
示例#11
0
OSStatus MiCOStartSiteWhereService(app_context_t* const inContext)
{
  sitewhere_log_trace();
  OSStatus err = kUnknownErr;
  char *bonjour_txt_record = NULL;
  char *bonjour_txt_field = NULL;
  
  // update wifi status
  err = mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void *)swNotify_WifiStatusHandler, inContext);
  require_noerr_action(err, exit, 
                       sitewhere_log("ERROR: mico_system_notify_register (mico_notify_WIFI_STATUS_CHANGED) failed!") );
  
  // create uinque hardeareID like: MODEL-HARDWARE_REVISION-MAC
  memset(hardwareId, '\0', sizeof(hardwareId));
  sprintf(hardwareId, "Enjoy_%s-%s-%c%c%c%c%c%c",MODEL, HARDWARE_REVISION, 
          mico_system_context_get()->micoStatus.mac[9],
          mico_system_context_get()->micoStatus.mac[10],
          mico_system_context_get()->micoStatus.mac[12],
          mico_system_context_get()->micoStatus.mac[13],
          mico_system_context_get()->micoStatus.mac[15],
          mico_system_context_get()->micoStatus.mac[16]
            );
  sitewhere_log("hardwareId=[%s]", hardwareId);
  // create system topic like: SiteWhere/commands/<hardwareid>
  memset(System1, '\0', sizeof(System1));
  sprintf(System1, "%s/%s", "SiteWhere/system", hardwareId);
  sitewhere_log("System1=[%s]", System1);
  // create command topic like: SiteWhere/<system/hardwareid>
  memset(Command1, '\0', sizeof(Command1));
  sprintf(Command1, "%s/%s", "SiteWhere/commands", hardwareId);
  sitewhere_log("Command1=[%s]", Command1);
  // specificationToken
  sitewhere_log("specificationToken=[%s]", specificationToken);
  
  //------------------------------------------------------------------------
  // update hardwareid in mdns text record
  sitewhere_log("update bonjour txt record.");
  bonjour_txt_record = malloc(550);
  require_action(bonjour_txt_record, exit, err = kNoMemoryErr);
  
  bonjour_txt_field = __strdup_trans_dot(inContext->mico_context->micoStatus.mac);
  sprintf(bonjour_txt_record, "MAC=%s.", bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(hardwareId);
  sprintf(bonjour_txt_record, "%sHardware ID=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(FIRMWARE_REVISION);
  sprintf(bonjour_txt_record, "%sFirmware Rev=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(HARDWARE_REVISION);
  sprintf(bonjour_txt_record, "%sHardware Rev=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(MicoGetVer());
  sprintf(bonjour_txt_record, "%sMICO OS Rev=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(MODEL);
  sprintf(bonjour_txt_record, "%sModel=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(PROTOCOL);
  sprintf(bonjour_txt_record, "%sProtocol=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  bonjour_txt_field = __strdup_trans_dot(MANUFACTURER);
  sprintf(bonjour_txt_record, "%sManufacturer=%s.", bonjour_txt_record, bonjour_txt_field);
  free(bonjour_txt_field);
  
  sprintf(bonjour_txt_record, "%sSeed=%u.", bonjour_txt_record, inContext->mico_context->flashContentInRam.micoSystemConfig.seed);
  
  mdns_update_txt_record(BONJOUR_SERVICE, Station, bonjour_txt_record);
  if(NULL != bonjour_txt_record) free(bonjour_txt_record);
  //------------------------------------------------------------------------
  
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "sitewhere", 
                                sitewhere_main_thread, STACK_SIZE_SITEWHERE_MAIN_THREAD, 
                                inContext );
  require_noerr_action( err, exit, sitewhere_log("ERROR: Unable to start sitewhere thread.") );
  
  //err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "MQTT Client", 
  //                              mqtt_loop_thread, 0xC00, (void*)inContext->mico_context );
  //require_noerr_action( err, exit, sitewhere_log("ERROR: Unable to start the MQTT client thread.") );
  
exit:
  return err;
}