@@ -96,67 +96,58 @@ int decodeByte(uint8_t value)
9696
9797bool parseStatusResponse (const std::vector<uint8_t > &data, int *position, int *slots)
9898{
99- // Some wheel firmware returns one frame containing the status command and values.
100- auto start = data. begin () ;
101- while (start != data.end ())
99+ std::vector< int > compactValues;
100+ size_t start = 0 ;
101+ while (start < data.size ())
102102 {
103- start = std::find (start, data.end (), kFrameByte );
104- if (start == data.end ())
103+ while (start < data.size () && data[start] != kFrameByte )
104+ start++;
105+ if (start == data.size ())
105106 break ;
106107
107- auto end = std::find (start + 1 , data.end (), kFrameByte );
108- if (end == data.end ())
108+ size_t end = start + 1 ;
109+ while (end < data.size () && data[end] != kFrameByte )
110+ end++;
111+ if (end == data.size ())
109112 break ;
110113
111- if (end - start >= 3 && *(start + 1 ) == kCmdStatus )
114+ size_t payloadSize = end - start - 1 ;
115+
116+ // Some wheel firmware returns one frame containing the status command and values.
117+ if (payloadSize >= 2 && data[start + 1 ] == kCmdStatus )
112118 {
113- int decodedPosition = decodeByte (*( start + 2 ) );
119+ int decodedPosition = decodeByte (data[ start + 2 ] );
114120 if (decodedPosition > 0 && position)
115121 *position = decodedPosition;
116122
117- if (end - start >= 4 )
123+ if (payloadSize >= 3 )
118124 {
119- int decodedSlots = decodeByte (*( start + 3 ) );
125+ int decodedSlots = decodeByte (data[ start + 3 ] );
120126 if (decodedSlots > 0 && slots)
121127 *slots = decodedSlots;
122128 }
123129
124130 return (decodedPosition > 0 );
125131 }
126132
127- start = end + 1 ;
128- }
129-
130- // EFW2 hardware also returns two compact frames: #position##slot-count#.
131- std::vector<int > values;
132- start = data.begin ();
133- while (start != data.end ())
134- {
135- start = std::find (start, data.end (), kFrameByte );
136- if (start == data.end ())
137- break ;
138-
139- auto end = std::find (start + 1 , data.end (), kFrameByte );
140- if (end == data.end ())
141- break ;
142-
143- if (end - start == 2 )
133+ // EFW2 hardware also returns two compact frames: #position##slot-count#.
134+ if (payloadSize == 1 )
144135 {
145- int value = decodeByte (*( start + 1 ) );
136+ int value = decodeByte (data[ start + 1 ] );
146137 if (value > 0 && value <= kMaxSlots )
147- values .push_back (value);
138+ compactValues .push_back (value);
148139 }
149140
150141 start = end + 1 ;
151142 }
152143
153- if (values .empty ())
144+ if (compactValues .empty ())
154145 return false ;
155146
156147 if (position)
157- *position = values [0 ];
158- if (slots && values .size () > 1 )
159- *slots = values [1 ];
148+ *position = compactValues [0 ];
149+ if (slots && compactValues .size () > 1 )
150+ *slots = compactValues [1 ];
160151 return true ;
161152}
162153
@@ -340,10 +331,7 @@ AtikEFW::AtikEFW(const DeviceDescriptor &desc, AtikEfwUsb::Backend &backend)
340331 setDeviceName (desc.name .c_str ());
341332}
342333
343- AtikEFW::~AtikEFW ()
344- {
345- Disconnect ();
346- }
334+ AtikEFW::~AtikEFW () = default ;
347335
348336const char *AtikEFW::getDefaultName ()
349337{
0 commit comments