-
Notifications
You must be signed in to change notification settings - Fork 108
IIO: Support oversampling_ratio configuration in IIO node #2354
Conversation
b620098
to
89de6e9
Compare
@ceolin @edersondisouza @fulong82 @laykuanloon This PR is for issue #2330 please have a review. Thanks |
@@ -218,6 +218,12 @@ | |||
"name": "offset" | |||
}, | |||
{ | |||
"data_type": "direction-vector", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "data_type" should be "sol_str_table" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In iio.json, data_type cannot be sol_str_table here, please check https://github.com/solettaproject/soletta/blob/master/src/lib/common/include/sol-types.h
src/lib/io/sol-iio.c
Outdated
|
||
if (craft_filename_path(path, sizeof(path), CHANNEL_OVERSAMPLING_RATIO_DEVICE_PATH, | ||
device->device_id, iter->key)) { | ||
if (sol_util_write_file(path, "%d", iter->val) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magnetometer have 3 items in sol_str_table, this only write the 1st item and return ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is OK for us to test BMP280. Yes, this will result into magnet bugs. I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check
src/modules/flow/iio/nodes.c
Outdated
{ } | ||
}; | ||
|
||
mdata->iio_base.config.oversampling_ratio_table = table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong and will lead to memory issues!
The table
variable will no longer exists when magnet_open() exit, therefore mdata->iio_base.config.oversampling_ratio_table
will point to an invalid area!
src/modules/flow/iio/nodes.c
Outdated
{ } | ||
}; | ||
|
||
mdata->iio_base.config.oversampling_ratio_table = table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same problem
src/modules/flow/iio/nodes.c
Outdated
{ } | ||
}; | ||
|
||
mdata->iio_base.config.oversampling_ratio_table = table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same problem
char path[PATH_MAX]; | ||
struct sol_str_table *iter; | ||
|
||
SOL_NULL_CHECK(device, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a public API. Do you really need to make this check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YES, check the input parameter pointer in function "iio_set_sampling_frequency" too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as @cabelitos said this does not make sense. There is only one place where this function is called and you have already checked this parameter there. It's looking redundant.
@ceolin @edersondisouza @fulong82 @laykuanloon This PR is for issue #2330 According to your first round comments, update the PR and have a review, please. Thanks |
src/lib/io/sol-iio.c
Outdated
device->device_id, iter->key)) { | ||
if (sol_util_write_file(path, "%d", iter->val) <= 0) | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
craft_filename_path
fails is not an error ? you are only returning false when sol_util_write_file
fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified it.
src/modules/flow/iio/nodes.c
Outdated
SOL_NULL_CHECK(mdata->iio_base.config.oversampling_ratio_table, -ENOMEM); | ||
|
||
table = mdata->iio_base.config.oversampling_ratio_table; | ||
table->key = strdup("in_magn_x_"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have to check the return of strdup
, it can lead to a segv because you doing in the next line a strlen
with it.
Since you'll need to do this with the others elements, you can create a macro here to avoid repeat code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified it.
src/modules/flow/iio/nodes.c
Outdated
ret = snprintf(mdata->iio_base.config.sampling_frequency_name, | ||
sizeof(mdata->iio_base.config.sampling_frequency_name), "%s", "in_temp_"); | ||
SOL_INT_CHECK_GOTO(ret, >= (int)sizeof(mdata->iio_base.config.sampling_frequency_name), err); | ||
SOL_INT_CHECK_GOTO(ret, < 0, err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but we have a macro called SOL_EXP_CHECK_GOTO
that an be used here to avoid two checks.
src/modules/flow/iio/nodes.c
Outdated
|
||
table = mdata->iio_base.config.oversampling_ratio_table; | ||
table->key = strdup("in_temp_"); | ||
table->len = strlen(table->key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
src/modules/flow/iio/nodes.c
Outdated
|
||
table = mdata->iio_base.config.oversampling_ratio_table; | ||
table->key = strdup("in_pressure_"); | ||
table->len = strlen(table->key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dito
Signed-off-by: Gu Chaojie <[email protected]>
@ceolin @edersondisouza @fulong82 @laykuanloon This PR is for issue #2330 According to your comments, update the PR and have a review, please. Thanks |
@ceolin @cabelitos @laykuanloon any more comments for the PR? We want to have this for BMP/BME 280 support in Soletta. |
I guess we're fine. |
yep, looks good. |
Signed-off-by: Gu Chaojie [email protected]