Skip to content

Commit

Permalink
uv_cutoff smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrant committed Jul 24, 2023
1 parent 73f80d0 commit 53a5264
Showing 1 changed file with 51 additions and 54 deletions.
105 changes: 51 additions & 54 deletions smoke/uv_cutoff/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

// TODO(devAdhiraj): update with actual ports and pins
#define UV_CUTOFF_PORT GPIO_PORT_A
#define UV_CUTOFF_PIN 5
#define UV_CUTOFF_PIN 4

#define HORN_PORT GPIO_PORT_A
#define HORN_PIN 5
#define HORN_PORT GPIO_PORT_B
#define HORN_PIN 14

#define LIGHTS_PORT GPIO_PORT_A
#define LIGHTS_PIN 5
#define LIGHTS_PORT GPIO_PORT_B
#define LIGHTS_PIN 13

static const GpioAddress uv_status = { .port = UV_CUTOFF_PORT, .pin = UV_CUTOFF_PIN };

Expand Down Expand Up @@ -54,107 +54,104 @@ void uv_smoke_logic() {
if (state == UV_CUTOFF_DISCONNECTED) {
return;
}


if (get_horn_and_lights_horn_state() && !lights_check) {

GpioState horn_val;
gpio_get_state(&horn,&horn_val);
// LOG_DEBUG("Horn actual state = %d\n", horn_val);
if (horn_val == (GpioState) GPIO_STATE_LOW) {
status = gpio_set_state(&horn, GPIO_STATE_HIGH);
// if(status != STATUS_CODE_OK) {
// LOG_DEBUG("GPIO Horn State could not be set to high\n");
// }
g_rx_struct.horn_and_lights_horn_state = GPIO_STATE_HIGH;
if (status == STATUS_CODE_OK) {
gpio_get_state(&horn, &state_val);
// if( state_val != GPIO_STATE_HIGH) {
// LOG_DEBUG("Horn State not set correctly\n")
// } else if (state_val == GPIO_STATE_HIGH) {
// LOG_DEBUG("Horn State set correctly\n");
// }
}
} else {
status = gpio_set_state(&horn, GPIO_STATE_LOW);
// if(status != STATUS_CODE_OK) {
// LOG_DEBUG("GPIO Horn State could not be set to low\n");
// }
g_rx_struct.horn_and_lights_horn_state = GPIO_STATE_LOW;
if (status == STATUS_CODE_OK) {
gpio_get_state(&horn, &state_val);
// if( state_val != GPIO_STATE_LOW) {
// LOG_DEBUG("Horn State not set correctly\n")
// } else if (state_val == GPIO_STATE_LOW) {
// LOG_DEBUG("Horn state set correctly\n");
// }
}

}

if (get_horn_and_lights_lights_state() && lights_check) {
status = gpio_set_state(&lights, GPIO_STATE_HIGH);
// if(status != STATUS_CODE_OK) {
// LOG_DEBUG("GPIO Lights State could not be set to high\n");
// }
if (status == STATUS_CODE_OK) {
gpio_get_state(&lights, &state_val);
// if(state_Val != GPIO_STATE_HIGH) {
// LOG_DEBUG("Lights State not set correctly\n");
// } else if (state_val == GPIO_STATE_HIGH) {
// LOG_DEBUG("Lights State set correctly\n")
// }
}

} else {
status = gpio_set_state(&lights, GPIO_STATE_LOW);
// if(status != STATUS_CODE_OK) {
// LOG_DEBUG("GPIO Lights State could not be set to low\n");
// }
if (status == STATUS_CODE_OK) {
gpio_get_state(&lights, &state_val);
// if(state_val != GPIO_STATE_LOW) {
// LOG_DEBUG("Lights State not set correctly\n");
// } else if (state_val == GPIO_STATE_LOW) {
// LOG_DEBUG("Lights State set correctly\n");
// }
GpioState light_val;
if(lights_check) {
gpio_get_state(&lights, &light_val);
if ( light_val == (GpioState) GPIO_STATE_LOW) {
status = gpio_set_state(&lights, GPIO_STATE_HIGH);
g_rx_struct.horn_and_lights_lights_state = GPIO_STATE_HIGH;
if (status == STATUS_CODE_OK) {
gpio_get_state(&lights, &state_val);
}

} else {
status = gpio_set_state(&lights, GPIO_STATE_LOW);
g_rx_struct.horn_and_lights_lights_state = GPIO_STATE_LOW;
if (status == STATUS_CODE_OK) {
gpio_get_state(&lights, &state_val);
}
}
}

}

TASK(smoke_task, TASK_MIN_STACK_SIZE) {
//
//TEST 1 - Disconnected UV status
LOG_DEBUG("Running test for UV Disconnected state\n");
gpio_set_state(&uv_status,GPIO_STATE_LOW);
uv_smoke_logic();
assert( g_tx_struct.uv_cutoff_notification_signal1 == UV_CUTOFF_DISCONNECTED );
LOG_DEBUG("uv_cutoff notification signal set to 'UV_CUTOFF_DISCONNECTED'\n");
delay_ms(1000);
//TEST 2 - Active UV status
LOG_DEBUG("Running test for UV Active state\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
uv_smoke_logic();
assert( g_tx_struct.uv_cutoff_notification_signal1 == UV_CUTOFF_ACTIVE );
LOG_DEBUG("uv_cutoff notification signal set to 'UV_CUTOFF_ACTIVE'\n");
delay_ms(1000);
//TEST 3 - Horn state HIGH
LOG_DEBUG("Running test for Horn in state HIGH\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&horn,GPIO_STATE_HIGH);
lights_check = 0;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_HIGH);
assert(state_val == GPIO_STATE_LOW);
LOG_DEBUG("horn state set to LOW\n");
delay_ms(1000);
//TEST 4 - Lights state HIGH
LOG_DEBUG("Running test for Lights in state HIGH\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&lights,GPIO_STATE_HIGH);
lights_check = 1;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_HIGH);
assert(state_val == GPIO_STATE_LOW);
LOG_DEBUG("lights state set to LOW\n");
delay_ms(1000);
//TEST 5 - Horn state LOW
LOG_DEBUG("Running test for Horn in state LOW\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&horn,GPIO_STATE_LOW);
lights_check = 0;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_LOW);
assert(state_val == GPIO_STATE_HIGH);
LOG_DEBUG("horn state set to HIGH\n");
delay_ms(1000);
//TEST 6 - Lights state LOW
LOG_DEBUG("Running test for Lights in state LOW\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&lights,GPIO_STATE_LOW);
lights_check = 1;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_LOW);
assert(state_val == GPIO_STATE_HIGH);
LOG_DEBUG("lights state set to HIGH\n");
delay_ms(1000);
LOG_DEBUG("All tasks completed!\n");
}

int main() {
Expand All @@ -163,7 +160,7 @@ int main() {

gpio_init();

gpio_init_pin(&uv_status, GPIO_INPUT_PULL_UP, GPIO_STATE_HIGH);
gpio_init_pin(&uv_status, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH);
gpio_init_pin(&horn, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
gpio_init_pin(&lights, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);

Expand Down

0 comments on commit 53a5264

Please sign in to comment.