串行线路上的原始TCP / IP数据包 - 如何传递到TCP / IP堆栈 [英] Raw TCP/IP packets over serial line - How to pass to TCP/IP stack

查看:92
本文介绍了串行线路上的原始TCP / IP数据包 - 如何传递到TCP / IP堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个关于某个问题的简单问题,肯定有人已经遇到过。我有一个通过RS-485与另一个设备通信(通信)的传统设备。它使用自己的协议来实现这一点,它非常简单并且嵌入了原始ARP,IP,TCP等数据包。

所以,让所有电缆都正确并剥离相应的(串行)标题关闭,我基本上留下了原始TCP / IP数据包。

处理这些数据包最方便的方法是什么,而不必编写完整的tcp / ip堆栈?



如果我理解正确的话,我必须用我写的代码替换第5层来拆除串行协议,但是如何从那里开始呢?



在此先感谢,

Tony Bom。

Hi,

I have a simple question about a problem that surely someone has already encountered. I have a legacy device that communicates (communicated) with another device through RS-485. It does this with its own protocol, which is quite simple and embedded in there are raw ARP, IP, TCP, etc packets.
So, having gotten the cables all correct and stripping the respective (serial) headers off, I'm basically left with raw TCP/IP packets.
What it the most convenient way to have these packets handled, without having to write a complete tcp/ip stack?

If I understood correctly, I must substitute the layer 5 with the code I wrote to dismantle the serial protocol, but how to go on from there?

Thanks in advance,
Tony Bom.

推荐答案

我能看到的一个解决方案是使用某些硬件允许您在计算机主机上使用Etherner端口而不是串口设备。 (无论如何,许多计算机没有串行或并行端口。)

例如,我发现该网站有 http ://www.industrialethernet.com/ [ ^ ],请参阅 http://www.industrialethernet.com/net232.html [ ^ ]或其他一些产品。在互联网上搜索,你将能够找到相对便宜的设备。



你可能会说我没有回答你的问题。不,我还没有,但想一想:你可能会花更多的钱(读工作时间,这比金钱更贵)用于软件解决方案。如果您放弃并购买转换器设备,则可以使用没有任何串行或并行端口的计算机。




如果你仍然需要一个软件(或不同的硬件解决方案)你可以搜索更多。



我会建议这样的事情:



http://en.lmgtfy.com/?q=serial+port+(IP + OR + TCPIP + OR +%20%22TCP%2FIP%22 + OR + TCP)+堆栈+ -linux [ ^ ]







HTTP: //en.lmgtfy.com/?q=serial+port+(IP+OR+TCPIP+OR+%20%22TCP%2FIP%22+OR+TCP)+stack+bridge+-linux [ ^ ]



-SA
One solution I can see is using some piece of hardware which would allow you to use Etherner port on you computer host instead of serial port device. (Many computers don't have a serial or parallel port anyway.)
For example, I've found the site http://www.industrialethernet.com/[^], see http://www.industrialethernet.com/net232.html[^] or some other products. Search in internet and you will be able to find relatively inexpensive device.

You may say I did not answer your Question. No, I did not yet, but think about it: you may spend much more money (read "working time", which is more expensive than money) for poor-software solution. If you give up and buy the converter device, you can make an additional benefit of using computers which do not have any serial or parallel ports.


If you still need a software (or different hardware solution) you can search some more.

I would suggest something like this:

http://en.lmgtfy.com/?q=serial+port+(IP+OR+TCPIP+OR+%20%22TCP%2FIP%22+OR+TCP)+stack+-linux[^]

or

http://en.lmgtfy.com/?q=serial+port+(IP+OR+TCPIP+OR+%20%22TCP%2FIP%22+OR+TCP)+stack+bridge+-linux[^]

—SA


好的,看起来这可能有用:



这两个站将建立TCP连接(这就是为什么你在开始时看到ARP,你可能会看到一些BOOTP,谁知道还有什么。如果您只有2个站,这可能不重要。然后,应用程序数据流经TCP连接。我将在Windows中取代你的东西做什么:

1)关闭序列标题(我认为你已经完成了)

2)监控ARP和TCP在主设备和从设备之间建立检测连接的握手过程。从这一点开始,您将需要一个TCP连接来担心

3)监控一个连接,例如两者之间的TCP数据包和剥离(在剥离RS85标头之后)TCP和IP标头(确保处理重复数据包和确认等等)

4)在剥离TCP标头后你得到您的原始应用数据并进行处理。基本上在这一点上你应该向你的应用程序数据处理器提供一个连续的数据流



实际上你正在实现TCP / IP堆栈的一小部分。

如果你的两个站建立一个永久的TCP连接并且永远保持它将会有所帮助 - 工作更容易。



顺便说一下,当你有机会看到最初以这种方式安排它的原始设计师时,告诉他们你经过这个世界上最有声望的软件论坛而且他们都尽管这个安排很糟糕:)
Okay, it looks like this may work:

The two stations will establish a TCP connection (that is why you are seeing ARPs in the beginning and you might see some BOOTPs and who knows what else. This will probably be unimportant if you only ever have 2 stations). Then the application data then flows through the TCP connection. What I would do in the Windows thingy that replaces your POS:
1) Strip the serial headers off (you have done that I think)
2) Monitor ARPs and TCP handshake process to detect a connection is established between master and slave. From this point, you will have one TCP connection to worry about
3) Monitor one connection e.g. TCP packets between the two and strip off (after stripping off RS85 headers) the TCP and IP headers (make sure to handle repeat packets and acks and so on)
4) After striping off TCP headers you get your raw app data and process it. Basically at this point you should present to your application data processor a contiguous stream of data

In effect you are implementing a small part of TCP/IP stack.
It will help if your two stations establish a permanent TCP connection and just keep it forever - job is easier that way.

And by the way, when you get a chance to see the original designers who arranged it this way in the first place, tell them that you run this past the most reputable software forum in the world and they all though the arrangement sucks big time :)


In Linux or OS X, you can use pppd for the TCP/IP part. Write a program which communicates with your device and converts between your device's protocol and PPP frames written to stdout and read from stdin. Then you would run pppd as superuser and "connect" to your program (e.g. "/home/joe/ppptranslator") instead of a serial line or a modem:

sudo pppd nodetach pty /home/joe/ppptranslator

PPP is easier than TCP/IP, but it's still challenging. Good luck!

Here is some reading:

PPP:
<a href="https://www.ietf.org/rfc/rfc1661.txt">https://www.ietf.org/rfc/rfc1661.txt</a>[<a href="https://www.ietf.org/rfc/rfc1661.txt" target="_blank" title="New Window">^</a>]

HDLC frames (PPP lowest level):
<a href="https://www.ietf.org/rfc/rfc1662.txt">https://www.ietf.org/rfc/rfc1662.txt</a>[<a href="https://www.ietf.org/rfc/rfc1662.txt" target="_blank" title="New Window">^</a>]

IP in PPP:
<a href="https://www.ietf.org/rfc/rfc1332.txt">https://www.ietf.org/rfc/rfc1332.txt</a>[<a href="https://www.ietf.org/rfc/rfc1332.txt" target="_blank" title="New Window">^</a>]

The TCP/IP Guide:
<a href="http://www.tcpipguide.com/free/index.htm">http://www.tcpipguide.com/free/index.htm</a>[<a href="http://www.tcpipguide.com/free/index.htm" target="_blank" title="New Window">^</a>]


这篇关于串行线路上的原始TCP / IP数据包 - 如何传递到TCP / IP堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