summaryrefslogtreecommitdiff
path: root/LoRaHandler/LoRaHandler.h
blob: 375c2776f9462c00e93f191e68d8f9c25c8f9b8d (plain)
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
#ifndef __LORAHANDLER_H__
#define __LORAHANDLER_H__

#include "mDot.h"

#define loraSignal (int32_t)0x02

class LoRaHandler {
    public:
        typedef enum {
            none = 0,
            busy,
            ping_success,
            send_success,
            join_success,
            ping_failure,
            send_failure,
            join_failure
        } LoRaStatus;

        typedef struct {
            bool status;
            mDot::ping_response up;
            mDot::ping_response down;
        } LoRaPing;

        typedef enum {
            green = 0,
            red
        } LedColor;

        LoRaHandler(osThreadId main);
        ~LoRaHandler();

        bool ping();
        bool send(std::vector<uint8_t> data);
        bool join();
        bool action(uint8_t cmd);
        LoRaStatus getStatus();
        LoRaPing getPingResults();
        uint32_t getJoinAttempts();
        void resetJoinAttempts();
        void blinker();
        void resetActivityLed();

        osThreadId _main;
        Thread _thread;
        LoRaStatus _status;
        LoRaPing _ping;
        mDot* _dot;
        Mutex _mutex;
        uint32_t _join_attempts;
        DigitalInOut _activity_led;
        Ticker _tick;
};

#endif