Skip to content

Commit c211cb3

Browse files
ycsinnashif
authored andcommitted
drivers: sensor: rtio: use catch-remaining for decoding
As new channels are added to the `enum sensor_channel`, some of the newer channel aren't updated in the whitelist of rtio decoder. Instead of specifying every channel in the list, do: 1. Verify that the `channel` is valid 2. cherry-pick the channels that require special handling, i.e. 1. `three_axis_data` 2. `byte_data` 3. `uint64_data` 3. handle the remaining `channel` in the default case as `q31_data` to make sure that all channels are handled. Updated the pytest to get channel 32, previously nothing would happen for this channel as there isn't a decoder for it, now it would return: ``` channel type=32((null)) ``` the channel name is NULL because it wasn't added to the channel name look up table in the sensor_shell.c, that is being fixed in #72815. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent c8ae265 commit c211cb3

File tree

1 file changed

+12
-86
lines changed

1 file changed

+12
-86
lines changed

drivers/sensor/default_rtio_sensor.c

Lines changed: 12 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
323323
__ASSERT_NO_MSG(base_size != NULL);
324324
__ASSERT_NO_MSG(frame_size != NULL);
325325

326+
if (((int)channel.chan_type < 0) || channel.chan_type >= (SENSOR_CHAN_ALL)) {
327+
return -ENOTSUP;
328+
}
329+
326330
switch (channel.chan_type) {
327331
case SENSOR_CHAN_ACCEL_X:
328332
case SENSOR_CHAN_ACCEL_Y:
@@ -342,49 +346,6 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
342346
*base_size = sizeof(struct sensor_three_axis_data);
343347
*frame_size = sizeof(struct sensor_three_axis_sample_data);
344348
return 0;
345-
case SENSOR_CHAN_DIE_TEMP:
346-
case SENSOR_CHAN_AMBIENT_TEMP:
347-
case SENSOR_CHAN_PRESS:
348-
case SENSOR_CHAN_HUMIDITY:
349-
case SENSOR_CHAN_LIGHT:
350-
case SENSOR_CHAN_IR:
351-
case SENSOR_CHAN_RED:
352-
case SENSOR_CHAN_GREEN:
353-
case SENSOR_CHAN_BLUE:
354-
case SENSOR_CHAN_ALTITUDE:
355-
case SENSOR_CHAN_PM_1_0:
356-
case SENSOR_CHAN_PM_2_5:
357-
case SENSOR_CHAN_PM_10:
358-
case SENSOR_CHAN_DISTANCE:
359-
case SENSOR_CHAN_CO2:
360-
case SENSOR_CHAN_VOC:
361-
case SENSOR_CHAN_GAS_RES:
362-
case SENSOR_CHAN_VOLTAGE:
363-
case SENSOR_CHAN_CURRENT:
364-
case SENSOR_CHAN_POWER:
365-
case SENSOR_CHAN_RESISTANCE:
366-
case SENSOR_CHAN_ROTATION:
367-
case SENSOR_CHAN_RPM:
368-
case SENSOR_CHAN_GAUGE_VOLTAGE:
369-
case SENSOR_CHAN_GAUGE_AVG_CURRENT:
370-
case SENSOR_CHAN_GAUGE_STDBY_CURRENT:
371-
case SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT:
372-
case SENSOR_CHAN_GAUGE_TEMP:
373-
case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE:
374-
case SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY:
375-
case SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY:
376-
case SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY:
377-
case SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY:
378-
case SENSOR_CHAN_GAUGE_AVG_POWER:
379-
case SENSOR_CHAN_GAUGE_STATE_OF_HEALTH:
380-
case SENSOR_CHAN_GAUGE_TIME_TO_EMPTY:
381-
case SENSOR_CHAN_GAUGE_TIME_TO_FULL:
382-
case SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE:
383-
case SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE:
384-
case SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT:
385-
*base_size = sizeof(struct sensor_q31_data);
386-
*frame_size = sizeof(struct sensor_q31_sample_data);
387-
return 0;
388349
case SENSOR_CHAN_PROX:
389350
*base_size = sizeof(struct sensor_byte_data);
390351
*frame_size = sizeof(struct sensor_byte_sample_data);
@@ -394,7 +355,9 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
394355
*frame_size = sizeof(struct sensor_uint64_sample_data);
395356
return 0;
396357
default:
397-
return -ENOTSUP;
358+
*base_size = sizeof(struct sensor_q31_data);
359+
*frame_size = sizeof(struct sensor_q31_sample_data);
360+
return 0;
398361
}
399362
}
400363

@@ -485,6 +448,10 @@ static int decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
485448
return -EINVAL;
486449
}
487450

451+
if (((int)chan_spec.chan_type < 0) || chan_spec.chan_type >= (SENSOR_CHAN_ALL)) {
452+
return 0;
453+
}
454+
488455
/* Check for 3d channel mappings */
489456
switch (chan_spec.chan_type) {
490457
case SENSOR_CHAN_ACCEL_X:
@@ -518,49 +485,8 @@ static int decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
518485
SENSOR_CHAN_POS_DY, SENSOR_CHAN_POS_DZ,
519486
chan_spec.chan_idx);
520487
break;
521-
case SENSOR_CHAN_DIE_TEMP:
522-
case SENSOR_CHAN_AMBIENT_TEMP:
523-
case SENSOR_CHAN_PRESS:
524-
case SENSOR_CHAN_HUMIDITY:
525-
case SENSOR_CHAN_LIGHT:
526-
case SENSOR_CHAN_IR:
527-
case SENSOR_CHAN_RED:
528-
case SENSOR_CHAN_GREEN:
529-
case SENSOR_CHAN_BLUE:
530-
case SENSOR_CHAN_ALTITUDE:
531-
case SENSOR_CHAN_PM_1_0:
532-
case SENSOR_CHAN_PM_2_5:
533-
case SENSOR_CHAN_PM_10:
534-
case SENSOR_CHAN_DISTANCE:
535-
case SENSOR_CHAN_CO2:
536-
case SENSOR_CHAN_VOC:
537-
case SENSOR_CHAN_GAS_RES:
538-
case SENSOR_CHAN_VOLTAGE:
539-
case SENSOR_CHAN_CURRENT:
540-
case SENSOR_CHAN_POWER:
541-
case SENSOR_CHAN_RESISTANCE:
542-
case SENSOR_CHAN_ROTATION:
543-
case SENSOR_CHAN_RPM:
544-
case SENSOR_CHAN_GAUGE_VOLTAGE:
545-
case SENSOR_CHAN_GAUGE_AVG_CURRENT:
546-
case SENSOR_CHAN_GAUGE_STDBY_CURRENT:
547-
case SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT:
548-
case SENSOR_CHAN_GAUGE_TEMP:
549-
case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE:
550-
case SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY:
551-
case SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY:
552-
case SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY:
553-
case SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY:
554-
case SENSOR_CHAN_GAUGE_AVG_POWER:
555-
case SENSOR_CHAN_GAUGE_STATE_OF_HEALTH:
556-
case SENSOR_CHAN_GAUGE_TIME_TO_EMPTY:
557-
case SENSOR_CHAN_GAUGE_TIME_TO_FULL:
558-
case SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE:
559-
case SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE:
560-
case SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT:
561-
count = decode_q31(header, q, data_out, chan_spec);
562-
break;
563488
default:
489+
count = decode_q31(header, q, data_out, chan_spec);
564490
break;
565491
}
566492
if (count > 0) {

0 commit comments

Comments
 (0)