Commit e993e994 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Anas Nashif
Browse files

sensors: add new channel `SENSOR_CHAN_POS_DXYZ`



Add new channel: `SENSOR_CHAN_POS_DXYZ`, so that it is
consistent with other 3-axis channels.

Updated pytest, `sensor_shell` & `fake_sensor` accordingly.

Signed-off-by: default avatarYong Cong Sin <ycsin@meta.com>
parent 4e716802
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -304,6 +304,9 @@ static int get_frame_count(const uint8_t *buffer, struct sensor_chan_spec channe
	case SENSOR_CHAN_MAGN_XYZ:
		channel.chan_type = SENSOR_CHAN_MAGN_X;
		break;
	case SENSOR_CHAN_POS_DXYZ:
		channel.chan_type = SENSOR_CHAN_POS_DX;
		break;
	default:
		break;
	}
@@ -343,6 +346,7 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
	case SENSOR_CHAN_POS_DX:
	case SENSOR_CHAN_POS_DY:
	case SENSOR_CHAN_POS_DZ:
	case SENSOR_CHAN_POS_DXYZ:
		*base_size = sizeof(struct sensor_three_axis_data);
		*frame_size = sizeof(struct sensor_three_axis_sample_data);
		return 0;
@@ -481,6 +485,7 @@ static int decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
	case SENSOR_CHAN_POS_DX:
	case SENSOR_CHAN_POS_DY:
	case SENSOR_CHAN_POS_DZ:
	case SENSOR_CHAN_POS_DXYZ:
		count = decode_three_axis(header, q, data_out, SENSOR_CHAN_POS_DX,
					  SENSOR_CHAN_POS_DY, SENSOR_CHAN_POS_DZ,
					  chan_spec.chan_idx);
