【发布时间】:2018-06-22 07:18:53
【问题描述】:
我正在尝试向 Tattile 交通摄像头发送数据包。
Tattile 摄像头使用其自己的 TCP 数据包协议,称为 TOP(Tattile 对象协议)
目前为止我所看到的阅读文档我需要一个 IP > TCP > TOP HEADER > VCR PAYLOAD
要创建 TOP Header
这是要求。
我相信需要 24 个字节。
这是命令头,从上图中,Header Dimension 部分是这个要求需要 24 个字节的 TOP Header?
这是 Header Constructor,我不明白为什么它在那里已经有一个 Command Header 具有相同的信息我能看到什么。
这是一个关于构建消息的示例,所以对于现阶段的command code,在我得到更好的理解之前,我要做的就是发送数据,没有收到,所以说
这是Start Engine命令代码.
这是我在代码方面的内容,到目前为止它连接并“发送消息”但是引擎没有启动,至于enum,将来当我更好地理解时,我应该会添加更多带有命令代码的命令。
class Command
{
public enum Codes
{
START_ENGINE
}
private static readonly byte[] HeaderDimension = new byte[24];
private static byte[] CommandCode;
private static readonly byte[] Sender = new byte[4] { 0xFF, 0xFF, 0xFF, 0xFF };
private static readonly byte[] Receiver = Sender;
private static readonly byte[] Error = new byte[] { 0 };
private static readonly byte[] DataDimension = new byte[] {0};
public static void Execute(Codes code)
{
if (code == Codes.START_ENGINE)
{
CommandCode = new byte[4]{ 0x35, 0x0, 0x0, 0x4};
}
using (TcpClient tcpClient = new TcpClient("192.168.1.21", 31000))
{
NetworkStream networkStream = tcpClient.GetStream();
byte[] bytesTosend = HeaderDimension.Concat(CommandCode)
.Concat(Sender)
.Concat(Receiver)
.Concat(Error)
.Concat(DataDimension).ToArray();
networkStream.Write(bytesTosend, 0, bytesTosend.Length);
}
}
}
我是这样称呼它的
static void Main()
{
Command.Execute(Command.Codes.START_ENGINE);
Console.ReadKey();
}
【问题讨论】:
-
我非常怀疑
0x35, 0x0, 0x0, 0x4是编码命令35004的正确方法。你是怎么得出这个结论的? -
@Damien_The_Unbeliever 我得出这个结论是因为它需要我认为的字节数组中的命令
-
但文档似乎对在其他地方使用十六进制表示法感到满意。如果 35004(没有任何其他指示)被解释为十六进制,则通常将其编码为
0x00, 0x03, 0x50, 0x04。但由于它看起来像一个普通的小数,您通常将该数字编码为0x00, 0x00, 0x88, 0xBC。