所以,我过去在大型系统上工作过,比如iso堆栈会话层,这样的东西对于我需要的东西来说太大了,但我确实对大局有一些了解。我现在拥有的是串行点对点通信链路,其中某些组件(通常)正在丢弃数据。
因此,我将不得不编写自己的可靠的交付系统,使用它进行传输。有人能给我指出基本算法的方向吗,或者甚至能给出一个关于它们被称为什么的线索?我尝试了一下谷歌,但最终得到了关于遗传算法之类的研究生理论。我需要最基本的东西。例如10-20行的纯C。
发布于 2012-09-10 22:23:46
在发送端;
///////////////////////////////////////// XBee logging
void dataLog(int idx, int t, float f)
{
ubyte stx[2] = { 0x10, 0x02 };
ubyte etx[2] = { 0x10, 0x03 };
nxtWriteRawHS(stx, 2, 1);
wait1Msec(1);
nxtWriteRawHS(idx, 2, 1);
wait1Msec(1);
nxtWriteRawHS(t, 2, 1);
wait1Msec(1);
nxtWriteRawHS(f, 4, 1);
wait1Msec(1);
nxtWriteRawHS(etx, 2, 1);
wait1Msec(1);
}在接收端
void XBeeMonitorTask()
{
int[] lastTick = Enumerable.Repeat<int>(int.MaxValue, 10).ToArray();
int[] wrapCounter = new int[10];
while (!XBeeMonitorEnd)
{
if (XBee != null && XBee.BytesToRead >= expectedMessageSize)
{
// read a data element, parse, add it to collection, see above for message format
if (XBee.BaseStream.Read(XBeeIncoming, 0, expectedMessageSize) != expectedMessageSize)
throw new InvalidProgramException();
//System.Diagnostics.Trace.WriteLine(BitConverter.ToString(XBeeIncoming, 0, expectedMessageSize));
if ((XBeeIncoming[0] != 0x10 && XBeeIncoming[1] != 0x02) || // dle stx
(XBeeIncoming[10] != 0x10 && XBeeIncoming[11] != 0x03)) // dle etx
{
System.Diagnostics.Trace.WriteLine("recover sync");
while (true)
{
int b = XBee.BaseStream.ReadByte();
if (b == 0x10)
{
int c = XBee.BaseStream.ReadByte();
if (c == 0x03)
break; // realigned (maybe)
}
}
continue; // resume at loop start
}
UInt16 idx = BitConverter.ToUInt16(XBeeIncoming, 2);
UInt16 tick = BitConverter.ToUInt16(XBeeIncoming, 4);
Single val = BitConverter.ToSingle(XBeeIncoming, 6);
if (tick < lastTick[idx])
wrapCounter[idx]++;
lastTick[idx] = tick;
Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => DataAdd(idx, tick * wrapCounter[idx], val)));
}
Thread.Sleep(2); // surely we can up with the NXT
}
}发布于 2015-01-29 17:09:43
- every data byte (or packet) is numbered
- both sides of communication maintain locally two numbers: last received and last sent
- every packet contains the copy of two number
- every successful transmission is confirmed by sending back an empty (or not) packet with the updated numbers
- if transmission is not confirmed within some timeout, send again.对于特殊处理(同步),向数据包添加标志(通常只有一个比特就足够了,以告知数据包是特殊的和使用的)。别忘了CRC。
这两个协议都不支持任何类型的会话。但您可以通过简单地添加另一个层来引入一个层-一个简单的状态机和一个计时器:
可以使用另一个特殊数据包进行正常的会话终止
这就是会话控制所能得到的最简单的结果。
发布于 2012-08-27 14:56:31
这个问题有两个方面。
首先,如果数据被丢弃,那么我将首先考虑解决硬件问题,否则您将拥有GIGO
至于通信协议,你的帖子建议了一个相当微不足道的系统?您是否要验证数据(奇偶校验、总和检查?)或者您是否正在尝试包含纠错功能?
如果只需要验证,那么我已经有了使用RS232和CRC8 sumchecks运行的可靠系统-在这种情况下,this StackOverflow page可能会有所帮助
https://stackoverflow.com/questions/12137392
复制相似问题