Skyward boardcore
Loading...
Searching...
No Matches
Gamma868.h
Go to the documentation of this file.
1/* Copyright (c) 2015-2018 Skyward Experimental Rocketry
2 * Authors: Alvise de'Faveri Tron, Nuno Barcellos
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
26#include <fcntl.h>
27#include <radio/Transceiver.h>
28
29#include "GammaTypes.h"
30
31namespace Boardcore
32{
33
34class Gamma868 : public Transceiver
35{
36public:
37 const int LEARN_MODE_TIMEOUT = 5000;
38 /*
39 * Create a Gamma868 object using the given path as the serial port to use.
40 * @param serialPath Name of the serial port (es. /dev/tty)
41 * @param multiplier If defined, after each send the send function
42 * will block for multiplier*nBytesSent
43 * milliseconds.
44 */
45 explicit Gamma868(const char* serialPath, const uint16_t multiplier = 0);
46
47 /*
48 * Create a Gamma868 that can be configured through the LRN pin.
49 * @param serialPath Name of the serial port (es. /dev/tty)
50 * @param learnModePin pin connected to the Learn Mode pin of the
51 * Gamma
52 * @param multiplier If defined, after each send the send() function
53 * will block for multiplier*nBytesSent
54 * milliseconds.
55 */
56 Gamma868(const char* serialPath, miosix::GpioPin* learnModePin,
57 const uint16_t multiplier = 0);
58
59 ~Gamma868();
60
61 /*
62 * Send a message through the serial port to the gamma868 module (blocking).
63 * @param pkt Pointer to the packet (needs to be at least
64 * packetLength bytes).
65 * @param packetLength Lenght of the packet to be sent.
66 * @return True if the message was sent correctly.
67 */
68 bool send(uint8_t* pkt, size_t packetLength) override;
69
70 /*
71 * Receive a message through the serial port to the gamma868 module
72 * (blocking).
73 * @param pkt Pointer to the buffer (needs to be at least
74 * packetLength bytes).
75 * @param packetLength Maximum lenght of the packet to be
76 * received.
77 * @return Size of the data received or -1 if failure
78 */
79 ssize_t receive(uint8_t* pkt, size_t packetLength) override;
80
81 /*
82 * Set a new configuration to the gamma868 module. Can be done only if the
83 * learn pin has been specified in the constructor.
84 * @return True if the configuration was set correctly.
85 */
86 bool configure(const GammaConf& newConf);
87
88 /*
89 * Reads the configuration from the device, updates the internal
90 * configuration variable and returns it. Meaningful only if the learn pin
91 * has been specified in the constructor.
92 * @return The current configuration.
93 */
95
96 /*
97 * Immediately returns the value of the configuration variable, without
98 * reading it from the device.
99 * @return The current configuration.
100 * @warning check the isValid bit to see if the returned configuration
101 * is meaningful.
102 */
103 GammaConf getConfig() { return conf; }
104
105private:
106 int fd;
107 const uint16_t sendTimeoutMultiplier;
108
109 GammaConf conf;
110 bool confEnabled;
111 miosix::GpioPin* gammaSwitch;
112
113 void enterLearnMode();
114 void exitLearnMode();
115
116 void writeConfig(const GammaConf& conf);
117 bool updateConfig();
118 void waitForOk();
119
120 PrintLogger logger = Logging::getLogger("gamma868");
121};
122
123} // namespace Boardcore
GammaConf getConfig()
Definition Gamma868.h:103
Gamma868(const char *serialPath, const uint16_t multiplier=0)
Definition Gamma868.cpp:35
const int LEARN_MODE_TIMEOUT
Definition Gamma868.h:37
bool configure(const GammaConf &newConf)
Definition Gamma868.cpp:112
bool send(uint8_t *pkt, size_t packetLength) override
Send a packet.
Definition Gamma868.cpp:67
Gamma868(const char *serialPath, miosix::GpioPin *learnModePin, const uint16_t multiplier=0)
GammaConf readConfig()
Definition Gamma868.cpp:88
ssize_t receive(uint8_t *pkt, size_t packetLength) override
Wait until a new packet is received.
Definition Gamma868.cpp:77
static PrintLogger getLogger(const string &name)
This file includes all the types the logdecoder script will decode.