Having some issues understanding program specs

beatdown

n00b
Joined
Apr 21, 2006
Messages
57
So I'm trying to complete this program for a job test that I have - here's part 1 that confuses me.

Parse a simulated incoming data stream, using the provided GetChar() function.
The format for the received data packets are given in the header file.
Validate the data packets and display to the console the received messages.
Provide error handling and recovery for invalid packets.

The simulated data stream is this:
static const char g_TestData[] = {'!', 'R', '0', '1', 'D', '4', '\n' ,
'!', 'W', '0', '2', 'D', 'A', '\n',
'!', 'R', '0', '2', '3', '0', '8', '\n',
'!', 'W', '1', 'A', '9', '\n'};

So thats great, I used their GetChar function to display that on the screen...I guess thats all I need to for the first part but what the heck do I need to do to validate the packets and do error handling? Basically every '!' is a new packet then its either 'R' or 'W' for read or write then a variable length of data in ASCII chars ending with the '\n' char. I've never had to do anything quite like this especially relating to data validation and error handling of packets...anyone got a clue?
 
If I answer this, does this mean I get the job? :p I don't understand where the confusion is. If you know the format of a valid packet, then that's how you validate the packets. Error handling is just the usual stuff. Be sure to cover all your bases.

No offense, but this is like first semester CS stuff. If you are having trouble on part 1 of the test, then I don't know how well you will do at that job.
 
in real life you dont just get to look at the real data packet...i think they are looking for some hamming code or something to detect and fix errors.
 
beatdown said:
in real life you dont just get to look at the real data packet...i think they are looking for some hamming code or something to detect and fix errors.
Validation is not the same as error detection. Validation is simply making sure the packet looks like what it should look like. You could have a valid packet with a garbage payload. Besides, are you just going to pick some arbitrary error detection/correction scheme and try to apply it to the packets on the receiving end? The given packets have no error detection data. How are you going to know when you have an error or not? I think it's too big of an assumption to add a checksum or something to the packets; it would change the problem too much.
 
ok guys i was really dumb - i was just missing the description saying part of the data is a checksum but even though i can follow checksum examples online these make absolutely no sense. Heres the data format according to the program:

/* DATA PACKET FORMAT:
START: SINGLE ASCII CHAR '!',
ID: SINGLE ASCII CHAR 'R' Read, 'W' Write
DATA: ASCII CHARS VARIABLE LENGTH
CHECKSUM: LAST TWO ASCII HEX CHARS PRIOR TO END CHAR, 8-BIT SUM WITH ROLLOVER,
END CHAR: 'LF' 0x0A */

/*******************************************/
/* SIMULATED SERIAL BUFFERS */
static const char g_TestData[] = {'!', 'R', '0', '1', 'D', '4', '\n' ,
'!', 'W', '0', '2', 'D', 'A', '\n',
'!', 'R', '0', '2', '3', '0', '8', '\n',
'!', 'W', '1', 'A', '9', '\n'};


The bottom part is the data of course...Now lets take the first one for example the data is 01 with a checksum of D4??????? shouldnt the checksum just be 01 as well??? the second packet is 02 with checksum DA ....shouldnt that just be 02 checksum as well?? any way you cut this it makes zero sense. Any ideas?
 
wow i feel dumb for missing that...

I have another issue if anyone can figure out I am supposed to write a function where you can pass a variable length integer like A290 for example and that will be converted into chars like 'A' '2' '9' '0' and put into a buffer without using string functions like atoi or sprinf (but I am provided the funtion to add to their char buffer one char at a time)...I wrote code to to this for up to 5 places but I cant get it to do an integer like 0001 since it gets passed as simply a 1...anyone know I can do this?
 
How do you know it is suppose to be 0001 in the first place? If its suppose to take an int and add it to a buffer I read that as three zeros and a one.

What job is this for btw?
 
We can't help with homework, but you want us to help with an interview question?
 
I dont think it can be done so i moved on and finished...just an firmware position at a local company
 
Back
Top