Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Receiving protocols with no end byte

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
Hi guys,
Normally when we receive a protocol, it will contain a byte (normally: 0x03 or 0x04) to indicate the end of transmission.

But if the protocol have no end byte, how do we know the transmission end?
 

I recommend you using these solution below:
- In case you know your data lenght. You can count the number of bytes that you received. When this number equal your data lenght. You can stop receive data anymore.
- In case you dont know data lenght. You can using timeout to confirm no more data comming.

Example code below:

#define MAX_TIMEOUT 100
void Tick_1ms() {
if (Data_Timeout > 0) {
Data_Timeout--;
if (Data_Timeout == 0) flag_end_tranmission = 1;
}
}
void Receive_Interrupt() {
Data_Timeout = MAX_TIMEOUT;
get_data();
}

void main() {
while (1) {
if (flag_end_tranmission == 1)
{
process_endtransmision();
flag_end_tranmission = 0;
}
}

}
 

Exactly, so general a communication protocol has an indicator of the start and end of the frame. But there are also protocols that have a start, length and end up with a CRC.
 

Hello!

About the length, it depends on what do you mean by knowing le length.
You don't know the length may mean that the length of the message is variable, so you
don't know in advance what the length of the next message will be.
In this case, there are methods to deal with this. Example: the first byte of your
message is the length (Like a Pascal string). This method is very much used in BlueTooth
API from BlueGiga.
But even if one of the bytes is the length of the message, you have to bear in mind that
the transmission might be interrupted (especially in radio). Therefore you also need some
kind of mechanism to reset your system. This can be a timeout.

Dora
 

hello,

you can use a circular buffer witch is deep enough to contains the maximum length of a message.
If you have a gap : silence time beetween each message ,you can use a timeout as an event , to decide
extract the message from the buffer and reinitialise the pointer at the beginning of buffer.

If you have a repetitive or recurent special caratere in your message , like a # or & or <CR> or <LF>
you can decide to extract the message from buffer ,when this special caractere occurs..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top