+4 −2
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ static const char *sensor_channel_name[SENSOR_CHAN_COMMON_COUNT] = {
	[SENSOR_CHAN_POS_DX] = "pos_dx",
	[SENSOR_CHAN_POS_DY] = "pos_dy",
	[SENSOR_CHAN_POS_DZ] = "pos_dz",
	[SENSOR_CHAN_POS_DXYZ] = "pos_dxyz",
	[SENSOR_CHAN_RPM] = "rpm",
	[SENSOR_CHAN_GAUGE_VOLTAGE] = "gauge_voltage",
	[SENSOR_CHAN_GAUGE_AVG_CURRENT] = "gauge_avg_current",
@@ -364,6 +365,7 @@ void sensor_shell_processing_callback(int result, uint8_t *buf, uint32_t buf_len
		case SENSOR_CHAN_MAGN_X:
		case SENSOR_CHAN_MAGN_Y:
		case SENSOR_CHAN_MAGN_Z:
		case SENSOR_CHAN_POS_DX:
		case SENSOR_CHAN_POS_DY:
		case SENSOR_CHAN_POS_DZ:
			continue;
@@ -392,7 +394,7 @@ void sensor_shell_processing_callback(int result, uint8_t *buf, uint32_t buf_len
				case SENSOR_CHAN_ACCEL_XYZ:
				case SENSOR_CHAN_GYRO_XYZ:
				case SENSOR_CHAN_MAGN_XYZ:
				case SENSOR_CHAN_POS_DX: {
				case SENSOR_CHAN_POS_DXYZ: {
					struct sensor_three_axis_data *data =
						(struct sensor_three_axis_data *)decoded_buffer;

@@ -446,7 +448,7 @@ void sensor_shell_processing_callback(int result, uint8_t *buf, uint32_t buf_len
			case SENSOR_CHAN_ACCEL_XYZ:
			case SENSOR_CHAN_GYRO_XYZ:
			case SENSOR_CHAN_MAGN_XYZ:
			case SENSOR_CHAN_POS_DX: {
			case SENSOR_CHAN_POS_DXYZ: {
				struct sensor_three_axis_data *data =
					(struct sensor_three_axis_data *)decoded_buffer;

+4 −2
Original line number Diff line number Diff line
@@ -150,6 +150,8 @@ enum sensor_channel {
	SENSOR_CHAN_POS_DY,
	/** Position change on the Z axis, in points. */
	SENSOR_CHAN_POS_DZ,
	/** Position change on the X, Y and Z axis, in points. */
	SENSOR_CHAN_POS_DXYZ,

	/** Revolutions per minute, in RPM. */
	SENSOR_CHAN_RPM,
@@ -929,12 +931,12 @@ struct __attribute__((__packed__)) sensor_data_generic_header {
 *
 * @param[in] chan The channel to check
 * @retval true if @p chan is any of @ref SENSOR_CHAN_ACCEL_XYZ, @ref SENSOR_CHAN_GYRO_XYZ, or
 *         @ref SENSOR_CHAN_MAGN_XYZ
 *         @ref SENSOR_CHAN_MAGN_XYZ, or @ref SENSOR_CHAN_POS_DXYZ
 * @retval false otherwise
 */
#define SENSOR_CHANNEL_3_AXIS(chan)                                                                \
	((chan) == SENSOR_CHAN_ACCEL_XYZ || (chan) == SENSOR_CHAN_GYRO_XYZ ||                      \
	 (chan) == SENSOR_CHAN_MAGN_XYZ)
	 (chan) == SENSOR_CHAN_MAGN_XYZ || (chan) == SENSOR_CHAN_POS_DXYZ)

/**
 * @brief Get the sensor's decoder API
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ struct sensor_data_header {
 * - :c:enum:`SENSOR_CHAN_POS_DX`
 * - :c:enum:`SENSOR_CHAN_POS_DY`
 * - :c:enum:`SENSOR_CHAN_POS_DZ`
 * - :c:enum:`SENSOR_CHAN_POS_DXYZ`
 */
struct sensor_three_axis_data {
	struct sensor_data_header header;
+4 −4
Original line number Diff line number Diff line
@@ -25,12 +25,12 @@ def test_sensor_shell_get(shell: Shell):
    assert any(['channel type=31(voltage)' in line for line in lines]), 'expected response not found'

    lines = shell.exec_command('sensor get sensor@1 53')
    assert any(['channel type=53(gauge_time_to_empty)' in line for line in lines]), 'expected response not found'
    assert any(['channel type=53(gauge_state_of_health)' in line for line in lines]), 'expected response not found'

    # Channel should be the last one before 'all' (because 'all' doesn't print anything) so that the
    # for-loop in `parse_named_int()` will go through everything
    lines = shell.exec_command('sensor get sensor@0 gauge_desired_charging_current')
    assert any(['channel type=58(gauge_desired_charging_current)' in line for line in lines]), 'expected response not found'
    assert any(['channel type=59(gauge_desired_charging_current)' in line for line in lines]), 'expected response not found'

    logger.info('response is valid')

@@ -42,7 +42,7 @@ def test_sensor_shell_attr_get(shell: Shell):
    assert any(['sensor@0(channel=co2, attr=sampling_frequency)' in line for line in lines]), 'expected response not found'

    lines = shell.exec_command('sensor attr_get sensor@1 53 3')
    assert any(['sensor@1(channel=gauge_time_to_empty, attr=slope_th)' in line for line in lines]), 'expected response not found'
    assert any(['sensor@1(channel=gauge_state_of_health, attr=slope_th)' in line for line in lines]), 'expected response not found'

    logger.info('response is valid')

@@ -55,7 +55,7 @@ def test_sensor_shell_attr_set(shell: Shell):
    assert any([expected_line in line for line in lines]), 'expected response not found'

    lines = shell.exec_command('sensor attr_set sensor@1 53 3 1')
    expected_line = 'sensor@1 channel=gauge_time_to_empty, attr=slope_th set to value=1'
    expected_line = 'sensor@1 channel=gauge_state_of_health, attr=slope_th set to value=1'
    assert any([expected_line in line for line in lines]), 'expected response not found'

    logger.info('response is valid')
Loading