Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Device Informations for ble #336

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 122 additions & 9 deletions libraries/Bluefruit52Lib/src/services/BLEDis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,51 +51,164 @@ BLEDis::BLEDis(void)
_hardware_rev = NULL;
_software_rev = ARDUINO_BSP_VERSION;
_manufacturer = "Adafruit Industries";
_system_id = NULL;
_reg_cert_list = NULL;
_pnp_id = NULL;
}

void BLEDis::setFirmwareRev(const char* firmware_rev)
{
_firmware_rev = firmware_rev;
_firmware_rev_length = strlen(firmware_rev);
}
void BLEDis::setFirmwareRev(const char* firmware_rev, uint8_t length)
{
_firmware_rev = firmware_rev;
_firmware_rev_length = length;
}

void BLEDis::setSerialNum(const char* serial_num)
{
_serial = serial_num;
_serial_length = strlen(serial_num);
}
void BLEDis::setSerialNum(const char* serial_num, uint8_t length)
{
_serial = serial_num;
_serial_length = length;
}

void BLEDis::setSystemID(const char* system_id)
{
_system_id = system_id;
_system_id_length = strlen(system_id);
}
void BLEDis::setSystemID(const char* system_id, uint8_t length)
{
_system_id = system_id;
_system_id_length = length;
}

void BLEDis::setRegCertList(const char* reg_cert_list)
{
_reg_cert_list = reg_cert_list;
_reg_cert_list_length = strlen(reg_cert_list);
}
void BLEDis::setRegCertList(const char* reg_cert_list, uint8_t length)
{
_reg_cert_list = reg_cert_list;
_reg_cert_list_length = length;
}

void BLEDis::setPNPID(const char* pnp_id)
{
_pnp_id = pnp_id;
_pnp_id_length = strlen(pnp_id);
}
void BLEDis::setPNPID(const char* pnp_id, uint8_t length)
{
_pnp_id = pnp_id;
_pnp_id_length = length;
}
void BLEDis::setModel(const char* model,uint8_t length)
{
_model = model;
_model_length = length;
}

void BLEDis::setHardwareRev(const char* hw_rev,uint8_t length)
{
_hardware_rev = hw_rev;
_hardware_rev_length = length;
}

void BLEDis::setSoftwareRev(const char* sw_rev, uint8_t length)
{
_software_rev = sw_rev;
_software_rev_length = length;
}

void BLEDis::setManufacturer(const char* manufacturer, uint8_t length)
{
_manufacturer = manufacturer;
_manufacturer_length = length;
}

void BLEDis::setModel(const char* model)
{
_model = model;
_model_length = strlen(model);
}

void BLEDis::setHardwareRev(const char* hw_rev)
{
_hardware_rev = hw_rev;
_hardware_rev_length = strlen(hw_rev);
}

void BLEDis::setSoftwareRev(const char* sw_rev)
{
_software_rev = sw_rev;
_software_rev_length = strlen(sw_rev);
}

void BLEDis::setManufacturer(const char* manufacturer)
{
_manufacturer = manufacturer;
_manufacturer_length = strlen(manufacturer);
}

