Chandra V
asked on
Experts Question
In my communication protocl application a want to use a modulus 128 operation which is as follows
I have a variable 'sequence_no' which comes from communication packet.
I have to verify in my function whether the 'sequence_no' is previously received or not.
For this operation here is an algorithm
unsigned char current_no; // This my applications global variable
if(sequence_no<=(current_n o-1))
// packet is already received
else if( sequence_no >= current_no)
{
// receive packet
current_no ++;
current_no %= 128; // I have to round off to '0' when number equals 128
}
else
// invalid packet(misalignment)
The above works fine for 0-127
My problem is, when the 'sequence_no = 127' if i receive the same packet twice for the first time it validates TRUE,
but for the second time the current_no rounds off to '0' and the condition "sequence_no<=(current_no- 1)" fails.
Can any one suggest a solution to above?
If there is any difficuly in understanding question please comment..
I have a variable 'sequence_no' which comes from communication packet.
I have to verify in my function whether the 'sequence_no' is previously received or not.
For this operation here is an algorithm
unsigned char current_no; // This my applications global variable
if(sequence_no<=(current_n
// packet is already received
else if( sequence_no >= current_no)
{
// receive packet
current_no ++;
current_no %= 128; // I have to round off to '0' when number equals 128
}
else
// invalid packet(misalignment)
The above works fine for 0-127
My problem is, when the 'sequence_no = 127' if i receive the same packet twice for the first time it validates TRUE,
but for the second time the current_no rounds off to '0' and the condition "sequence_no<=(current_no-
Can any one suggest a solution to above?
If there is any difficuly in understanding question please comment..
use a long variable, use %128 when sending but keep the entire variable for your use.
if you can't do this you might also check the absolute value of the difference between 'sequence_no' and 'current_no' if it's bigger the 128/2 then you know you have to add 128 and then test your condition...
if you can't do this you might also check the absolute value of the difference between 'sequence_no' and 'current_no' if it's bigger the 128/2 then you know you have to add 128 and then test your condition...
is it that simple - are you sure that your packets always arrive in sequence (although possibly duplicated)?
If they can also arrive out of sequence then you need a map of those already received (in which case, this problem goes away & another replaces it).
Most telecommunications protocols allow for out of sequence reception.
If they can also arrive out of sequence then you need a map of those already received (in which case, this problem goes away & another replaces it).
Most telecommunications protocols allow for out of sequence reception.
ASKER
Hai graham_k,
You have guessed correctly. I have to support out of sequence_number reception also for the current windows size (i.e, 4).
Can you suggest some solution?
You have guessed correctly. I have to support out of sequence_number reception also for the current windows size (i.e, 4).
Can you suggest some solution?
ASKER
Hai graham_k,
You have guessed correctly. I have to support out of sequence_number reception also for the current windows size (i.e, 4).
Can you suggest some solution?
You have guessed correctly. I have to support out of sequence_number reception also for the current windows size (i.e, 4).
Can you suggest some solution?
well, for a start, that means that you need to have an array of [window size], with the receive status of each frame.
I obviously can't post commercial source code here. But consider something like ...
- at start of transmission, set all to not received
- when a frame is received ...
if (abs(received frame # - expect frame #) > window size))
{
frame is wildly out of sequence. E.g windows size is 64 and are expecting frame # 12, but receivef # 101 or are expecting # 99 and received # 3
ignore frame & return;
}
if (received number < expected)
simple out of sequence frame, just set array entry to received and store the frame data
else
if (received number == expected)
expected = (expected + 1) mod window size
shuffle all window status up one
set frame receive status
else
// we have received a higher frame # than expected
set frame receive status
don't change value of next expected frame
Now - this is all off the top of my head & I haven't looked at the code in some time, but it might give you a rough idea and I can't give you my emploer's code (or even algorithm) anyway.
Also, what do you do if you receive frame #4 saying that it is the final frame & you have previously received # 0,1,2, but not #3? Do you discard all received frames, or do you pad the missing bit with zeros (if frames are of a fixed length)?
You probably also need a similar mechanism for sent frames, where you note which are acknowledged, so that when you don't have anything more to send, you send the oldest unacknowledged frame again. Also, some protocols have times on each frame & if they don't get a timely acknowledgement the conection is released.
Maybe if you say which protocol it is, someone will know more than me & can point you to some source.
I think this one will take some time, though.
best wishes,
Graham
I obviously can't post commercial source code here. But consider something like ...
- at start of transmission, set all to not received
- when a frame is received ...
if (abs(received frame # - expect frame #) > window size))
{
frame is wildly out of sequence. E.g windows size is 64 and are expecting frame # 12, but receivef # 101 or are expecting # 99 and received # 3
ignore frame & return;
}
if (received number < expected)
simple out of sequence frame, just set array entry to received and store the frame data
else
if (received number == expected)
expected = (expected + 1) mod window size
shuffle all window status up one
set frame receive status
else
// we have received a higher frame # than expected
set frame receive status
don't change value of next expected frame
Now - this is all off the top of my head & I haven't looked at the code in some time, but it might give you a rough idea and I can't give you my emploer's code (or even algorithm) anyway.
Also, what do you do if you receive frame #4 saying that it is the final frame & you have previously received # 0,1,2, but not #3? Do you discard all received frames, or do you pad the missing bit with zeros (if frames are of a fixed length)?
You probably also need a similar mechanism for sent frames, where you note which are acknowledged, so that when you don't have anything more to send, you send the oldest unacknowledged frame again. Also, some protocols have times on each frame & if they don't get a timely acknowledgement the conection is released.
Maybe if you say which protocol it is, someone will know more than me & can point you to some source.
I think this one will take some time, though.
best wishes,
Graham
ASKER
Dear graham_k,
Thankyou for your analysation.
I am looking for someone who can give some code.
I need it in developing Protection protocol of my V5.2 Protocol Stack software.
Thankyou for your analysation.
I am looking for someone who can give some code.
I need it in developing Protection protocol of my V5.2 Protocol Stack software.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hey, what's happenin' I kind of like my suggestion. - No comments...?
Questions asked = 10
Grades given = 2
Grades given = 2
ASKER
Good suggession. But I haven't got the actual solution to my problem.
Anyway thanks alot.
Anyway thanks alot.
ASKER
Good suggession. But I haven't got the actual solution to my problem.
Anyway thanks alot.
Anyway thanks alot.
Look up the ranges.