-
Notifications
You must be signed in to change notification settings - Fork 7.7k
BLE: BLECharacteristic::setValue()
cleanup and optimization
#11751
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
base: master
Are you sure you want to change the base?
Changes from all commits
5653eb6
c6517e4
273eedf
5edf464
73ccce2
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 | ||||
---|---|---|---|---|---|---|
|
@@ -346,7 +346,7 @@ void BLECharacteristic::setReadProperty(bool value) { | |||||
* @param [in] data The data to set for the characteristic. | ||||||
* @param [in] length The length of the data in bytes. | ||||||
*/ | ||||||
void BLECharacteristic::setValue(uint8_t *data, size_t length) { | ||||||
void BLECharacteristic::setValue(const uint8_t *data, size_t length) { | ||||||
// The call to BLEUtils::buildHexData() doesn't output anything if the log level is not | ||||||
// "VERBOSE". As it is quite CPU intensive, it is much better to not call it if not needed. | ||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE | ||||||
|
@@ -371,43 +371,28 @@ void BLECharacteristic::setValue(uint8_t *data, size_t length) { | |||||
* @param [in] Set the value of the characteristic. | ||||||
* @return N/A. | ||||||
*/ | ||||||
void BLECharacteristic::setValue(String value) { | ||||||
setValue((uint8_t *)(value.c_str()), value.length()); | ||||||
void BLECharacteristic::setValue(const String &value) { | ||||||
setValue(reinterpret_cast<const uint8_t *>(value.c_str()), value.length()); | ||||||
} // setValue | ||||||
|
||||||
void BLECharacteristic::setValue(uint16_t &data16) { | ||||||
uint8_t temp[2]; | ||||||
temp[0] = data16; | ||||||
temp[1] = data16 >> 8; | ||||||
setValue(temp, 2); | ||||||
void BLECharacteristic::setValue(uint16_t data16) { | ||||||
setValue(reinterpret_cast<uint8_t *>(&data16), sizeof(data16)); | ||||||
} // setValue | ||||||
|
||||||
void BLECharacteristic::setValue(uint32_t &data32) { | ||||||
uint8_t temp[4]; | ||||||
temp[0] = data32; | ||||||
temp[1] = data32 >> 8; | ||||||
temp[2] = data32 >> 16; | ||||||
temp[3] = data32 >> 24; | ||||||
setValue(temp, 4); | ||||||
void BLECharacteristic::setValue(uint32_t data32) { | ||||||
setValue(reinterpret_cast<uint8_t *>(&data32), sizeof(data32)); | ||||||
} // setValue | ||||||
|
||||||
void BLECharacteristic::setValue(int &data32) { | ||||||
uint8_t temp[4]; | ||||||
temp[0] = data32; | ||||||
temp[1] = data32 >> 8; | ||||||
temp[2] = data32 >> 16; | ||||||
temp[3] = data32 >> 24; | ||||||
setValue(temp, 4); | ||||||
void BLECharacteristic::setValue(int data32) { | ||||||
setValue(reinterpret_cast<uint8_t *>(&data32), sizeof(data32)); | ||||||
} // setValue | ||||||
|
||||||
void BLECharacteristic::setValue(float &data32) { | ||||||
float temp = data32; | ||||||
setValue((uint8_t *)&temp, 4); | ||||||
void BLECharacteristic::setValue(float data32) { | ||||||
setValue(reinterpret_cast<uint8_t *>(&data32), sizeof(data32)); | ||||||
} // setValue | ||||||
|
||||||
void BLECharacteristic::setValue(double &data64) { | ||||||
double temp = data64; | ||||||
setValue((uint8_t *)&temp, 8); | ||||||
void BLECharacteristic::setValue(double data64) { | ||||||
setValue(reinterpret_cast<uint8_t *>(&data64), sizeof(data64)); | ||||||
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. Casting away const from a value parameter creates undefined behavior. The data32 parameter is passed by value, so &data32 points to a temporary that will be destroyed. Use reinterpret_cast<const uint8_t *> and ensure the underlying setValue method can handle const data. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. Casting away const from a value parameter creates undefined behavior. The data32 parameter is passed by value, so &data32 points to a temporary that will be destroyed. Use reinterpret_cast<const uint8_t *> and ensure the underlying setValue method can handle const data. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. Casting away const from a value parameter creates undefined behavior. The data32 parameter is passed by value, so &data32 points to a temporary that will be destroyed. Use reinterpret_cast<const uint8_t *> and ensure the underlying setValue method can handle const data. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. Casting away const from a value parameter creates undefined behavior. The data64 parameter is passed by value, so &data64 points to a temporary that will be destroyed. Use reinterpret_cast<const uint8_t *> and ensure the underlying setValue method can handle const data.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} // setValue | ||||||
|
||||||
/** | ||||||
|
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.
Casting away const from a value parameter creates undefined behavior. The data16 parameter is passed by value, so &data16 points to a temporary that will be destroyed. Use reinterpret_cast<const uint8_t *> and ensure the underlying setValue method can handle const data.
Copilot uses AI. Check for mistakes.