-
Notifications
You must be signed in to change notification settings - Fork 0
/
mt-lite.h
executable file
·73 lines (63 loc) · 1.35 KB
/
mt-lite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __MT_LITE_H__
#define __MT_LITE_H__
#include <Arduino.h>
#include <LoRa.h>
#include "picopb.h"
typedef enum
{
TEXT_MESSAGE = 1,
} mt_packet_type;
struct _mt_packet
{
uint32_t dest;
uint32_t src;
uint32_t sequence;
uint8_t flags;
uint8_t channel;
uint16_t reserved;
uint8_t payload[256];
};
typedef struct _mt_packet mt_packet;
struct _text_message
{
uint64_t mt_packet_type;
uint8_t text_message[256];
};
typedef struct _text_message text_message;
struct _user
{
uint8_t id[32];
uint8_t longname[32];
uint8_t shortname[4];
};
typedef struct _user user;
class mt_lite
{
public:
mt_lite();
void init(uint32_t id);
void update();
void set_aeskey(uint8_t *key,int len);
void encrypt(mt_packet *packet,int len);
size_t packet_available();
void read_packet(uint8_t *rxdata);
void write_packet(uint8_t *txdata,size_t size);
uint8_t random();
private:
void send_packet(mt_packet *mtp,int len);
void ack_packet(mt_packet *mtp,int len);
void fetch_packet(mt_packet *mtp,int size);
bool seen_seq(uint32_t seq);
void handle_rx();
void handle_tx();
uint32_t id;
uint32_t sequence;
//LoRaClass &lora;
uint32_t seen_sequence[16];
uint8_t last_seen;
mt_packet rxpacket;
size_t rxsize;
mt_packet txpacket;
size_t txsize;
};
#endif //__MT_LITE_H__