76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
/*
|
|
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
|
|
|
This file is part of Savanni's AVR library.
|
|
|
|
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef __RADIO_H__
|
|
#define __RADIO_H__
|
|
|
|
#include <stddef.h>
|
|
#include "packet.h"
|
|
|
|
#define MAX_MESSAGE_LENGTH 60
|
|
#define IS_OK(val) (val == NULL || !*val)
|
|
|
|
typedef struct {
|
|
size_t length;
|
|
char data[0];
|
|
} msg_t;
|
|
|
|
typedef struct {
|
|
uint16_t sender;
|
|
msg_t message;
|
|
} received_msg_t;
|
|
|
|
typedef enum {
|
|
ok,
|
|
not_found,
|
|
message_too_long,
|
|
outgoing_full,
|
|
unhandled_error,
|
|
} radio_status_e;
|
|
|
|
typedef struct conn_s conn_t;
|
|
|
|
typedef enum {
|
|
sleep,
|
|
standby,
|
|
tx,
|
|
rx,
|
|
listen
|
|
} radio_mode_e;
|
|
|
|
typedef struct {
|
|
bool packet_sent;
|
|
bool packet_ready;
|
|
} flags_t;
|
|
|
|
typedef struct radio_s radio_t;
|
|
|
|
struct radio_s {
|
|
void (*set_mode)(radio_t *, radio_mode_e, radio_status_e *);
|
|
flags_t (*get_flags)(radio_t *, radio_status_e *);
|
|
void (*transmit)(radio_t *, packet_t *, radio_status_e *);
|
|
void (*receive)(radio_t *, uint8_t data[66], radio_status_e *);
|
|
};
|
|
|
|
conn_t * conn_connect(radio_t *radio);
|
|
|
|
void conn_set_address(conn_t *, uint8_t, radio_status_e *);
|
|
void conn_set_mode(conn_t *, radio_mode_e, radio_status_e *);
|
|
flags_t conn_get_flags(conn_t *, radio_status_e *);
|
|
|
|
void conn_send(conn_t *, uint8_t, msg_t *, radio_status_e *);
|
|
received_msg_t * conn_receive(conn_t *, radio_status_e *);
|
|
|
|
// void radio_broadcast(conn_t *, uint16_t, msg_t *, radio_status_e *);
|
|
|
|
#endif
|