Skip to content

Commit

Permalink
Added files I forgot
Browse files Browse the repository at this point in the history
  • Loading branch information
avtoku committed Nov 13, 2024
1 parent 280f91e commit 70f37f7
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 66 deletions.
35 changes: 14 additions & 21 deletions common/Varmint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ uint16_t Varmint::sensors_init_message_count() { return varmint.status_len(); }
bool Varmint::sensors_init_message_good(uint16_t i) { return varmint.status(i)->initGood(); }

uint16_t Varmint::sensors_init_message(char * message, uint16_t size, uint16_t i)
{
{
if (i > varmint.status_len()) return 0;

uint32_t status = varmint.status(i)->status();
Expand All @@ -145,7 +145,7 @@ uint16_t Varmint::sensors_init_message(char * message, uint16_t size, uint16_t i

///////////////////////////////////////////////////////////////////////////////////////////////
// IMU
bool Varmint::imu_read(rosflight_firmware::ImuStruct *imu)
bool Varmint::imu_read(rosflight_firmware::ImuStruct * imu)
{
ImuPacket p;
if (imu0_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
Expand All @@ -166,7 +166,7 @@ void Varmint::imu_not_responding_error(){};

///////////////////////////////////////////////////////////////////////////////////////////////
// MAG
bool Varmint::mag_read(rosflight_firmware::MagStruct *mag)
bool Varmint::mag_read(rosflight_firmware::MagStruct * mag)
{
MagPacket p;
if (mag_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
Expand All @@ -182,7 +182,7 @@ bool Varmint::mag_read(rosflight_firmware::MagStruct *mag)

///////////////////////////////////////////////////////////////////////////////////////////////
// Baro
bool Varmint::baro_read(rosflight_firmware::PressureStruct *baro)
bool Varmint::baro_read(rosflight_firmware::PressureStruct * baro)
{
PressurePacket p;
if (baro_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
Expand All @@ -196,7 +196,7 @@ bool Varmint::baro_read(rosflight_firmware::PressureStruct *baro)

///////////////////////////////////////////////////////////////////////////////////////////////
// Pitot
bool Varmint::diff_pressure_read(rosflight_firmware::PressureStruct *diff_pressure)
bool Varmint::diff_pressure_read(rosflight_firmware::PressureStruct * diff_pressure)
{
PressurePacket p;
if (pitot_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
Expand All @@ -210,15 +210,15 @@ bool Varmint::diff_pressure_read(rosflight_firmware::PressureStruct *diff_pressu

///////////////////////////////////////////////////////////////////////////////////////////////
// Sonar
bool Varmint::sonar_read(rosflight_firmware::RangeStruct *sonar)
bool Varmint::sonar_read(rosflight_firmware::RangeStruct * sonar)
{
(void)sonar; // unused
(void) sonar; // unused
return false;
}

///////////////////////////////////////////////////////////////////////////////////////////////
// Battery
bool Varmint::battery_read(rosflight_firmware::BatteryStruct *batt)
bool Varmint::battery_read(rosflight_firmware::BatteryStruct * batt)
{
AdcPacket p;
if (adc_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
Expand Down Expand Up @@ -286,7 +286,7 @@ bool Varmint::gnss_read(rosflight_firmware::GnssStruct * gnss)
gnss->vel_d = p.pvt.velD;
gnss->speed_accy = p.pvt.sAcc;
gnss->mag_var = p.pvt.magDec;
gnss->valid = ( (p.pvt.flags & 0x01)!=0 ) ;
gnss->valid = ((p.pvt.flags & 0x01) != 0);
gnss->num_sat = p.pvt.numSV;
gnss->dop = p.pvt.pDOP;
gnss->fix_type = p.pvt.fixType;
Expand All @@ -311,23 +311,16 @@ bool Varmint::gnss_read(rosflight_firmware::GnssStruct * gnss)

///////////////////////////////////////////////////////////////////////////////////////////////
// RC
void Varmint::rc_init(rc_type_t rc_type)
{
rcPacketEverRead_ = false;
};
void Varmint::rc_init(rc_type_t rc_type) { rcPacketEverRead_ = false; };
bool Varmint::rc_lost() { return rc_.lol(); }
bool Varmint::rc_read(rosflight_firmware::RcStruct *rc_struct)
bool Varmint::rc_read(rosflight_firmware::RcStruct * rc_struct)
{
RcPacket p;

if (rc_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p)))
{
if (rc_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
rc_struct->timestamp = p.timestamp;
uint16_t len = RC_STRUCT_CHANNELS<RC_PACKET_CHANNELS?RC_STRUCT_CHANNELS:RC_PACKET_CHANNELS;
for(uint16_t i=0;i<len;i++)
{
rc_struct->chan[i]=p.chan[i];
}
uint16_t len = RC_STRUCT_CHANNELS < RC_PACKET_CHANNELS ? RC_STRUCT_CHANNELS : RC_PACKET_CHANNELS;
for (uint16_t i = 0; i < len; i++) { rc_struct->chan[i] = p.chan[i]; }
rc_struct->frameLost = p.frameLost;
rc_struct->failsafeActivated = p.failsafeActivated;
return true;
Expand Down
16 changes: 8 additions & 8 deletions common/Varmint.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
#include <Telem.h>
#include <Ubx.h>
#include <Vcp.h>
#include <sensors.h>
#include <board.h>
#include <sensors.h>

#include <BoardConfig.h>

Expand Down Expand Up @@ -114,20 +114,20 @@ class Varmint : public rosflight_firmware::Board
uint16_t sensors_init_message(char * message, uint16_t size, uint16_t i) override;
bool sensors_init_message_good(uint16_t i) override;

bool imu_read(rosflight_firmware::ImuStruct *imu) override;
bool imu_read(rosflight_firmware::ImuStruct * imu) override;

void imu_not_responding_error() override;

bool mag_read(rosflight_firmware::MagStruct *mag) override;
bool mag_read(rosflight_firmware::MagStruct * mag) override;

bool baro_read(rosflight_firmware::PressureStruct *baro) override;
bool baro_read(rosflight_firmware::PressureStruct * baro) override;

bool diff_pressure_read(rosflight_firmware::PressureStruct *diff_pressure) override;
bool diff_pressure_read(rosflight_firmware::PressureStruct * diff_pressure) override;

bool sonar_read(rosflight_firmware::RangeStruct *sonar) override;
bool sonar_read(rosflight_firmware::RangeStruct * sonar) override;

// Battery
bool battery_read(rosflight_firmware::BatteryStruct *bat) override;
bool battery_read(rosflight_firmware::BatteryStruct * bat) override;
//bool battery_present() override;
void battery_voltage_set_multiplier(double multiplier) override;
void battery_current_set_multiplier(double multiplier) override;
Expand All @@ -138,7 +138,7 @@ class Varmint : public rosflight_firmware::Board
// RC
void rc_init(rc_type_t rc_type) override;
bool rc_lost() override;
bool rc_read(rosflight_firmware::RcStruct * rc) override;
bool rc_read(rosflight_firmware::RcStruct * rc) override;

// PWM
void pwm_init(const float * rate, uint32_t channels) override;
Expand Down
2 changes: 1 addition & 1 deletion common/drivers/Auav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ PollingState Auav::state(uint64_t poll_counter)
// Pitot
{1, AUAV_PITOT_CMD},
{74, AUAV_PITOT_RX}, // 7.2ms
// Baro
// Baro
{0, AUAV_BARO_CMD},
{73, AUAV_BARO_RX}, // 9.4ms
};
Expand Down
22 changes: 11 additions & 11 deletions common/drivers/Sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ uint32_t Sd::init(SD_HandleTypeDef * hsd, SD_TypeDef * hsd_instance)
return initializationStatus_;
}


#define SD_CRC_BYTES sizeof(uint32_t)

bool Sd::read(uint8_t * dest, size_t len)
Expand All @@ -109,10 +108,11 @@ bool Sd::read(uint8_t * dest, size_t len)
// CRC must be set-up for byte sized data, i.e., hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES
// I'm not bothering to code for the case of data in any other format
if (hcrc.InputDataFormat != CRC_INPUTDATA_FORMAT_BYTES) { return false; }
uint32_t crc = HAL_CRC_Calculate(&hcrc,(uint32_t *) sd_rx_buf, len); // len Assumes hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES
uint8_t *crc2 = (uint8_t*)(&crc);
uint8_t *crc1 = (uint8_t*)(&(sd_rx_buf[len]));
if((crc1[0] != crc2[0])||(crc1[1] != crc2[1])||(crc1[2] != crc2[2])||(crc1[3] != crc2[3])) { return false; }
uint32_t crc = HAL_CRC_Calculate(&hcrc, (uint32_t *) sd_rx_buf,
len); // len Assumes hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES
uint8_t * crc2 = (uint8_t *) (&crc);
uint8_t * crc1 = (uint8_t *) (&(sd_rx_buf[len]));
if ((crc1[0] != crc2[0]) || (crc1[1] != crc2[1]) || (crc1[2] != crc2[2]) || (crc1[3] != crc2[3])) { return false; }
memcpy(dest, sd_rx_buf, len);
}

Expand All @@ -130,12 +130,12 @@ bool Sd::write(uint8_t * src, size_t len)
// CRC must be set-up for byte sized data hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES
// I'm not bothering to code for the case of data in any other format
if (hcrc.InputDataFormat != CRC_INPUTDATA_FORMAT_BYTES) { return false; }
uint32_t crc = HAL_CRC_Calculate(&hcrc,(uint32_t *) sd_tx_buf, len);
uint8_t *crc2 = (uint8_t*)(&crc);
sd_tx_buf[len] = crc2[0];
sd_tx_buf[len+1] = crc2[1];
sd_tx_buf[len+2] = crc2[2];
sd_tx_buf[len+3] = crc2[3];
uint32_t crc = HAL_CRC_Calculate(&hcrc, (uint32_t *) sd_tx_buf, len);
uint8_t * crc2 = (uint8_t *) (&crc);
sd_tx_buf[len] = crc2[0];
sd_tx_buf[len + 1] = crc2[1];
sd_tx_buf[len + 2] = crc2[2];
sd_tx_buf[len + 3] = crc2[3];

hal_status = HAL_SD_WriteBlocks_DMA(hsd_, sd_tx_buf, 0, Nblocks);
if (hal_status != HAL_OK) return false;
Expand Down
1 change: 1 addition & 0 deletions common/drivers/Spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Spi : public Status
SPI_HandleTypeDef * hspi_;
uint8_t * txBuffer_;
uint8_t * rxBuffer_;

public:
// uint16_t size_;
GPIO_TypeDef * port_;
Expand Down
6 changes: 3 additions & 3 deletions common/drivers/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
class Status
{
public:
Status() { initializationStatus_ = DRIVER_NOT_INITIALIZED;}
Status() { initializationStatus_ = DRIVER_NOT_INITIALIZED; }
bool initGood(void) { return initializationStatus_ == DRIVER_OK; }
uint32_t status() { return initializationStatus_;}
char *name() { return name_;}
uint32_t status() { return initializationStatus_; }
char * name() { return name_; }

protected:
uint32_t initializationStatus_ = DRIVER_NOT_INITIALIZED;
Expand Down
2 changes: 1 addition & 1 deletion pixracer_pro/specific/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#define SANDBOX false
#define BOARD_STATUS_PRINT false
#define USE_TELEM 0 // 1 = use UART, 0 = use VCP for link to companion computer.
#define USE_TELEM 0 // 1 = use UART, 0 = use VCP for link to companion computer.

// UART used for printf's
#define MISC_HUART (&huart2)
Expand Down
16 changes: 9 additions & 7 deletions pixracer_pro/specific/Varmint_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ void Varmint::init_board(void)
// misc_printf uses the timer, so can't be used before it's initialized.

#define ASCII_ESC 27
misc_printf("\n\n%c[H", ASCII_ESC); // home
misc_printf("%c[2J", ASCII_ESC); // clear screen
misc_printf("\n\n%c[H", ASCII_ESC); // home
misc_printf("%c[2J", ASCII_ESC); // clear screen

misc_printf("\nTime64 Startup\n");
misc_exit_status(init_status);
Expand Down Expand Up @@ -238,12 +238,14 @@ void Varmint::init_board(void)
// Review Status List

misc_printf("\n\nStatus List:\n");
for(uint32_t i = 0; i<status_len_ ; i++)
{
for (uint32_t i = 0; i < status_len_; i++) {
//status_list_[i]->print();
if(status_list_[i]->initGood()) { misc_printf("\033[0;42m"); }
else { misc_printf("\033[0;41m");}
misc_printf("%-16s Status: 0x%08X",status_list_[i]->name(),status_list_[i]->status());
if (status_list_[i]->initGood()) {
misc_printf("\033[0;42m");
} else {
misc_printf("\033[0;41m");
}
misc_printf("%-16s Status: 0x%08X", status_list_[i]->name(), status_list_[i]->status());
misc_printf("\033[0m\n");
}

Expand Down
2 changes: 1 addition & 1 deletion test/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Board
virtual uint16_t sensors_init_message(char * message, uint16_t size, uint16_t i) = 0;

// IMU
virtual bool imu_present() =0;
virtual bool imu_present() = 0;
virtual bool imu_has_new_data() = 0;
virtual bool imu_read(float accel[3], float * temperature, float gyro[3], uint64_t * time) = 0;
virtual void imu_not_responding_error() = 0;
Expand Down
2 changes: 1 addition & 1 deletion varmint_10X/specific/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#define SANDBOX false
#define BOARD_STATUS_PRINT false
#define USE_TELEM 0 // 1 = use UART, 0 = use VCP for link to companion computer.
#define USE_TELEM 0 // 1 = use UART, 0 = use VCP for link to companion computer.

// UART used for printf's
#define MISC_HUART (&huart2)
Expand Down
26 changes: 14 additions & 12 deletions varmint_10X/specific/Varmint_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ void Varmint::init_board(void)
// MX_ADC1_Init(); // initialized elsewhere
// MX_ADC3_Init(); // initialized elsewhere
// MX_USB_DEVICE_Init(); // initialized elsewhere
MX_FDCAN1_Init(); // not used
// MX_SDMMC1_SD_Init(); // initialized elsewhere
MX_RTC_Init(); // not used
MX_CRC_Init(); // Used for SD Card data checksum
MX_RNG_Init(); // not used
MX_FDCAN1_Init(); // not used
// MX_SDMMC1_SD_Init(); // initialized elsewhere
MX_RTC_Init(); // not used
MX_CRC_Init(); // Used for SD Card data checksum
MX_RNG_Init(); // not used

#if _USBD_USE_HS // USB HS (480MB/s
MX_USB_OTG_HS_PCD_Init();
Expand All @@ -125,8 +125,8 @@ void Varmint::init_board(void)
init_status = time64.init(HTIM_LOW, HTIM_LOW_INSTANCE, HTIM_HIGH, HTIM_HIGH_INSTANCE);

#define ASCII_ESC 27
misc_printf("\n\n%c[H", ASCII_ESC); // home
misc_printf("%c[2J", ASCII_ESC); // clear screen
misc_printf("\n\n%c[H", ASCII_ESC); // home
misc_printf("%c[2J", ASCII_ESC); // clear screen

misc_printf("\nTime64 Startup\n");
misc_exit_status(init_status);
Expand Down Expand Up @@ -240,12 +240,14 @@ void Varmint::init_board(void)
// Review Status List

misc_printf("\n\nStatus List:\n");
for(uint32_t i = 0; i<status_len_ ; i++)
{
for (uint32_t i = 0; i < status_len_; i++) {
//status_list_[i]->print();
if(status_list_[i]->initGood()) { misc_printf("\033[0;42m"); }
else { misc_printf("\033[0;41m");}
misc_printf("%-16s Status: 0x%08X",status_list_[i]->name(),status_list_[i]->status());
if (status_list_[i]->initGood()) {
misc_printf("\033[0;42m");
} else {
misc_printf("\033[0;41m");
}
misc_printf("%-16s Status: 0x%08X", status_list_[i]->name(), status_list_[i]->status());
misc_printf("\033[0m\n");
}

Expand Down

0 comments on commit 70f37f7

Please sign in to comment.