-
Notifications
You must be signed in to change notification settings - Fork 498
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]); | ||
} else { | ||
chars.setFixedLen(strlen(_strarr[i])); | ||
} | ||
VERIFY_STATUS( chars.begin() ); | ||
chars.write(_strarr[i]); | ||
if (_strarr_length[i]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for using this API with length, I would suggest to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right.