Arduino Asked by Sicks on September 25, 2021
Hello I’m trying to send some Structs such as:
typedef struct __attribute__ ((__packed__)) myohw_command_set_mode {
myohw_command_header_t header; ///< command == myohw_command_set_mode. payload_size = 3.
uint8_t emg_mode; ///< EMG sensor mode. See myohw_emg_mode_t.
uint8_t imu_mode; ///< IMU mode. See myohw_imu_mode_t.
uint8_t classifier_mode; ///< Classifier mode. See myohw_classifier_mode_t.
} myohw_command_set_mode_t;
To another device via BLE using the Arduino BLE library.
I have the services and characteristics all set up correctly.
My problem is that arduino BLE .writeValue() function expects some specific formats and i’m not quite sure the best way to convert this struct to one of them.
int writeValue(const uint8_t value[], int length);
int writeValue(const void* value, int length);
int writeValue(const char* value);
int writeValue(uint8_t value);
int writeValue(int8_t value);
int writeValue(uint16_t value);
int writeValue(int16_t value);
int writeValue(uint32_t value);
int writeValue(int32_t value);
What format should i use? And what is the best way to cast the Struct to the format?
Thanks,
What format should i use?
int writeValue(const uint8_t value[], int length);
And what is the best way to cast the Struct to the format?
writeValue((uint8_t *)&myStruct, sizeof(myStruct));
Correct answer by Majenko on September 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP