avr/packet-radio/radio.h

64 lines
1.6 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>
#ifdef __AVR__
#else
#include <stdint.h>
#include <stdbool.h>
#endif
#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,
} radio_status_e;
typedef struct conn_s conn_t;
typedef enum {
sleep,
standby,
tx,
rx,
listen
} radio_mode_e;
void conn_set_address(conn_t *, uint8_t, radio_status_e *);
void conn_set_mode(conn_t *, radio_mode_e, 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