err_t BLEDis::begin(void)
{
// Invoke base class begin()
VERIFY_STATUS( BLEService::begin() );

_serial = getMcuUniqueID();
_firmware_rev = getBootloaderVersion();
if(!_serial) {
_serial = getMcuUniqueID();
}
if (!_firmware_rev) {
_firmware_rev = getBootloaderVersion();
}

for(uint8_t i=0; i<arrcount(_strarr); i++)
for(uint8_t i=0; i<arrcount(_strarr)-1; i++) // without PNP_ID
{
if ( _strarr[i] != NULL )
{
BLECharacteristic chars(UUID16_CHR_MODEL_NUMBER_STRING+i);
BLECharacteristic chars(UUID16_CHR_SYSTEM_ID+i);
chars.setTempMemory();

chars.setProperties(CHR_PROPS_READ);
chars.setFixedLen(strlen(_strarr[i]));

if (_strarr_length[i]) {
chars.setFixedLen(_strarr_length[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. should only use the _strarr_legnth[i], there is no point to use the strlen() function anymore.

Copy link
Contributor Author

@elral elral Sep 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

} else {
chars.setFixedLen(strlen(_strarr[i]));
}
VERIFY_STATUS( chars.begin() );
chars.write(_strarr[i]);
if (_strarr_length[i]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

@elral elral Sep 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

chars.write(_strarr[i], _strarr_length[i]);
} else {
chars.write(_strarr[i]);
}

}
}

if ( _strarr[arrcount(_strarr)-1] != NULL )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I am not familliar with PNP_ID, but why this characteristic isn't included in the above loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last characteristic from the loop is 0x2A2A (IEEE_REGULATORY_CERTIFICATION), PNP_ID is 0x2A50. So there is a big gap between last entry from loop and PNP_ID. I had no better idea than to do it seperatly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see the reason now.

{
BLECharacteristic chars(UUID16_CHR_PNP_ID);
chars.setTempMemory();
chars.setProperties(CHR_PROPS_READ);
if (_pnp_id_length == 0) {
chars.setFixedLen(strlen(_strarr[arrcount(_strarr)-1]));
} else {
chars.setFixedLen(_pnp_id_length);
}
VERIFY_STATUS( chars.begin() );
if (_pnp_id_length == 0) {
chars.write(_strarr[arrcount(_strarr)-1]);
} else {
chars.write(_strarr[arrcount(_strarr)-1], _pnp_id_length);
}
}

return ERROR_NONE;
}

34 changes: 33 additions & 1 deletion libraries/Bluefruit52Lib/src/services/BLEDis.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,56 @@ class BLEDis : public BLEService
protected:
union {
struct {
const char * _system_id;
const char * _model;
const char * _serial;
const char * _firmware_rev;
const char * _hardware_rev;
const char * _software_rev;
const char * _manufacturer;
const char * _reg_cert_list;
const char * _pnp_id;
};

const char * _strarr[6];
const char * _strarr[9];
};

union {
struct {
uint8_t _system_id_length;
uint8_t _model_length;
uint8_t _serial_length;
uint8_t _firmware_rev_length;
uint8_t _hardware_rev_length;
uint8_t _software_rev_length;
uint8_t _manufacturer_length;
uint8_t _reg_cert_list_length;
uint8_t _pnp_id_length;
};
const uint8_t _strarr_length[9];
};

public:
BLEDis(void);

void setModel(const char* model);
void setModel(const char* model,uint8_t length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for using this API with length, I would suggest to

  1. change the type of 1st parameter to const uint8_t* e.g setModel(const uint8_t model, uint8_t length)
  2. also please implement the const char* as inline function as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, you are right. Then inside function it must be "_model = (const char*)model;"
  2. Sorry, I don't know what to change, or do you mean "_model = (const char*)model;"

void setHardwareRev(const char* hw_rev);
void setHardwareRev(const char* hw_rev,uint8_t length);
void setSoftwareRev(const char* sw_rev);
void setSoftwareRev(const char* sw_rev, uint8_t length);
void setManufacturer(const char* manufacturer);
void setManufacturer(const char* manufacturer, uint8_t length);
void setFirmwareRev(const char* firmware_rev);
void setFirmwareRev(const char* firmware_rev, uint8_t length);
void setSerialNum(const char* serial_num);
void setSerialNum(const char* serial_num, uint8_t length);
void setSystemID(const char* system_id);
void setSystemID(const char* system_id, uint8_t length);
void setRegCertList(const char* reg_cert_list);
void setRegCertList(const char* reg_cert_list, uint8_t length);
void setPNPID(const char* pnp_id);
void setPNPID(const char* pnp_id, uint8_t pnp_id_length);

virtual err_t begin(void);
};
Expand Down