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?
 

nbb3i

Newbie level 5
Joined
Dec 27, 2007
Messages
9
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,318
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;
}
}

}
 

Магсоѕ

Newbie level 1
Joined
May 15, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Nicaragua
Activity points
4
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.
 

doraemon

Super Moderator
Staff member
Joined
Jun 21, 2009
Messages
1,112
Helped
282
Reputation
572
Reaction score
260
Trophy points
1,363
Location
Japan
Activity points
11,136
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
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,454
Helped
295
Reputation
590
Reaction score
278
Trophy points
1,363
Location
France 01800
Activity points
10,301
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top