A
andy.dreistadt
Hi all,
I came across another problem that is probably pretty easy but, again,
due to my rusty-ness with C, I'm a little stumped.
I have a struct that looks like this:
/* Instrument Data structure */
struct instrument_info
{
int ID;
char serial[30];
char type[30];
char model[30];
char name[30];
char location[30];
char last_calibration[30];
char calibration_results[10];
};
and and array of these structs as follows:
/* Instrument Data structure array*/
struct instrument_info instrument_array[MAX_INSTRUMENTS];
My question is this:
My program is communicating through UDP packets to a remote Java
program. I need to take the char arrays from the struct above and
place them into a byte buffer so they may be transferred in the UDP
packet. I need the end buffer to look something like this:
"ID,serial,type,model,name,location,last_calilbration,calibration_results;ID,serial,type...."
So that a comma is the attribute delimeter, while the semicolon is the
instrument delimeter.
In Java the answer would be something along the lines of:
String send_buf = "";
for(int i = 0; i<=num_inst; i++)
{
send_buf += instrument_array.ID + ",";
send_buf += instrument_array.serial + ",";
send_buf += instrument_array.type + ",";
send_buf += instrument_array.model + ",";
send_buf += instrument_array.name + ",";
send_buf += instrument_array.location + ",";
send_buf += instrument_array.last_calibration + ",";
send_buf += instrument_array.calibration_results + ";";
}
byte[] send_bytes = send_buf.getBytes();
Due to my lack of C knowledge, I was wondering if anyone out there
could help.
Thanks in advance,
Andy
I came across another problem that is probably pretty easy but, again,
due to my rusty-ness with C, I'm a little stumped.
I have a struct that looks like this:
/* Instrument Data structure */
struct instrument_info
{
int ID;
char serial[30];
char type[30];
char model[30];
char name[30];
char location[30];
char last_calibration[30];
char calibration_results[10];
};
and and array of these structs as follows:
/* Instrument Data structure array*/
struct instrument_info instrument_array[MAX_INSTRUMENTS];
My question is this:
My program is communicating through UDP packets to a remote Java
program. I need to take the char arrays from the struct above and
place them into a byte buffer so they may be transferred in the UDP
packet. I need the end buffer to look something like this:
"ID,serial,type,model,name,location,last_calilbration,calibration_results;ID,serial,type...."
So that a comma is the attribute delimeter, while the semicolon is the
instrument delimeter.
In Java the answer would be something along the lines of:
String send_buf = "";
for(int i = 0; i<=num_inst; i++)
{
send_buf += instrument_array.ID + ",";
send_buf += instrument_array.serial + ",";
send_buf += instrument_array.type + ",";
send_buf += instrument_array.model + ",";
send_buf += instrument_array.name + ",";
send_buf += instrument_array.location + ",";
send_buf += instrument_array.last_calibration + ",";
send_buf += instrument_array.calibration_results + ";";
}
byte[] send_bytes = send_buf.getBytes();
Due to my lack of C knowledge, I was wondering if anyone out there
could help.
Thanks in advance,
Andy