PDA

View Full Version : Defining data format in c++



locus
24th March 2007, 07:34
I would like to transmit a stream of bits formatted to my liking, between two PCs, i already have a serial conection betwen them which will allow me to transmit data; an array with a string ("hello world") for example.

My problem is i don't have any idea as to how to go about defining the format, so that both PCs can parse it and pick out relevant information.

I think need to know how to create and send a binary frame, example:

start_bit + character + stop_bit; where the character will inclued the parity bit

I also need to know how to implement data identification, as i am sendng different types of information:

example; at one point i may need to send, say, user_information;
which may include user_name, user_password etc.

and at another time i may want to send somthing else, like, say,
system_info; which may include system_status, number_of_users, ect.

basically, the recieving PC must be able to tell:

1) what data is being sent: user or system info

2) if its user info, where does user_name stop, and user_password begin, and where does the whole user_info stop.

Does anyone know how i can implement this?

I am using MS visual studio .NET 2003 and programmng in C++. Along wit the qt VS .NET 2003 integration.

If you can give some suggstions or direct me to some resource that covers this kind of thing, i would be most greatful.

Thanks very much for your attention

You are invited to be as generous as possible with your sugestions.
All suggestions welcomed.

wysota
24th March 2007, 10:16
I'd suggest to use some platform independent solution, like ASN.1 - all the parsing and stuff would be made automatically then.

locus
13th April 2007, 19:46
Thanks wysota for that info on the ASN1 encoding form.
I tried it and it works well, and i am using it in my project.

I have read that:


ASN expresses only syntax (data types), not semantics

could you tell me in what context the word
semantics is being used here?

See i aside from data i need to transfer a small .WAV
file, and from the quote above i am guessing that ASN cannot encode the file for me.

I am trying to find some easy to use encoding form that will enable me to send the file.

I am not confining myself to using an encoding, any suggestions for sending the file is welcomed. I am sending my data via COM port between the two computers.

Thanks for your help so far, i really appreciate it.

wysota
13th April 2007, 20:40
could you tell me in what context the word is being used here?
"Grammar". It means the encoding carries no meaning with the data. It is only a container for data.


file, and from the quote above i am guessing that ASN cannot encode the file for me.

You're wrong then. It'll do just fine with binary data. It just means it won't treat it specially because it's a WAV file or it won't be able to convert it to MP3, etc. It'll just be a blob of data.


I am not confining myself to using an encoding, any suggestions for sending the file is welcomed. I am sending my data via COM port between the two computers.
You always use some form of encoding. It's just your decision which one to choose. If you just need to send a WAV file over a cable, you don't need to use ASN.1. But if you want to send some other things like numbers, characters, etc. in a platform independent way then ASN.1 might prove helpful.