static pwr_tStatus AnteAdopt ( ldh_tSesContext Session, pwr_tObjid Card, /* current card object */ pwr_tClassId Class /* class of child to adopt */ ) { pwr_tStatus sts; pwr_sClass_Do_HVDO32 RCard; pwr_sdClass_Do_HVDO32 DCard; pwr_tUInt32 MaxChan; pwr_tUInt32 Chan; int i; if (Class != pwr_cClass_ChanDo) return PWRB__CHANCLASS; sts = ldh_ReadObjectBody(Session, Card, "RtBody", &RCard, sizeof(RCard)); if (EVEN(sts)) return sts; sts = ldh_ReadObjectBody(Session, Card, "DevBody", &DCard, sizeof(DCard)); if (EVEN(sts)) return sts; MaxChan = co_min(32, RCard.MaxNoOfChannels); for (i = 0, Chan = 1; i < (int)MaxChan; i++, Chan <<= 1) { if ((DCard.ChannelAllocation & Chan) == 0) break; } if (i >= (int)MaxChan) return PWRB__ALOCHAN; else return LDH__ADOPTRENAME; }
static pwr_tStatus PostUnadopt ( ldh_tSesContext Session, pwr_tObjid Card, /* current card object */ pwr_tObjid Channel, pwr_tClassId Class /* class of child to adopt */ ) { pwr_tStatus sts; pwr_sClass_Do_HVDO32 RCard; pwr_sClass_ChanDo ChanDo; pwr_sdClass_Do_HVDO32 DCard; pwr_tUInt32 MaxChan; pwr_tUInt32 Chan; pwr_tString80 NewName; if (Class != pwr_cClass_ChanDo) return PWRB__SUCCESS; sts = ldh_ReadObjectBody(Session, Card, "RtBody", &RCard, sizeof(RCard)); if (EVEN(sts)) return PWRB__SUCCESS; sts = ldh_ReadObjectBody(Session, Card, "DevBody", &DCard, sizeof(DCard)); if (EVEN(sts)) return PWRB__SUCCESS; MaxChan = co_min(32, RCard.MaxNoOfChannels); /* get attributes of channel NOTE ! this should be done by a method of the channel object, but is not implemented in this version of PROVIEW/R. */ switch (Class) { case pwr_cClass_ChanDo: sts = ldh_ReadObjectBody(Session, Channel, "RtBody", &ChanDo, sizeof(ChanDo)); if (EVEN(sts)) return PWRB__SUCCESS; Chan = ChanDo.Number; break; } /* deallocate channel */ if (Chan > MaxChan) return PWRB__SUCCESS; DCard.ChannelAllocation &= ~(1 << Chan); sts = ldh_SetObjectBody(Session, Card, "DevBody", (char *)&DCard, sizeof(DCard)); if (EVEN(sts)) return PWRB__SUCCESS; sts = ldh_GetUniqueObjectName(Session, Channel, NewName); if (EVEN(sts)) return PWRB__SUCCESS; sts = ldh_SetObjectName(Session, Channel, NewName); if (EVEN(sts)) return PWRB__SUCCESS; return PWRB__SUCCESS; }
/** **************************************************************************************** * @brief app_api function. Project advertising function. Setup advertise string. * * * * @return void. **************************************************************************************** */ void app_adv_func(struct gapm_start_advertise_cmd *cmd) { // Start advertising. Fill GAPM_START_ADVERTISE_CMD message // Device Name Length uint8_t device_name_length; int8_t device_name_avail_space; uint8_t device_name_temp_buf[64]; cmd->op.code = GAPM_ADV_UNDIRECT;//GAPM_ADV_UNDIRECT;//GAPM_ADV_NON_CONN; cmd->op.addr_src = GAPM_PUBLIC_ADDR; cmd->intv_min = APP_ADV_INT_MIN; cmd->intv_max = APP_ADV_INT_MAX; cmd->channel_map = APP_ADV_CHMAP; cmd->info.host.mode = GAP_GEN_DISCOVERABLE; /*----------------------------------------------------------------------------------- * Set the Advertising Data and the Scan Response Data *---------------------------------------------------------------------------------*/ cmd->info.host.adv_data_len = APP_ADV_DATA_MAX_SIZE; cmd->info.host.scan_rsp_data_len = APP_SCAN_RESP_DATA_MAX_SIZE; // Advertising Data #if (NVDS_SUPPORT) if(nvds_get(NVDS_TAG_APP_BLE_ADV_DATA, &cmd->info.host.adv_data_len, &cmd->info.host.adv_data[0]) != NVDS_OK) #endif //(NVDS_SUPPORT) { cmd->info.host.adv_data_len = APP_ADV_DATA_LEN; memcpy(&cmd->info.host.adv_data[0], APP_ADV_DATA, cmd->info.host.adv_data_len); } // Scan Response Data #if (NVDS_SUPPORT) if(nvds_get(NVDS_TAG_APP_BLE_SCAN_RESP_DATA, &cmd->info.host.scan_rsp_data_len, &cmd->info.host.scan_rsp_data[0]) != NVDS_OK) #endif //(NVDS_SUPPORT) { cmd->info.host.scan_rsp_data_len = APP_SCNRSP_DATA_LENGTH; memcpy(&cmd->info.host.scan_rsp_data[0], APP_SCNRSP_DATA, cmd->info.host.scan_rsp_data_len); } // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag device_name_avail_space = APP_ADV_DATA_MAX_SIZE - cmd->info.host.adv_data_len - 2; // Check if data can be added to the Advertising data if (device_name_avail_space > 0) { // Get the Device Name to add in the Advertising Data (Default one or NVDS one) #if (NVDS_SUPPORT) device_name_length = NVDS_LEN_DEVICE_NAME; if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK) #endif //(NVDS_SUPPORT) { // Get default Device Name (No name if not enough space) device_name_length = strlen(APP_DEVICE_NAME); memcpy(&device_name_temp_buf[0], APP_DEVICE_NAME, device_name_length); } if(device_name_length > 0) { // Check available space device_name_length = co_min(device_name_length, device_name_avail_space); // Fill Length cmd->info.host.adv_data[cmd->info.host.adv_data_len] = device_name_length + 1; // Fill Device Name Flag cmd->info.host.adv_data[cmd->info.host.adv_data_len + 1] = '\x09'; // Copy device name memcpy(&cmd->info.host.adv_data[cmd->info.host.adv_data_len + 2], device_name_temp_buf, device_name_length); // Update Advertising Data Length cmd->info.host.adv_data_len += (device_name_length + 2); } } #ifdef __DA14581__ if (cmd->op.code == GAPM_ADV_UNDIRECT) arch_adv_int = calculate_arch_adv_time(cmd->info.host.adv_data_len,cmd->info.host.scan_rsp_data_len); else if (cmd->op.code == GAPM_ADV_NON_CONN) arch_adv_int = 500; #endif return; }
static pwr_tStatus PostAdopt ( ldh_tSesContext Session, pwr_tObjid Card, /* current card object */ pwr_tObjid Channel, pwr_tClassId Class /* class of child to adopt */ ) { pwr_tStatus sts; pwr_sClass_Do_HVDO32 RCard; pwr_sdClass_Do_HVDO32 DCard; pwr_sClass_ChanDo ChanDo; pwr_tUInt32 MaxChan; pwr_tUInt32 Chan; pwr_tString80 NewName; pwr_tString80 Description; pwr_tString80 Identity; pwr_tString80 DefName; pwr_sObject DefBody; pwr_tObjid DefObject; int i; if (Class != pwr_cClass_ChanDo) return PWRB__CHANCLASS; sts = ldh_ReadObjectBody(Session, Card, "RtBody", &RCard, sizeof(RCard)); if (EVEN(sts)) return sts; sts = ldh_ReadObjectBody(Session, Card, "DevBody", &DCard, sizeof(DCard)); if (EVEN(sts)) return sts; MaxChan = co_min(32, RCard.MaxNoOfChannels); for (i = 0, Chan = 1; i < (int)MaxChan; i++, Chan <<= 1) { if ((DCard.ChannelAllocation & Chan) == 0) break; } if (i >= (int)MaxChan) return PWRB__ALOCHAN; /* allocate new channel */ DCard.ChannelAllocation |= Chan; sts = ldh_SetObjectBody(Session, Card, "DevBody", (char *)&DCard, sizeof(DCard)); if (EVEN(sts)) return sts; /* change attributes of channel NOTE ! this should be done by a method of the channel object, but is not implemented in this version of PROVIEW/R. */ switch (Class) { case pwr_cClass_ChanDo: sts = ldh_ReadObjectBody(Session, Channel, "RtBody", &ChanDo, sizeof(ChanDo)); if (EVEN(sts)) return sts; if (ChanDo.Description[0] != '\0') { sprintf(Description, ChanDo.Description, i); if (strlen(Description) <= sizeof(ChanDo.Description) - 1) { strcpy(ChanDo.Description, Description); } } if (ChanDo.Identity[0] != '\0') { sprintf(Identity, ChanDo.Identity, i); if (strlen(Identity) <= sizeof(ChanDo.Identity) - 1) { strcpy(ChanDo.Identity, Identity); } } ChanDo.Number = i; sts = ldh_SetObjectBody(Session, Channel, "RtBody", (char *)&ChanDo, sizeof(ChanDo)); strcpy(DefName, "pwrb:Class-ChanDo-Defaults"); break; } /* change name of channel */ sts = ldh_NameToObjid(Session, &DefObject, DefName); if (EVEN(sts)) return PWRB__SUCCESS; sts = ldh_ReadObjectBody(Session, DefObject, "SysBody", &DefBody, sizeof(DefBody)); if (DefBody.Name[0] != '\0') { sprintf(NewName, DefBody.Name, i+1); NewName[31] = '\0'; sts = ldh_SetObjectName(Session, Channel, NewName); } return PWRB__SUCCESS; }