Skip to content

Commit

Permalink
potentially flyable ns-124 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Shipman committed Feb 25, 2024
1 parent ff57157 commit eda0d27
Show file tree
Hide file tree
Showing 8 changed files with 19,218 additions and 19,420 deletions.
Binary file modified Code/BITS/BITSv5/flight/build/CMakeFiles/flight.dir/flight.cpp.obj
Binary file not shown.
Binary file modified Code/BITS/BITSv5/flight/build/flight.bin
Binary file not shown.
32,213 changes: 16,002 additions & 16,211 deletions Code/BITS/BITSv5/flight/build/flight.dis

Large diffs are not rendered by default.

Binary file modified Code/BITS/BITSv5/flight/build/flight.elf
Binary file not shown.
1,337 changes: 668 additions & 669 deletions Code/BITS/BITSv5/flight/build/flight.elf.map

Large diffs are not rendered by default.

4,962 changes: 2,474 additions & 2,488 deletions Code/BITS/BITSv5/flight/build/flight.hex

Large diffs are not rendered by default.

Binary file modified Code/BITS/BITSv5/flight/build/flight.uf2
Binary file not shown.
126 changes: 74 additions & 52 deletions Code/BITS/BITSv5/flight/flight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ DRF1262 radio(spi1, CS_PIN, SCK_PIN, MOSI_PIN, MISO_PIN, TXEN_PIN, DIO1_PIN,

char id[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1] = {0};

short debug_msgs = 0; // controls if debug messages are printed

char radio_rx_buf[100] = {0};
uint8_t radio_tx_buf[100] = {0};
uint8_t radio_ack_buf[100] = {0};
Expand All @@ -46,21 +44,16 @@ void led_on();
void led_off();
void gpio_callback(uint gpio, uint32_t events);
bool tx_timer_callback(repeating_timer_t *rt);
void get_gps_data(void);

// FLIGHT CODE
int main() {
stdio_init_all();

// set_sys_clock_48mhz();

gpio_set_irq_enabled_with_callback(DIO1_PIN, GPIO_IRQ_EDGE_RISE, true,
&gpio_callback);

uart_init(uart1, 9600);
gpio_set_function(SCL_PIN, GPIO_FUNC_UART);

setup_led();

led_off();

sleep_ms(5000);
Expand All @@ -73,16 +66,14 @@ int main() {
return 1;
}

radio.debug_msg_en = debug_msgs;
radio.debug_msg_en = 0;
radio.radio_init();

pico_get_unique_board_id_string(id,
2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1);

printf("\n%s %s\n", __DATE__, __TIME__);

// radio.radio_receive_single();

while (true) {
// printf("\n\n\n\n\n\n\n\n\n\n\n\n\n");

Expand All @@ -109,29 +100,39 @@ int main() {
// transmit_test(radio_ack_buf, strlen((char *)radio_ack_buf));
// }

if (transmit) {
transmit_test((uint8_t *)radio_tx_buf, sizeof(radio_tx_buf));
transmit = false;
}
// RX THING TO TRY
// rx_test();

// if (tx_done) {
// }
// RX THING TO TRY
if (gpio_get(DIO1_PIN) && !gpio_get(BUSY_PIN)) {
printf("DIO1 is high and BUSY is low!\n");
char data[6] = {
'\0', '\0', '\0', '\0', '\0', '\0',
};

while (uart_is_readable(uart1) > 0) {
char c = uart_getc(uart1);
if (c == '*') {
strcpy((char *)radio_tx_buf, gps_buf);
gps_buf_offset = 0;
}
char ack_msg[] = "_ack-__________";

if (gps_buf_offset >= 89) gps_buf_offset = 0;
radio.get_irq_status();

if (c == '$') gps_buf_offset = 0;
if (radio.irqs.RX_DONE) {
printf("got some data!\n");
radio.read_radio_buffer((uint8_t *)data, 5);

gps_buf[gps_buf_offset] = c;
gps_buf_offset++;
printf("%c", c);
printf("Got some data: %s\n", data);

strcpy(ack_msg + 4, data);

transmit_test((uint8_t *)ack_msg, sizeof(ack_msg));
}
printf("moving on!\n");
}

if (transmit) {
transmit_test((uint8_t *)radio_tx_buf, sizeof(radio_tx_buf));
transmit = false;
}

get_gps_data();
}
}

Expand All @@ -146,23 +147,17 @@ void transmit_test(uint8_t *buf, size_t len) {

radio.radio_send(buf, len);

sleep_ms(10);
while (gpio_get(BUSY_PIN))
;

sleep_ms(20);

led_off();
printf("%s\n", (char *)buf);
// radio.disable_tx();
// radio.radio_receive_single();

#if INCLUDE_DEBUG
radio.get_radio_errors();
radio.get_irq_status();
#endif

radio.clear_irq_status();

#if INCLUDE_DEBUG
radio.get_irq_status();
#endif
}

void setup_led() {
Expand All @@ -175,25 +170,52 @@ void led_on() { gpio_put(LED_PIN, true); }

void led_off() { gpio_put(LED_PIN, false); }

void gpio_callback(uint gpio, uint32_t events) {
printf("i\n");
if (gpio == DIO1_PIN) {
radio.get_irq_status();
bool tx_timer_callback(repeating_timer_t *rt) {
transmit = true;

if (radio.irqs.RX_DONE) {
rx_done = true;
}
return true; // keep repeating
}

if (radio.irqs.TX_DONE) {
tx_done = true;
}
void rx_test() {
char data[6] = {
'\0', '\0', '\0', '\0', '\0', '\0',
};

char ack_msg[] = "_ack-__________";

printf("Receive Test\n");

radio.clear_irq_status();
radio.radio_receive_single();

while (!gpio_get(DIO1_PIN) && !transmit) {
sleep_ms(1);
}

radio.clear_irq_status();

radio.read_radio_buffer((uint8_t *)data, 5);

printf("Got some data: %s\n", data);

strcpy(ack_msg + 4, data);

transmit_test((uint8_t *)ack_msg, sizeof(ack_msg));
}

bool tx_timer_callback(repeating_timer_t *rt) {
transmit = true;
void get_gps_data(void) {
while (uart_is_readable(uart1) > 0) {
char c = uart_getc(uart1);
if (c == '*') {
strcpy((char *)radio_tx_buf, gps_buf);
gps_buf_offset = 0;
}

return true; // keep repeating
if (gps_buf_offset >= 89) gps_buf_offset = 0;

if (c == '$') gps_buf_offset = 0;

gps_buf[gps_buf_offset] = c;
gps_buf_offset++;
printf("%c", c);
}
}

0 comments on commit eda0d27

Please sign in to comment.