commands/commands.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | ****************************************************************************** | ||
| 3 | * @file : commands.c | ||
| 4 | * @brief : Contains general command functions common to all embedded controllers | ||
| 5 | ****************************************************************************** | ||
| 6 | * @copyright | ||
| 7 | * | ||
| 8 | * Copyright (c) 2025 Sun Devil Rocketry. | ||
| 9 | * All rights reserved. | ||
| 10 | * | ||
| 11 | * This software is licensed under terms that can be found in the LICENSE | ||
| 12 | * file in the root directory of this software component. | ||
| 13 | * If no LICENSE file comes with this software, it is covered under the | ||
| 14 | * BSD-3-Clause. | ||
| 15 | * | ||
| 16 | * https://opensource.org/license/bsd-3-clause | ||
| 17 | * | ||
| 18 | ****************************************************************************** | ||
| 19 | */ | ||
| 20 | |||
| 21 | |||
| 22 | /*------------------------------------------------------------------------------ | ||
| 23 | Standard Includes | ||
| 24 | ------------------------------------------------------------------------------*/ | ||
| 25 | #include <stdbool.h> | ||
| 26 | #include <string.h> | ||
| 27 | |||
| 28 | /*------------------------------------------------------------------------------ | ||
| 29 | Project Includes | ||
| 30 | ------------------------------------------------------------------------------*/ | ||
| 31 | #include "main.h" | ||
| 32 | #include "commands.h" | ||
| 33 | #include "usb.h" | ||
| 34 | #include "sensor.h" | ||
| 35 | |||
| 36 | /*------------------------------------------------------------------------------ | ||
| 37 | Globals | ||
| 38 | ------------------------------------------------------------------------------*/ | ||
| 39 | extern SENSOR_DATA sensor_data; | ||
| 40 | |||
| 41 | /*------------------------------------------------------------------------------ | ||
| 42 | Procedures | ||
| 43 | ------------------------------------------------------------------------------*/ | ||
| 44 | |||
| 45 | |||
| 46 | /** | ||
| 47 | * @brief Sends a 1 byte response back to host PC to signal a functioning | ||
| 48 | * serial connection | ||
| 49 | */ | ||
| 50 | 1 | void ping | |
| 51 | ( | ||
| 52 | void | ||
| 53 | ) | ||
| 54 | { | ||
| 55 | /*------------------------------------------------------------------------------ | ||
| 56 | Local variables | ||
| 57 | ------------------------------------------------------------------------------*/ | ||
| 58 | 1 | uint8_t response; /* A0002 Response Code */ | |
| 59 | |||
| 60 | /*------------------------------------------------------------------------------ | ||
| 61 | Initializations | ||
| 62 | ------------------------------------------------------------------------------*/ | ||
| 63 | 1 | response = PING_RESPONSE_CODE; /* Code specific to board and revision */ | |
| 64 | |||
| 65 | /*------------------------------------------------------------------------------ | ||
| 66 | Command Implementation | ||
| 67 | ------------------------------------------------------------------------------*/ | ||
| 68 | 1 | usb_transmit( &response, sizeof( response ), HAL_DEFAULT_TIMEOUT ); | |
| 69 | |||
| 70 | 1 | } /* ping */ | |
| 71 | |||
| 72 | |||
| 73 | #ifdef A0002_REV2 | ||
| 74 | /** | ||
| 75 | * @brief Sends the data required by the dashboard. | ||
| 76 | * | ||
| 77 | * @return USB transmission status. | ||
| 78 | */ | ||
| 79 | 2 | USB_STATUS dashboard_dump | |
| 80 | ( | ||
| 81 | void | ||
| 82 | ) | ||
| 83 | { | ||
| 84 | /*------------------------------------------------------------------------------ | ||
| 85 | Local variables | ||
| 86 | ------------------------------------------------------------------------------*/ | ||
| 87 | 2 | DASHBOARD_DUMP_TYPE buffer; | |
| 88 | 2 | SENSOR_STATUS sensor_status = SENSOR_OK; | |
| 89 | |||
| 90 | 2 | sensor_status = sensor_dump( &sensor_data ); | |
| 91 | |||
| 92 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2 | if ( !( sensor_status == SENSOR_OK ) ) |
| 93 | { | ||
| 94 | return USB_FAIL; | ||
| 95 | } | ||
| 96 | |||
| 97 | 1 | dashboard_construct_dump( &buffer ); | |
| 98 | |||
| 99 | 1 | return usb_transmit( &buffer, | |
| 100 | DASHBOARD_DUMP_SIZE, | ||
| 101 | HAL_SENSOR_TIMEOUT /* more forgiving HW timeout */ ); | ||
| 102 | } /* dashboard_dump */ | ||
| 103 | |||
| 104 | |||
| 105 | /** | ||
| 106 | * @brief Fill the buffer with the dashboard dump. | ||
| 107 | * | ||
| 108 | * @param dump_buffer_ptr Pointer to the dashboard dump buffer. Must be | ||
| 109 | * DASHBOARD_DUMP_SIZE. | ||
| 110 | */ | ||
| 111 | 2 | void dashboard_construct_dump | |
| 112 | ( | ||
| 113 | DASHBOARD_DUMP_TYPE* dump_buffer_ptr /* must be DASHBOARD_DUMP_SIZE */ | ||
| 114 | ) | ||
| 115 | { | ||
| 116 | /* Quats */ | ||
| 117 | 2 | dump_buffer_ptr->attitude = sensor_data.state_estimate.attitude; | |
| 118 | |||
| 119 | /* Baro */ | ||
| 120 | 2 | dump_buffer_ptr->alt = sensor_data.baro_alt; | |
| 121 | |||
| 122 | /* GPS */ | ||
| 123 | 2 | dump_buffer_ptr->longitude = sensor_data.gps_dec_longitude; | |
| 124 | 2 | dump_buffer_ptr->latitude = sensor_data.gps_dec_latitude; | |
| 125 | |||
| 126 | /* Controls */ | ||
| 127 | 2 | dump_buffer_ptr->acc_x = sensor_data.imu_converted.accel_x; | |
| 128 | 2 | dump_buffer_ptr->roll_rate = sensor_data.state_estimate.roll_rate; | |
| 129 | |||
| 130 | 2 | } | |
| 131 | #endif | ||
| 132 | |||
| 133 | |||
| 134 | /******************************************************************************* | ||
| 135 | * END OF FILE * | ||
| 136 | *******************************************************************************/ | ||
| 137 |