JoGe
JoGe

Reputation: 126

Convert WORD to string

I'm trying to send a CAN message using WiFi.

The message is composed of a 2 byte ID (WORD) and a 8 byte data field (QWORD).

I have to write the packet to the WiFi chip using UART so I want to convert the WORD and QWORD to a string and then use putsUART to send it.

How can I convert those variables to a string?

Struct of the WiFi packet:

typedef struct {
    WORD id;
    QWORD data;
} WiFiTXPacket;

Upvotes: 0

Views: 3111

Answers (3)

syler
syler

Reputation: 126

char *package = (char *)&wifiPackage;
putsUART(package, sizeof (WiFiTXPacket)); 

Depend on Gossamer's answer. I think it could be like this. if use memcpy function. and calculate with strlen(packeage). if there any zero value. may cause problem happened!

Upvotes: 1

corny
corny

Reputation: 7852

printf("id: %hu  data: %llu \n", id, data); 

Upvotes: 1

Gossamer
Gossamer

Reputation: 309

Maybe something like this:

char package[10];
memcpy (&package, &wifiPackage, sizeof (WiFiTXPacket));

putsUART(package, strlen(package)); // i dont know how this function looks like, but for example ...

Upvotes: 2

Related Questions