Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatma J Onboarding #196

Open
wants to merge 2 commits into
base: level3
Choose a base branch
from
Open

Conversation

TheRealGecko
Copy link

Purpose

To check my onboarding

New Changes

Did onboarding

Testing

Looked at the test cases in the output

Outstanding Changes

Idk

@Yarik-Popov Yarik-Popov changed the title did the thing Fatma J Onboarding Nov 1, 2024
Copy link

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

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

Overall good start, some changes are needed to improve the code quality

lm75bd/lm75bd.c Outdated
@@ -27,7 +27,17 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */

uint8_t sendBuf[1] = {0x0U};
uint8_t buffer[2];

Choose a reason for hiding this comment

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

Initialize the buffer

lm75bd/lm75bd.c Outdated
Comment on lines 32 to 33
i2cSendTo (devAddr, sendBuf, 1U);
i2cReceiveFrom (devAddr, buffer, 2U);

Choose a reason for hiding this comment

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

  • wrap both lines inside of a RETURN_IF_ERROR_CODE
  • use sizeof(sendBuf) instead of 1
  • use sizeof(buffer) instead of 2

@@ -43,18 +43,32 @@ void initThermalSystemManager(lm75bd_config_t *config) {

error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) {
/* Send an event to the thermal manager queue */
xQueueSend(thermalMgrQueueHandle, event, 0); // why u throwing error

Choose a reason for hiding this comment

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

  • check to make sure that thermal mgr queue isn't null before use, returning invalid state
  • check to make sure that the event isn't null
  • in general, you should be checking the return value of non void functions for errors and handling them accordingly

lm75bd/lm75bd.c Show resolved Hide resolved
Comment on lines 53 to 60
float temp;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);

if(temp > 80) {
overTemperatureDetected();
} else if(temp < 75) {
safeOperatingConditions();
}

Choose a reason for hiding this comment

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

Do not read inside the os handler as it may block. Send an event and have the thermalMgr task function handle it

Comment on lines 56 to 58
if(temp > 80) {
overTemperatureDetected();
} else if(temp < 75) {

Choose a reason for hiding this comment

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

Use the macros defined in the lm75bd.h instead of hardocding the values

thermal_mgr_event_t data = *(thermal_mgr_event_t *) pvParameters;
if(xQueueReceive(thermalMgrQueueHandle, pvParameters, 0) == pdTRUE && data.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { // ensure about the tick time + how to checl the type ajsdkfk
float temp;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);

Choose a reason for hiding this comment

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

Check the return value for an error code, log it if it exists and continue. we don't want to add a temp value that failed to read we don't know if temp will be a valid value

}

static void thermalMgr(void *pvParameters) {
/* Implement this task */
while (1) {

thermal_mgr_event_t data = *(thermal_mgr_event_t *) pvParameters;
if(xQueueReceive(thermalMgrQueueHandle, pvParameters, 0) == pdTRUE && data.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { // ensure about the tick time + how to checl the type ajsdkfk

Choose a reason for hiding this comment

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

  • Use portMAX_DELAY instead of 0
  • you should be logging if an invalid event was received

lm75bd/lm75bd.c Outdated
Comment on lines 34 to 40
uint8_t a = 1U;
uint8_t mask = a << 7;
if (!(buffer[0] & mask)) {
*temp = ((buffer[0] << 3) | (buffer[1] >> 5)) * 0.125;
} else {
*temp = -(((~((buffer[0] << 3) | (buffer[1] >> 5))) & (0b0000011111111111)) + 1) * 0.125;
}

Choose a reason for hiding this comment

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

the code is overly complicated

Suggested change
uint8_t a = 1U;
uint8_t mask = a << 7;
if (!(buffer[0] & mask)) {
*temp = ((buffer[0] << 3) | (buffer[1] >> 5)) * 0.125;
} else {
*temp = -(((~((buffer[0] << 3) | (buffer[1] >> 5))) & (0b0000011111111111)) + 1) * 0.125;
}
int16_t temperature = ((buffer[0] << 8) | buffer[1]) >> 5;
*temp = temperature * 0.125;

You might need to do some casting to get this to work

Copy link

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

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

A step in the right direction, there are still some changes that need to be handled

@@ -43,18 +44,47 @@ void initThermalSystemManager(lm75bd_config_t *config) {

error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) {
/* Send an event to the thermal manager queue */

return ERR_CODE_SUCCESS;
if(thermalMgrQueueHandle != NULL && event != NULL) {

Choose a reason for hiding this comment

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

  • return invalid argument if event is null
  • return invalid state if thermal mgr queue handle is null as its not an argument but a state variable


return ERR_CODE_SUCCESS;
if(thermalMgrQueueHandle != NULL && event != NULL) {
xQueueSend(thermalMgrQueueHandle, event, 0);

Choose a reason for hiding this comment

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

In general, you should check the return of non-void functions for error codes and handle them

}

static void thermalMgr(void *pvParameters) {
/* Implement this task */
while (1) {

thermal_mgr_event_t data = *(thermal_mgr_event_t *) pvParameters;

Choose a reason for hiding this comment

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

PvParameters is not of type thermal mgr event but of the lm75bd config so you shouldn't do this. Just thermal_mgr_event_t event={0};


thermal_mgr_event_t data = *(thermal_mgr_event_t *) pvParameters;

error_code_t errCodeEvent = xQueueReceive(thermalMgrQueueHandle, pvParameters, portMAX_DELAY);

Choose a reason for hiding this comment

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

The return type of xQueueReceive isn't error_code_t. Only the functions we write on the team use that custom error code. Libraries have there own

}
addTemperatureTelemetry(temp);
} else if(data.type == THERMAL_MGR_EVENT_OS_INTERRUPT) {
if(temp > LM75BD_DEFAULT_OT_THRESH) {

Choose a reason for hiding this comment

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

You should be reading the temperature when you get an over temperature event as if temp wasn't read for a while the value might be stale and not represent the current temperature

Comment on lines +38 to +45
uint8_t a = 1U;
uint8_t mask = a << 7;
int16_t temperature = ((buffer[0] << 8) | buffer[1]) >> 5;
if (!(buffer[0] & mask)) {
*temp = temperature * 0.125;
} else {
*temp = -((~temperature & 0b0000011111111111) + 1) * 0.125;
}

Choose a reason for hiding this comment

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

Out of these lines, you only need lines 40 and 42. You might need to cast the temperature before assign it to temp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants