@@ -192,129 +192,139 @@ int lighting_command_decode(
192192 case BACNET_LIGHTS_NONE :
193193 break ;
194194 case BACNET_LIGHTS_FADE_TO :
195- if ((apdu_size - apdu_len ) == 0 ) {
196- return BACNET_STATUS_REJECT ;
197- }
198- /* target-level [1] REAL (0.0..100.0) OPTIONAL */
195+ /* target-level [1] REAL (0.0..100.0) */
199196 len = bacnet_real_context_decode (
200- & apdu [apdu_len ], apdu_size , 1 , & real_value );
197+ & apdu [apdu_len ], apdu_size - apdu_len , 1 , & real_value );
201198 if (len > 0 ) {
202199 apdu_len += len ;
203200 if (data ) {
204201 data -> target_level = real_value ;
205202 data -> use_target_level = true;
206203 }
204+ } else {
205+ return BACNET_STATUS_ERROR ;
207206 }
208- if ((apdu_size - apdu_len ) > 0 ) {
209- /* Tag 4: fade-time - OPTIONAL */
210- len = bacnet_unsigned_context_decode (
211- & apdu [apdu_len ], apdu_size , 4 , & unsigned_value );
212- if (len > 0 ) {
213- apdu_len += len ;
214- if (data ) {
215- data -> fade_time = (uint32_t )unsigned_value ;
216- data -> use_fade_time = true;
217- }
218- } else {
219- return BACNET_STATUS_ERROR ;
207+ /* Tag 4: fade-time - OPTIONAL */
208+ len = bacnet_unsigned_context_decode (
209+ & apdu [apdu_len ], apdu_size - apdu_len , 4 , & unsigned_value );
210+ if (len > 0 ) {
211+ apdu_len += len ;
212+ if (data ) {
213+ data -> fade_time = (uint32_t )unsigned_value ;
214+ data -> use_fade_time = true;
220215 }
216+ } else if (len == 0 ) {
217+ /* fade-time is optional, so do nothing */
218+ } else {
219+ return BACNET_STATUS_ERROR ;
221220 }
222- if ((apdu_size - apdu_len ) > 0 ) {
223- /* priority [5] Unsigned (1..16) OPTIONAL */
224- len = bacnet_unsigned_context_decode (
225- & apdu [apdu_len ], apdu_size , 5 , & unsigned_value );
226- if (len > 0 ) {
227- apdu_len += len ;
228- if (data ) {
229- data -> priority = (uint8_t )unsigned_value ;
230- data -> use_priority = true;
231- }
221+ /* priority [5] Unsigned (1..16) OPTIONAL */
222+ len = bacnet_unsigned_context_decode (
223+ & apdu [apdu_len ], apdu_size - apdu_len , 5 , & unsigned_value );
224+ if (len > 0 ) {
225+ apdu_len += len ;
226+ if (data ) {
227+ data -> priority = (uint8_t )unsigned_value ;
228+ data -> use_priority = true;
232229 }
230+ } else if (len == 0 ) {
231+ /* priority is optional, so do nothing */
232+ } else {
233+ return BACNET_STATUS_ERROR ;
233234 }
234235 break ;
235236 case BACNET_LIGHTS_RAMP_TO :
236- if ((apdu_size - apdu_len ) == 0 ) {
237- return BACNET_STATUS_REJECT ;
238- }
239- /* target-level [1] REAL (0.0..100.0) OPTIONAL */
237+ /* target-level [1] REAL (0.0..100.0) */
240238 len = bacnet_real_context_decode (
241- & apdu [apdu_len ], apdu_size , 1 , & real_value );
239+ & apdu [apdu_len ], apdu_size - apdu_len , 1 , & real_value );
242240 if (len > 0 ) {
243241 apdu_len += len ;
244242 if (data ) {
245243 data -> target_level = real_value ;
246244 data -> use_target_level = true;
247245 }
246+ } else {
247+ return BACNET_STATUS_ERROR ;
248248 }
249- if ((apdu_size - apdu_len ) > 0 ) {
250- /* ramp-rate [2] REAL (0.1..100.0) OPTIONAL */
251- len = bacnet_real_context_decode (
252- & apdu [apdu_len ], apdu_size , 2 , & real_value );
253- if (len > 0 ) {
254- apdu_len += len ;
255- if (data ) {
256- data -> ramp_rate = real_value ;
257- data -> use_ramp_rate = true;
258- }
249+ /* ramp-rate [2] REAL (0.1..100.0) OPTIONAL */
250+ len = bacnet_real_context_decode (
251+ & apdu [apdu_len ], apdu_size - apdu_len , 2 , & real_value );
252+ if (len > 0 ) {
253+ apdu_len += len ;
254+ if (data ) {
255+ data -> ramp_rate = real_value ;
256+ data -> use_ramp_rate = true;
259257 }
258+ } else if (len == 0 ) {
259+ /* ramp-rate is optional, so do nothing */
260+ } else {
261+ return BACNET_STATUS_ERROR ;
260262 }
261- if ((apdu_size - apdu_len ) > 0 ) {
262- /* priority [5] Unsigned (1..16) OPTIONAL */
263- len = bacnet_unsigned_context_decode (
264- & apdu [apdu_len ], apdu_size , 5 , & unsigned_value );
265- if (len > 0 ) {
266- apdu_len += len ;
267- if (data ) {
268- data -> priority = (uint8_t )unsigned_value ;
269- data -> use_priority = true;
270- }
263+ /* priority [5] Unsigned (1..16) OPTIONAL */
264+ len = bacnet_unsigned_context_decode (
265+ & apdu [apdu_len ], apdu_size - apdu_len , 5 , & unsigned_value );
266+ if (len > 0 ) {
267+ apdu_len += len ;
268+ if (data ) {
269+ data -> priority = (uint8_t )unsigned_value ;
270+ data -> use_priority = true;
271271 }
272+ } else if (len == 0 ) {
273+ /* priority is optional, so do nothing */
274+ } else {
275+ return BACNET_STATUS_ERROR ;
272276 }
273277 break ;
274278 case BACNET_LIGHTS_STEP_UP :
275279 case BACNET_LIGHTS_STEP_DOWN :
276280 case BACNET_LIGHTS_STEP_ON :
277281 case BACNET_LIGHTS_STEP_OFF :
278- if ((apdu_size - apdu_len ) > 0 ) {
279- /* step-increment [3] REAL (0.1..100.0) OPTIONAL */
280- len = bacnet_real_context_decode (
281- & apdu [apdu_len ], apdu_size , 3 , & real_value );
282- if (len > 0 ) {
283- apdu_len += len ;
284- if (data ) {
285- data -> step_increment = real_value ;
286- data -> use_step_increment = true;
287- }
282+ /* step-increment [3] REAL (0.1..100.0) OPTIONAL */
283+ len = bacnet_real_context_decode (
284+ & apdu [apdu_len ], apdu_size - apdu_len , 3 , & real_value );
285+ if (len > 0 ) {
286+ apdu_len += len ;
287+ if (data ) {
288+ data -> step_increment = real_value ;
289+ data -> use_step_increment = true;
288290 }
291+ } else if (len == 0 ) {
292+ /* step-increment is optional, so do nothing */
293+ } else {
294+ return BACNET_STATUS_ERROR ;
289295 }
290- if ((apdu_size - apdu_len ) > 0 ) {
291- /* priority [5] Unsigned (1..16) OPTIONAL */
292- len = bacnet_unsigned_context_decode (
293- & apdu [apdu_len ], apdu_size , 5 , & unsigned_value );
294- if (len > 0 ) {
295- apdu_len += len ;
296- if (data ) {
297- data -> priority = (uint8_t )unsigned_value ;
298- data -> use_priority = true;
299- }
296+ /* priority [5] Unsigned (1..16) OPTIONAL */
297+ len = bacnet_unsigned_context_decode (
298+ & apdu [apdu_len ], apdu_size - apdu_len , 5 , & unsigned_value );
299+ if (len > 0 ) {
300+ apdu_len += len ;
301+ if (data ) {
302+ data -> priority = (uint8_t )unsigned_value ;
303+ data -> use_priority = true;
300304 }
305+ } else if (len == 0 ) {
306+ /* priority is optional, so do nothing */
307+ } else {
308+ return BACNET_STATUS_ERROR ;
301309 }
302310 break ;
303311 case BACNET_LIGHTS_WARN :
304312 case BACNET_LIGHTS_WARN_OFF :
305313 case BACNET_LIGHTS_WARN_RELINQUISH :
306314 case BACNET_LIGHTS_STOP :
307- if ((apdu_size - apdu_len ) > 0 ) {
308- /* priority [5] Unsigned (1..16) OPTIONAL */
309- len = bacnet_unsigned_context_decode (
310- & apdu [apdu_len ], apdu_size , 5 , & unsigned_value );
311- if (len > 0 ) {
312- apdu_len += len ;
313- if (data ) {
314- data -> priority = (uint8_t )unsigned_value ;
315- data -> use_priority = true;
316- }
315+ /* priority [5] Unsigned (1..16) OPTIONAL */
316+ len = bacnet_unsigned_context_decode (
317+ & apdu [apdu_len ], apdu_size - apdu_len , 5 , & unsigned_value );
318+ if (len > 0 ) {
319+ apdu_len += len ;
320+ if (data ) {
321+ data -> priority = (uint8_t )unsigned_value ;
322+ data -> use_priority = true;
317323 }
324+ } else if (len == 0 ) {
325+ /* priority is optional, so do nothing */
326+ } else {
327+ return BACNET_STATUS_ERROR ;
318328 }
319329 break ;
320330 default :
0 commit comments