Browse Source

Add support for parsing responses that contain \r symbols in them

Thanks to alex # dyaconov.com for the test data
Georgi Chorbadzhiyski 6 years ago
parent
commit
e954cfe15a
5 changed files with 328 additions and 3 deletions
  1. 1
    0
      ChangeLog
  2. 14
    3
      cmd.c
  3. 201
    0
      test/input-r.txt
  4. 3
    0
      test/run
  5. 109
    0
      test/test-r.ok

+ 1
- 0
ChangeLog View File

@@ -1,6 +1,7 @@
1 1
 |-----------------------------------------------------------------------|
2 2
 xxxx-xx-xx : Version -dev
3 3
  * Add parsing support for CONFIGURATION command
4
+ * Add support for input that contains Windows style line endings
4 5
  * Ignore 'END PRELUDE' command
5 6
 
6 7
 2014-12-08 : Version 2.0

+ 14
- 3
cmd.c View File

@@ -340,10 +340,20 @@ bool parse_command(struct videohub_data *d, char *cmd) {
340 340
 	return ret;
341 341
 }
342 342
 
343
-int parse_text_buffer(struct videohub_data *d, char *cmd_buffer) {
343
+int parse_text_buffer(struct videohub_data *d, char *_cmd_buffer) {
344
+	int r, cmd_buffer_pos = 0, cmd_len = strlen(_cmd_buffer);
345
+	char *cmd_buffer = xzalloc(cmd_len + 1);
346
+	// Clean \r from output because it breaks parsing
347
+	for (r = 0; r < cmd_len; r++) {
348
+		if (_cmd_buffer[r] == '\r') continue;
349
+		cmd_buffer[cmd_buffer_pos++] = _cmd_buffer[r];
350
+	}
344 351
 	// The buffer contains only one command, no splitting is needed
345
-	if (!strstr(cmd_buffer, "\n\n"))
346
-		return parse_command(d, cmd_buffer);
352
+	if (!strstr(cmd_buffer, "\n\n")) {
353
+		bool ret = parse_command(d, cmd_buffer);
354
+		free(cmd_buffer);
355
+		return ret;
356
+	}
347 357
 	// Split commands and parse them one by one
348 358
 	int ok_commands = 0;
349 359
 	char *buf_copy = xstrdup(cmd_buffer);
@@ -361,6 +371,7 @@ int parse_text_buffer(struct videohub_data *d, char *cmd_buffer) {
361 371
 		cmd = newcmd + 2; // Advance cmd to the next command
362 372
 	}
363 373
 	free(buf_copy);
374
+	free(cmd_buffer);
364 375
 	return ok_commands;
365 376
 }
366 377
 

+ 201
- 0
test/input-r.txt View File

@@ -0,0 +1,201 @@
1
+PROTOCOL PREAMBLE:
2
+Version: 2.4
3
+
4
+VIDEOHUB DEVICE:
5
+Device present: true
6
+Model name: Blackmagic Micro Videohub
7
+Friendly name: My Videohub
8
+Unique ID: 7c2e0d021714
9
+Video inputs: 16
10
+Video processing units: 4
11
+Video outputs: 16
12
+Video monitoring outputs: 4
13
+Serial ports: 8
14
+
15
+INPUT LABELS:
16
+0 Windows 1
17
+1 Windows 2
18
+2 Windows 3
19
+3 Windows 4 HD
20
+4 Input 5
21
+5 Input 6
22
+6 Input 7
23
+7 Input 8
24
+8 Input 9
25
+9 Input 10
26
+10 Input 11
27
+11 DPlay1
28
+12 DPlay2
29
+13 Input 14
30
+14 Input 15
31
+15 Loopback
32
+
33
+OUTPUT LABELS:
34
+0 Enc1 1
35
+1 Enc1 2
36
+2 Enc1 3
37
+3 Enc1 4
38
+4 Output 5
39
+5 Output 6
40
+6 Output 7
41
+7 Output 8
42
+8 Enc2 1
43
+9 Output 10
44
+10 Output 11
45
+11 Denc
46
+12 Output 13
47
+13 Output 14
48
+14 Output 15
49
+15 Loopback
50
+
51
+VIDEO OUTPUT LOCKS:
52
+0 L
53
+1 L
54
+2 L
55
+3 L
56
+4 U
57
+5 U
58
+6 U
59
+7 U
60
+8 L
61
+9 U
62
+10 U
63
+11 L
64
+12 O
65
+13 U
66
+14 U
67
+15 O
68
+
69
+VIDEO OUTPUT ROUTING:
70
+0 2
71
+1 1
72
+2 0
73
+3 0
74
+4 4
75
+5 5
76
+6 6
77
+7 3
78
+8 3
79
+9 9
80
+10 10
81
+11 12
82
+12 11
83
+13 13
84
+14 14
85
+15 15
86
+
87
+VIDEO INPUT STATUS:
88
+0 BNC
89
+1 BNC
90
+2 BNC
91
+3 BNC
92
+4 Optical
93
+5 Optical
94
+6 Optical
95
+7 Optical
96
+13 None
97
+14 None
98
+
99
+VIDEO OUTPUT STATUS:
100
+4 None
101
+5 None
102
+6 None
103
+8 BNC
104
+9 BNC
105
+10 BNC
106
+11 BNC
107
+12 Optical
108
+13 Optical
109
+14 Optical
110
+15 Optical
111
+
112
+MONITORING OUTPUT LABELS:
113
+0 Monitor 1
114
+1 Monitor 2
115
+2 Monitor 3
116
+3 Monitor 4
117
+
118
+VIDEO MONITORING OUTPUT ROUTING:
119
+0 0
120
+1 1
121
+2 2
122
+3 3
123
+
124
+MONITORING OUTPUT LOCKS:
125
+0 U
126
+1 O
127
+2 L
128
+3 U
129
+
130
+SERIAL PORT LABELS:
131
+0 Serial Ctrl 1
132
+1 Serial Ctrl 2
133
+2 Deck 3
134
+3 Deck 4
135
+4 Serial 5
136
+5 Serial 6
137
+6 Serial 7
138
+7 Serial 8
139
+
140
+SERIAL PORT ROUTING:
141
+0 2
142
+1 3
143
+2 5
144
+3 -1
145
+2 -1
146
+
147
+SERIAL PORT LOCKS:
148
+0 O
149
+1 U
150
+2 L
151
+3 U
152
+
153
+SERIAL PORT STATUS:
154
+0 RS422
155
+1 RS422
156
+2 RS422
157
+3 RS422
158
+6 None
159
+7 None
160
+
161
+SERIAL PORT DIRECTIONS:
162
+0 control
163
+1 auto
164
+2 slave
165
+3 auto
166
+4 auto
167
+5 auto
168
+6 control
169
+7 slave
170
+
171
+PROCESSING UNIT ROUTING:
172
+0 3
173
+1 1
174
+3 2
175
+
176
+PROCESSING UNIT LOCKS:
177
+0 L
178
+1 U
179
+2 O
180
+3 U
181
+
182
+FRAME LABELS:
183
+0 Frame 1
184
+1 Frame 2
185
+2 Frame 3
186
+3 Frame 4
187
+4 Frame 5
188
+5 Frame 6
189
+6 Frame 7
190
+7 Frame 8
191
+
192
+FRAME BUFFER ROUTING:
193
+0 12
194
+1 13
195
+2 14
196
+
197
+FRAME BUFFER LOCKS:
198
+0 U
199
+1 L
200
+2 O
201
+

+ 3
- 0
test/run View File

@@ -157,3 +157,6 @@ check test/test-18 "Test --list-proc-units option output"
157 157
 
158 158
 videohubctrl --test-input test/input-00.txt --list-frames $@ &> test/test-19.out
159 159
 check test/test-19 "Test --list-frames option output"
160
+
161
+videohubctrl --test-input test/input-r.txt $@ &> test/test-r.out
162
+check test/test-r "Test input with windows line endings"

+ 109
- 0
test/test-r.ok View File

@@ -0,0 +1,109 @@
1
+Device info
2
+  -------------------------------------------------------------------
3
+  | Device address             | sdi-matrix                         |
4
+  | Device port                | 9990                               |
5
+  | Model name                 | Blackmagic Micro Videohub          |
6
+  | Friendly name              | My Videohub                        |
7
+  | Unique ID                  | 7c2e0d021714                       |
8
+  | Protocol                   | 2.4                                |
9
+  | Video inputs               | 16                                 |
10
+  | Video outputs              | 16                                 |
11
+  | Serial ports               | 8                                  |
12
+  | Video processing units     | 4                                  |
13
+  | Video monitoring outputs   | 4                                  |
14
+  -------------------------------------------------------------------
15
+
16
+Video inputs
17
+  ----------------------------------------------------------------------
18
+  | ### | Video input name         | nn | Routed to output         | s |
19
+  ----------------------------------------------------------------------
20
+  |   1 | Windows 1                |  2 | Enc1 3                   | B |
21
+  |     |                          |    | Enc1 4                   |   |
22
+  |   2 | Windows 2                |  1 | Enc1 2                   | B |
23
+  |   3 | Windows 3                |  1 | Enc1 1                   | B |
24
+  |   4 | Windows 4 HD             |  2 | Output 8                 | B |
25
+  |     |                          |    | Enc2 1                   |   |
26
+  |   5 | Input 5                  |  1 | Output 5                 | o |
27
+  |   6 | Input 6                  |  1 | Output 6                 | o |
28
+  |   7 | Input 7                  |  1 | Output 7                 | o |
29
+  |   8 | Input 8                  |  0 | -                        | o |
30
+  |   9 | Input 9                  |  0 | -                        |   |
31
+  |  10 | Input 10                 |  1 | Output 10                |   |
32
+  |  11 | Input 11                 |  1 | Output 11                |   |
33
+  |  12 | DPlay1                   |  1 | Output 13                |   |
34
+  |  13 | DPlay2                   |  1 | Denc                     |   |
35
+  |  14 | Input 14                 |  1 | Output 14                | x |
36
+  |  15 | Input 15                 |  1 | Output 15                | x |
37
+  |  16 | Loopback                 |  1 | Loopback                 |   |
38
+  ----------------------------------------------------------------------
39
+
40
+Video outputs
41
+  ---------------------------------------------------------------------
42
+  | ### | x | Video output name        | Connected video input    | s |
43
+  ---------------------------------------------------------------------
44
+  |   1 | L | Enc1 1                   | Windows 3                |   |
45
+  |   2 | L | Enc1 2                   | Windows 2                |   |
46
+  |   3 | L | Enc1 3                   | Windows 1                |   |
47
+  |   4 | L | Enc1 4                   | Windows 1                |   |
48
+  |   5 |   | Output 5                 | Input 5                  | x |
49
+  |   6 |   | Output 6                 | Input 6                  | x |
50
+  |   7 |   | Output 7                 | Input 7                  | x |
51
+  |   8 |   | Output 8                 | Windows 4 HD             |   |
52
+  |   9 | L | Enc2 1                   | Windows 4 HD             | B |
53
+  |  10 |   | Output 10                | Input 10                 | B |
54
+  |  11 |   | Output 11                | Input 11                 | B |
55
+  |  12 | L | Denc                     | DPlay2                   | B |
56
+  |  13 | O | Output 13                | DPlay1                   | o |
57
+  |  14 |   | Output 14                | Input 14                 | o |
58
+  |  15 |   | Output 15                | Input 15                 | o |
59
+  |  16 | O | Loopback                 | Loopback                 | o |
60
+  ---------------------------------------------------------------------
61
+
62
+Monitoring outputs
63
+  -----------------------------------------------------------------
64
+  | ### | x | Monitoring output name   | Connected video input    |
65
+  -----------------------------------------------------------------
66
+  |   1 |   | Monitor 1                | Windows 1                |
67
+  |   2 | O | Monitor 2                | Windows 2                |
68
+  |   3 | L | Monitor 3                | Windows 3                |
69
+  |   4 |   | Monitor 4                | Windows 4 HD             |
70
+  -----------------------------------------------------------------
71
+
72
+Serial ports
73
+  ----------------------------------------------------------------
74
+  | ### | x | Dir  | Serial port        | Connected serial   | s |
75
+  ----------------------------------------------------------------
76
+  |   1 | O |   in | Serial Ctrl 1      | Deck 3             | 4 |
77
+  |   2 |   | auto | Serial Ctrl 2      | Deck 4             | 4 |
78
+  |   3 | L |  out | Deck 3             |                    | 4 |
79
+  |   4 |   | auto | Deck 4             |                    | 4 |
80
+  |   5 |   | auto | Serial 5           |                    |   |
81
+  |   6 |   | auto | Serial 6           |                    |   |
82
+  |   7 |   |   in | Serial 7           |                    | x |
83
+  |   8 |   |  out | Serial 8           |                    | x |
84
+  ----------------------------------------------------------------
85
+
86
+Processing units
87
+  --------------------------------------------
88
+  | Proc Unit | x | Connected video input    |
89
+  --------------------------------------------
90
+  |         1 | L | Windows 4 HD             |
91
+  |         2 |   | Windows 2                |
92
+  |         3 | O |                          |
93
+  |         4 |   | Windows 3                |
94
+  --------------------------------------------
95
+
96
+Frames
97
+  -----------------------------------------------------------------
98
+  | ### | x | Frame name               | Connected output         |
99
+  -----------------------------------------------------------------
100
+  |   1 |   | Frame 1                  | Output 13                |
101
+  |   2 | L | Frame 2                  | Output 14                |
102
+  |   3 | O | Frame 3                  | Output 15                |
103
+  |   4 |   | Frame 4                  |                          |
104
+  |   5 |   | Frame 5                  |                          |
105
+  |   6 |   | Frame 6                  |                          |
106
+  |   7 |   | Frame 7                  |                          |
107
+  |   8 |   | Frame 8                  |                          |
108
+  -----------------------------------------------------------------
109
+

Loading…
Cancel
Save