Skip to content

Commit bb716a0

Browse files
author
NEVSTOP
committed
update protocol
1 parent 80da56f commit bb716a0

File tree

5 files changed

+121
-19
lines changed

5 files changed

+121
-19
lines changed

Protocol.v0.(en).md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Protocol Definition
2+
3+
The TCP packet format used in the CSM-TCP-Router is defined as follows:
4+
5+
```
6+
| Data Length (4B) | Version (1B) | TYPE (1B) | FLAG1 (1B) | FLAG2 (1B) | Text Data |
7+
╰───────────────────────────────── Header ──────────────────────────────╯╰─── Data Length Range ──╯
8+
```
9+
10+
## Header Fields
11+
12+
### Data Length (4 Bytes)
13+
14+
This field specifies the length of the data section and is represented using 4 bytes.
15+
16+
### Version (1 Byte)
17+
18+
This field indicates the version of the data packet. The current version is `0x01`. Different versions can be handled appropriately to ensure forward compatibility.
19+
20+
### Packet Type (1 Byte)
21+
22+
This field defines the type of the data packet and is an enumerated value. The supported packet types are:
23+
24+
- Information Packet (`info`) - `0x00`
25+
- Error Packet (`error`) - `0x01`
26+
- Command Packet (`cmd`) - `0x02`
27+
- Synchronous Response Packet (`resp`) - `0x03`
28+
- Asynchronous Response Packet (`async-resp`) - `0x04`
29+
- Subscription Status Packet (`status`) - `0x05`
30+
31+
### FLAG1 (1 Byte)
32+
33+
This field is reserved for future use to describe additional attributes of the data packet.
34+
35+
### FLAG2 (1 Byte)
36+
37+
Similar to FLAG1, this field is reserved for future use to describe additional attributes of the data packet.
38+
39+
## Data Content
40+
41+
### Information Packet (`info`)
42+
43+
The content of an information packet is plain text containing informational data.
44+
45+
### Error Packet (`error`)
46+
47+
The content of an error packet is plain text describing an error, formatted as per the CSM Error format.
48+
49+
> [!NOTE]
50+
> The CSM Error format is: `[Error: Error Code] Error Message`.
51+
52+
### Command Packet (`cmd`)
53+
54+
The content of a command packet is a command in the CSM local command format. It supports the following types of messages:
55+
56+
- Synchronous (`-@`)
57+
- Asynchronous (`->`)
58+
- Asynchronous without return (`->|`)
59+
- Register (`register`)
60+
- Unregister (`unregister`)
61+
62+
> [!NOTE]
63+
> Example: Suppose there is a CSM module named `DAQmx` in the local program with an interface `API: Start Sampling`. You can send the following messages to control data acquisition:
64+
>
65+
> - `API: Start Sampling -@ DAQmx` // Synchronous message
66+
> - `API: Start Sampling -> DAQmx` // Asynchronous message
67+
> - `API: Start Sampling ->| DAQmx` // Asynchronous message without return
68+
>
69+
> These messages can also be sent over a TCP connection to achieve remote control.
70+
71+
> [!NOTE]
72+
> Example: Suppose there is a CSM module `A` that continuously sends a monitoring status called `Status`. Another module `B` can subscribe to this status:
73+
>
74+
> - `status@a >> api@b -><register>` // Subscribe to status
75+
> - `status@a >> api@b -><unregister>` // Unsubscribe from status
76+
>
77+
> Similarly, these messages can be sent over a TCP connection to manage subscriptions remotely.
78+
>
79+
> If the subscriber (`api@b`) is omitted, it indicates that the client connected to the TCP router is subscribing to the status:
80+
>
81+
> - `status@a -><register>` // Client subscribes to module A's status
82+
> - `status@a >> api@b -><unregister>` // Client unsubscribes from module A's status
83+
>
84+
> When module `A` sends a `Status`, the client will automatically receive a `status` packet.
85+
86+
### Synchronous Response Packet (`resp`)
87+
88+
After executing a synchronous command, the TCP router sends a response packet back to the client.
89+
90+
### Asynchronous Response Packet (`async-resp`)
91+
92+
After executing an asynchronous command, the TCP router sends a response packet back to the client. The format is: `Response Data <- Original Asynchronous Message`.
93+
94+
### Subscription Status Packet (`status`)
95+
96+
When a client subscribes to the status of a CSM module, it will automatically receive this packet whenever the status changes.
97+
98+
The packet format is: `Status Name >> Status Data <- Sending Module`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CSM TCP Router 网络传输协议定义
1+
# 传输协议
22

33
CSM-TCP-Router 中 TCP 数据包格式定义如下:
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CSM TCP Router 网络传输协议定义
1+
# 传输协议
22

33
CSM-TCP-Router 中 TCP 数据包格式定义如下:
44

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ This repository demonstrates how to create a reusable TCP communication layer (C
1212
- Based on the JKI-TCP-Server library, it supports multiple TCP clients connecting simultaneously.
1313
- [client] Provides a standard TCP client that can connect to the server to verify remote connections and message sending.
1414

15-
> [!IMPORTANT]
16-
> `TCP Packet Format:` | Data Length (4 bytes) | CSM Command String (plain text) |
17-
18-
> [!NOTE]
19-
> Example: Suppose there is a CSM module named DAQmx locally with an interface "API: Start Sampling".
20-
> Locally, we can send messages to this module to control the start and stop of sampling:
21-
>
22-
> - API: Start Sampling -@ DAQmx // Synchronous message
23-
> - API: Start Sampling -> DAQmx // Asynchronous message
24-
> - API: Start Sampling ->| DAQmx // Asynchronous message without return
25-
>
26-
> Now, by sending the same text message via TCP connection, remote control can be achieved.
27-
28-
> [!WARNING]
29-
> Currently, CSM-TCP-Router only supports synchronous messages (-@) and asynchronous messages without return (->|). Asynchronous messages (->) will be treated as asynchronous messages without return.
15+
## Protocol
16+
17+
The TCP packet format used in the CSM-TCP-Router is defined as follows:
18+
19+
```
20+
| Data Length (4B) | Version (1B) | TYPE (1B) | FLAG1 (1B) | FLAG2 (1B) | Text Data |
21+
╰───────────────────────────────── Header ──────────────────────────────╯╰─── Data Length Range ──╯
22+
```
23+
24+
This field defines the type of the data packet and is an enumerated value. The supported packet types are:
25+
26+
- Information Packet (`info`) - `0x00`
27+
- Error Packet (`error`) - `0x01`
28+
- Command Packet (`cmd`) - `0x02`
29+
- Synchronous Response Packet (`resp`) - `0x03`
30+
- Asynchronous Response Packet (`async-resp`) - `0x04`
31+
- Subscription Status Packet (`status`) - `0x05`
32+
33+
For detailed communication protocol definitions, see [Protocol Design](/Protocol%20Design.v0.(en).md).
3034

3135
## Supported Command Sets
3236

src/CSM-TCP-Router.lvcsm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ Item 27 = "action: loop check"
125125
Item 28 = "action: end loop"
126126

127127
[CSM Debug Console]
128-
Response Timeout(s) = 30
129-
History Length = 50
128+
Response Timeout(s) = 30
129+
History Length = 50
130130

131131
[CSMModule.CSM TCP Router]
132132
VIName = "CSM-TCP-Router.lvlib:CSM-TCP-Router.vi"

0 commit comments

Comments
 (0)