@@ -37,8 +37,8 @@ bool protocolSerial2MyMessage(MyMessage &message, char *inputString)
37
37
38
38
// Extract command data coming on serial line
39
39
for (str = strtok_r (inputString, " ;" , &p); // split using semicolon
40
- str && index < 6 ; // loop while str is not null an max 5 times
41
- str = strtok_r (NULL , " ;" , &p) // get subsequent tokens
40
+ str && index < 5 ; // loop while str is not null an max 4 times
41
+ str = strtok_r (NULL , " ;" , &p), index++ // get subsequent tokens
42
42
) {
43
43
switch (index) {
44
44
case 0 : // Radio id (destination)
@@ -57,34 +57,30 @@ bool protocolSerial2MyMessage(MyMessage &message, char *inputString)
57
57
case 4 : // Data type
58
58
message.type = atoi (str);
59
59
break ;
60
- case 5 : {// Variable value
61
- if (command == C_STREAM) {
62
- uint8_t bvalue[MAX_PAYLOAD];
63
- uint8_t blen = 0 ;
64
- while (*str) {
65
- uint8_t val;
66
- val = convertH2I (*str++) << 4 ;
67
- val += convertH2I (*str++);
68
- bvalue[blen] = val;
69
- blen++;
70
- }
71
- message.set (bvalue, blen);
72
- } else {
73
- char *value = str;
74
- // Remove trailing carriage return and newline character (if it exists)
75
- const uint8_t lastCharacter = strlen (value) - 1 ;
76
- if (value[lastCharacter] == ' \r ' || value[lastCharacter] == ' \n ' ) {
77
- value[lastCharacter] = ' \0 ' ;
78
- }
79
- message.set (value);
80
- }
81
- break ;
82
60
}
61
+ }
62
+ // payload
63
+ if (command == C_STREAM) {
64
+ uint8_t bvalue[MAX_PAYLOAD];
65
+ uint8_t blen = 0 ;
66
+ while (*str) {
67
+ uint8_t val;
68
+ val = convertH2I (*str++) << 4 ;
69
+ val += convertH2I (*str++);
70
+ bvalue[blen] = val;
71
+ blen++;
72
+ }
73
+ message.set (bvalue, blen);
74
+ } else {
75
+ char *value = str;
76
+ // Remove trailing carriage return and newline character (if it exists)
77
+ const uint8_t lastCharacter = strlen (value) - 1 ;
78
+ if (value[lastCharacter] == ' \r ' || value[lastCharacter] == ' \n ' ) {
79
+ value[lastCharacter] = ' \0 ' ;
83
80
}
84
- index++ ;
81
+ message. set (value) ;
85
82
}
86
- // Return true if input valid
87
- return (index == 6 );
83
+ return (index == 5 );
88
84
}
89
85
90
86
char *protocolMyMessage2Serial (MyMessage &message)
@@ -114,7 +110,7 @@ bool protocolMQTT2MyMessage(MyMessage &message, char *topic, uint8_t *payload,
114
110
mSetEcho (message, false );
115
111
for (str = strtok_r (topic + strlen (MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) + 1 , " /" , &p);
116
112
str && index < 5 ;
117
- str = strtok_r (NULL , " /" , &p)
113
+ str = strtok_r (NULL , " /" , &p), index++
118
114
) {
119
115
switch (index) {
120
116
case 0 :
@@ -158,7 +154,6 @@ bool protocolMQTT2MyMessage(MyMessage &message, char *topic, uint8_t *payload,
158
154
message.type = atoi (str);
159
155
break ;
160
156
}
161
- index++;
162
157
}
163
158
// Return true if input valid
164
159
return (index == 5 );
0 commit comments