@@ -83,6 +83,8 @@ void SBusListGet( uint16_t ch_list[ SBUS_CH_MAX ] )
83
83
////////////////////////////////////////////////////////////////////////////////
84
84
static void SBusProcess ( uint8_t byte_in )
85
85
{
86
+ static uint8_t byte_in_prev = SBUS_HEADER_VALUE ;
87
+
86
88
/// Structure defining the contents of an S.Bus data payload. Each of the
87
89
/// channel fields (ch1:ch16) occupies 11 bytes.
88
90
typedef union
@@ -127,11 +129,10 @@ static void SBusProcess( uint8_t byte_in )
127
129
128
130
static enum
129
131
{
130
- SM_END ,
131
132
SM_START ,
132
133
SM_DATA ,
133
134
134
- } sm_state = SM_END ;
135
+ } sm_state = SM_START ;
135
136
136
137
static SBUS_DATA_U sbus_data ;
137
138
@@ -141,29 +142,14 @@ static void SBusProcess( uint8_t byte_in )
141
142
// packet - i.e. rather than only checking the start/header byte.
142
143
switch ( sm_state )
143
144
{
144
- case SM_END :
145
- {
146
- // End byte received ?
147
- if ( byte_in == SBUS_FOOTER_VALUE )
148
- {
149
- sm_state ++ ;
150
- }
151
-
152
- break ;
153
- }
154
145
case SM_START :
155
146
{
156
- // Start byte received ?
157
- if ( byte_in == SBUS_HEADER_VALUE )
147
+ // Footer followed by Header byte has been received ?
148
+ if ( ( byte_in_prev == SBUS_FOOTER_VALUE ) &&
149
+ ( byte_in == SBUS_HEADER_VALUE ) )
158
150
{
159
151
sm_state ++ ;
160
152
}
161
- else
162
- {
163
- // Start byte needs to be next received byte following the
164
- // end byte of the previous message.
165
- sm_state = SM_END ;
166
- }
167
153
168
154
break ;
169
155
}
@@ -178,7 +164,7 @@ static void SBusProcess( uint8_t byte_in )
178
164
{
179
165
// Reset for reception of next data stream.
180
166
ch_data_idx = 0 ;
181
- sm_state = SM_END ;
167
+ sm_state = SM_START ;
182
168
183
169
// Process the received data.
184
170
sbus_ch_data [ 0 ] = sbus_data .ch1 ;
@@ -202,4 +188,7 @@ static void SBusProcess( uint8_t byte_in )
202
188
break ;
203
189
}
204
190
}
191
+
192
+ // Latch current byte for next evaluation.
193
+ byte_in_prev = byte_in ;
205
194
}
0 commit comments