c - Convert double to uint8_t* -
i have function accepts uint8_t* supposed string. want send double function. have tried code below doesn't work.
double = 10.98 uint8_t* p = (uint8_t*) &a; printf("p: %u \n", p); send_data(p);
but code below works, want replace string "90" double variable above.
static const char *data[6]; data[0] = "90"; static uint8_t *test; test = ( unsigned char *) data[datacounter] ; send_data(test);
so mean doesn't work function send_data supposed send string on bluetooth android phone. if first sample code, string passed correctly.
note: i think possibly because of difference in data types being passed second argument. function expecting 3 arguments.
static uint32_t send_data(uint8_t data[]){ return ble_nus_string_send(&m_nus, data, 5); }
this function defintion:
uint32_t ble_nus_string_send (ble_nus_t * p_nus,uint8_t * p_string, uint16_t length )
there 2 different things might mean "sending double string". might mean "send actual existing bytes of double array of bytes" (in other words, send 4.5 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x40}), or might mean "send textual representation of double string (iow, send 4.5 "4.5"). former case be:
double d = 4.5; ble_nus_string_send(&m_nus, (uint8_t *)(&d), 8);
this not want, since app sending must expecting same way, same endianness, same floating point representation, etc. want second case:
double d = 4.5; char temp[20]; snprintf(temp, 20, "%g", d); ble_nus_string_send(&m_nus, (uint8_t *)temp, strlen(temp));
Comments
Post a Comment