I am trying to take an integer argument (1-65536) and turn it into two hex characters. If argument -t is -t20 then I need 0x01 0x04 in a character array for sending through a socket.
Relavent snippets:
char tstr[3];
char timetxt[6];
struct pulsepayload {
char chan;
char state;
char width[2];
} pp;
....
// get the arguments
case 't': // if -t then do pulse command
cmd0 = 0x07;
strcpy(timetxt, &argv[1][2]);
// put some magic here to get
// tstr[0] = 0x05; // forcing 5 sec here
// tstr[1] = 0x00;
// when -t5
.....
// Populate the payload
pp.chan = cnl;
pp.state = st;
pp.width[0] = tstr[0];
pp.width[1] = tstr[1];
pdata = &pp;
char *paylp = (char*)pdata;
.....
// combine header and payload and send
printf("pulse command: to State %d, time %d \n ",st, tstr[1]);
strcat(command, paylp);
bytesSent = send(m_socket, command, 51, 0);
Thanks in advance.