Timeline for Reading bits from a const char pointer
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 23, 2021 at 2:57 | vote | accept | Chris Schmitz | ||
| Feb 22, 2021 at 19:48 | answer | added | Edgar Bonet | timeline score: 1 | |
| Feb 22, 2021 at 17:31 | comment | added | Chris Schmitz | @Juraj those are the message formats that the library I'm using gives me. There's not an option for just a buffer of bytes. I would think that the c-string is the equivalent of the buffer, but there's the null terminator issue. | |
| Feb 22, 2021 at 17:27 | comment | added | Juraj♦ | it looks like a X->Y problem. "I'm getting a message from a server that comes through as either a c style string, a standard library string, or a WString" why? | |
| Feb 22, 2021 at 17:03 | comment | added | dandavis | might have to hex encode the values to transmit them. | |
| Feb 22, 2021 at 16:52 | review | Close votes | |||
| Mar 10, 2021 at 3:04 | |||||
| Feb 22, 2021 at 16:23 | comment | added | timemage |
Well, "c-string" basically means zero or more non-'\0' followed by '\0'. If any of your numbers happen to have a zero byte in them, that will terminate the "string" before the end of your actual data. E.g. 0xAA00BB. It's really just not a string at all. In terms of how you get the data out of it, if it's properly aligned for uint32_t, you can just const uint32_t *ui32p = reinterpret_cast<const uint32_t *>(mycharptr); If it's not aligned, you would do something like memcpy it into an array or individual elements into a single uint32_t variable. There's nothing really "Arduino" here.
|
|
| Feb 22, 2021 at 16:16 | comment | added | Chris Schmitz | but yeah, data is a c-string of bytes and I know that I want to interpret it as 32 bit integers, I just can't figure out how to do it. | |
| Feb 22, 2021 at 16:15 | comment | added | Chris Schmitz |
Oh, I just mean data (the const char *) holds bits in it that can't be Serial.println-ed because because even in 8 bit form they're not ascii/utf valid characters so nothing goes to the monitor.
|
|
| Feb 22, 2021 at 15:47 | comment | added | timemage |
"they're just bit values". You mean, they're just uint32_t that are being pointed at with a const char * ?
|
|
| Feb 22, 2021 at 15:36 | history | asked | Chris Schmitz | CC BY-SA 4.0 |