@@ -346,7 +346,7 @@ void BLECharacteristic::setReadProperty(bool value) {
346346 * @param [in] data The data to set for the characteristic.
347347 * @param [in] length The length of the data in bytes.
348348 */
349- void BLECharacteristic::setValue (uint8_t *data, size_t length) {
349+ void BLECharacteristic::setValue (const uint8_t *data, size_t length) {
350350// The call to BLEUtils::buildHexData() doesn't output anything if the log level is not
351351// "VERBOSE". As it is quite CPU intensive, it is much better to not call it if not needed.
352352#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
@@ -371,43 +371,28 @@ void BLECharacteristic::setValue(uint8_t *data, size_t length) {
371371 * @param [in] Set the value of the characteristic.
372372 * @return N/A.
373373 */
374- void BLECharacteristic::setValue (String value) {
375- setValue (( uint8_t *) (value.c_str ()), value.length ());
374+ void BLECharacteristic::setValue (const String & value) {
375+ setValue (reinterpret_cast < const uint8_t *> (value.c_str ()), value.length ());
376376} // setValue
377377
378- void BLECharacteristic::setValue (uint16_t &data16) {
379- uint8_t temp[2 ];
380- temp[0 ] = data16;
381- temp[1 ] = data16 >> 8 ;
382- setValue (temp, 2 );
378+ void BLECharacteristic::setValue (uint16_t data16) {
379+ setValue (reinterpret_cast <const uint8_t *>(&data16), sizeof (data16));
383380} // setValue
384381
385- void BLECharacteristic::setValue (uint32_t &data32) {
386- uint8_t temp[4 ];
387- temp[0 ] = data32;
388- temp[1 ] = data32 >> 8 ;
389- temp[2 ] = data32 >> 16 ;
390- temp[3 ] = data32 >> 24 ;
391- setValue (temp, 4 );
382+ void BLECharacteristic::setValue (uint32_t data32) {
383+ setValue (reinterpret_cast <const uint8_t *>(&data32), sizeof (data32));
392384} // setValue
393385
394- void BLECharacteristic::setValue (int &data32) {
395- uint8_t temp[4 ];
396- temp[0 ] = data32;
397- temp[1 ] = data32 >> 8 ;
398- temp[2 ] = data32 >> 16 ;
399- temp[3 ] = data32 >> 24 ;
400- setValue (temp, 4 );
386+ void BLECharacteristic::setValue (int data32) {
387+ setValue (reinterpret_cast <const uint8_t *>(&data32), sizeof (data32));
401388} // setValue
402389
403- void BLECharacteristic::setValue (float &data32) {
404- float temp = data32;
405- setValue ((uint8_t *)&temp, 4 );
390+ void BLECharacteristic::setValue (float data32) {
391+ setValue (reinterpret_cast <const uint8_t *>(&data32), sizeof (data32));
406392} // setValue
407393
408- void BLECharacteristic::setValue (double &data64) {
409- double temp = data64;
410- setValue ((uint8_t *)&temp, 8 );
394+ void BLECharacteristic::setValue (double data64) {
395+ setValue (reinterpret_cast <const uint8_t *>(&data64), sizeof (data64));
411396} // setValue
412397
413398/* *
0 commit comments