Include packet length with the data

This commit is contained in:
Savanni D'Gerinel 2022-07-02 21:55:08 -04:00
parent 4843c547fe
commit ff6a5b3d70
3 changed files with 9 additions and 10 deletions

View File

@ -43,7 +43,6 @@ int main(void) {
int clock = 0; int clock = 0;
uint8_t primes[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 0 }; uint8_t primes[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 0 };
/*
display_t display = { display_t display = {
.reg = { .reg = {
.output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 }, .output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
@ -51,7 +50,6 @@ int main(void) {
.latch_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 }, .latch_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
}, },
}; };
*/
rfm_t radio = (rfm_t){ rfm_t radio = (rfm_t){
.spi = { .spi = {
@ -64,23 +62,23 @@ int main(void) {
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 }, .reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
}; };
// _delay_ms(15); _delay_ms(15);
// display_init(&display); display_init(&display);
rfm_error_e error; rfm_error_e error;
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error); rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
// status(&display, &radio, clock); status(&display, &radio, clock);
int next_transmit = 0; int next_transmit = 0;
int prime = 0; int prime = 0;
while (1) { while (1) {
if (clock >= next_transmit) { if (clock >= next_transmit) {
// display_clear(&display); display_clear(&display);
char msg[16]; char msg[16];
sprintf(msg, "sending %d", primes[prime]); sprintf(msg, "sending %d", primes[prime]);
// display_write_message(&display, msg); display_write_message(&display, msg);
rfm_transmit(&radio, &primes[prime], 1); rfm_transmit(&radio, &primes[prime], 1);
if (primes[prime] == 0) { if (primes[prime] == 0) {
prime = 0; prime = 0;
@ -90,7 +88,7 @@ int main(void) {
next_transmit = clock + 10; next_transmit = clock + 10;
_delay_ms(1000); _delay_ms(1000);
} }
// status(&display, &radio, clock); status(&display, &radio, clock);
interrupt_flags_t flags = rfm_interrupts(&radio); interrupt_flags_t flags = rfm_interrupts(&radio);
if (flags.packet_sent) { if (flags.packet_sent) {

View File

@ -122,8 +122,9 @@ void rfm_standby(rfm_t *rfm) {
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = standby }); rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = standby });
} }
void rfm_transmit(rfm_t *rfm, uint8_t *data, size_t length) { void rfm_transmit(rfm_t *rfm, uint8_t *data, uint8_t length) {
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = standby }); rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = standby });
_rfm_write(rfm, REG_FIFO, &length, 1);
_rfm_write(rfm, REG_FIFO, data, length); _rfm_write(rfm, REG_FIFO, data, length);
_rfm_write(rfm, REG_DIO_MAPPING1, (uint8_t [1]){ 0x00 }, 1); _rfm_write(rfm, REG_DIO_MAPPING1, (uint8_t [1]){ 0x00 }, 1);
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = tx }); rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = tx });

View File

@ -75,7 +75,7 @@ void rfm_packet_format(rfm_t *rfm, packet_format_e format, size_t length);
void rfm_sleep(rfm_t *); void rfm_sleep(rfm_t *);
void rfm_standby(rfm_t *); void rfm_standby(rfm_t *);
void rfm_receive_mode(rfm_t *); void rfm_receive_mode(rfm_t *);
void rfm_transmit(rfm_t *rfm, uint8_t *data, size_t length); void rfm_transmit(rfm_t *rfm, uint8_t *data, uint8_t length);
void rfm_receive(rfm_t *rfm, uint8_t *data, size_t length); void rfm_receive(rfm_t *rfm, uint8_t *data, size_t length);
op_mode_t rfm_mode(rfm_t *rfm); op_mode_t rfm_mode(rfm_t *rfm);