Skip to content

Code Review & Discussion#1

Draft
electricalgorithm wants to merge 21 commits into
code-reviewfrom
main
Draft

Code Review & Discussion#1
electricalgorithm wants to merge 21 commits into
code-reviewfrom
main

Conversation

@electricalgorithm

Copy link
Copy Markdown
Owner

This pull request is a draft PR that will be used for code-review and discussion for the life-time of the repo.

@electricalgorithm electricalgorithm added the enhancement New feature or request label Jul 24, 2023
@electricalgorithm electricalgorithm self-assigned this Jul 24, 2023
Comment thread includes/bluetooth_interface.h
Comment thread includes/bluetooth_interface.h
Comment thread includes/bluetooth_interface.h
Comment thread src/sensor_interface.c
Comment on lines +31 to +42
if (dev == NULL) {
/* No such node, or the node does not have status "okay". */
LOG_WRN("No BME280 sensor found. Will be using simulator instead.");
return NULL;
}

if (!device_is_ready(dev)) {
LOG_ERR("Error: Device \"%s\" is not ready. Check the driver initialization logs for errors.",
dev->name);
return NULL;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debug purposes it is okay but if the outcome is same for the upper modules, you can just use the if(NULL == dev && device_is_read(dev))

Comment thread src/sensor_interface.c
const struct device *get_bme280_device(void) {
const struct device *const dev = DEVICE_DT_GET_ANY(bosch_bme280);

if (dev == NULL) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are using an if against a macro, macro should be written first such as (NULL == dev), this eliminates the errors such as (dev = NULL).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more info on the subject, I didn't get the point. Should we put the macro first, or last? Why would it be a problem to have macro output as NULL?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When evaluating the equality of a variable against a constant, the constant should be on the left side. Such as,

	if (NULL == dev)

This eliminates the errors such as accidently making the variable equal to the constant, which is a really hard to bug to catch.

	if (dev = NULL) // This is a very hard bug to catch. 

Comment thread src/main.c

while (1) {
// Wait for the semaphore to be available.
if (k_sem_take(&semaphore_send_ready, K_NO_WAIT) == 0) {

@Yusufss4 Yusufss4 Jul 29, 2023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is usually good option to hide the semaphores under a module or function that owns them, such as is_data_ready_to_send()

Comment thread src/main.c
notify_ble_connected_device(filtered_values);

// Free the memory.
k_free(filtered_values);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a static buffer would also eliminate the need for the freeing them because you were just going to overwrite the older values.

Comment thread src/bluetooth_interface.c

void notify_ble_connected_device(struct values_for_ble_t *value_to_notify) {
// Save the int part and dec part of the reading into an array.
temp_reading = value_to_notify->temp_reading_int * 100 + value_to_notify->temp_reading_dec * 0.0001;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is some kind of conversion it is better to use function like macros for readbility and for elimating the duplication, such as,

Suggested change
temp_reading = value_to_notify->temp_reading_int * 100 + value_to_notify->temp_reading_dec * 0.0001;
temp_reading = SCALED_NUM_TO_INT(value_to_notify->temp_reading_int, value_to_notify->temp_reading_dec)

Comment thread src/bluetooth_interface.c
}


void notify_ble_connected_device(struct values_for_ble_t *value_to_notify) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const if not modified

Comment thread includes/structs.h
Comment on lines +13 to +18
struct sensor_value_store_t {
void *lifo_reserved;
struct sensor_value temperature;
struct sensor_value pressure;
// struct sensor_value humidity;
}; No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use typedefs such as, the t suffix is for the typedef.

Suggested change
struct sensor_value_store_t {
void *lifo_reserved;
struct sensor_value temperature;
struct sensor_value pressure;
// struct sensor_value humidity;
};
typedef struct sensor_value_store_t {
void *lifo_reserved;
struct sensor_value temperature;
struct sensor_value pressure;
// struct sensor_value humidity;
}; sensor_value_store_t;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants