Skyward boardcore
Loading...
Searching...
No Matches
ATCommands.h
Go to the documentation of this file.
1/* Copyright (c) 2021 Skyward Experimental Rocketry
2 * Author: Luca Erbetta
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
25#include "APIFrames.h"
26#include "Xbee.h"
27
28namespace Boardcore
29{
30
31namespace Xbee
32{
33
43inline bool setChannelMask(Xbee& xbee, uint32_t mask,
44 unsigned int timeout = 1000)
45{
47
48 mask = swapBytes32(mask);
49
50 return xbee.sendATCommand("CM", &response,
51 reinterpret_cast<uint8_t*>(&mask), 4, timeout);
52}
53
64inline bool setChannelMask(Xbee& xbee, bool channels[30],
65 unsigned int timeout = 1000)
66{
67 uint32_t val = 0;
68
69 for (int i = 0; i < 30; i++)
70 val &= ((uint32_t)channels[i]) << i;
71
72 return setChannelMask(xbee, val, timeout);
73}
74
82inline bool enableAllChannels(Xbee& xbee, unsigned int timeout = 1000)
83{
84 return setChannelMask(xbee, 0x3EFFFDFF, timeout);
85}
86
93inline bool disableFrequencyHopping(Xbee& xbee, unsigned int timeout = 1000)
94{
95 return setChannelMask(xbee, 0x20000000, timeout);
96}
97
105inline bool setDataRate(Xbee& xbee, bool dataRate80kbps,
106 unsigned int timeout = 1000)
107{
108 uint8_t param = (uint8_t)dataRate80kbps;
109 ATCommandResponseFrame response;
110
111 return xbee.sendATCommand("BR", &response, &param, 1, timeout);
112}
113
121inline bool writeToMemory(Xbee& xbee, unsigned int timeout = 1000)
122{
123 ATCommandResponseFrame response;
124 return xbee.sendATCommand("WR", &response, nullptr, 0, timeout);
125}
126
137inline bool energyDetect(Xbee& xbee, int* energyDetectData, uint8_t duration,
138 unsigned int timeout = 1000)
139{
140 ATCommandResponseFrame response;
141 if (xbee.sendATCommand("ED", &response, &duration, 1, timeout))
142 {
143 uint16_t respLen = response.getCommandDataLength();
144 if (respLen == 30)
145 {
146 for (int i = 0; i < 30; i++)
147 {
148 energyDetectData[i] =
149 (int)(*(response.getCommandDataPointer() + i));
150 }
151
152 return true;
153 }
154 }
155 return false;
156}
157
158} // namespace Xbee
159
160} // namespace Boardcore
bool enableAllChannels(Xbee &xbee, unsigned int timeout=1000)
Enable communication on all available channels. Equivalent to calling setChannelMask(xbee,...
Definition ATCommands.h:82
bool writeToMemory(Xbee &xbee, unsigned int timeout=1000)
Writes parameter values to non-volatile memory so that parameter modifications persist through subseq...
Definition ATCommands.h:121
bool disableFrequencyHopping(Xbee &xbee, unsigned int timeout=1000)
Disables frequency hopping by allowing communication only on channel #29. Equivalent to calling setCh...
Definition ATCommands.h:93
bool setDataRate(Xbee &xbee, bool dataRate80kbps, unsigned int timeout=1000)
Configures the desired xbee data rate.
Definition ATCommands.h:105
bool energyDetect(Xbee &xbee, int *energyDetectData, uint8_t duration, unsigned int timeout=1000)
Performs an energy detect scan on all channels.
Definition ATCommands.h:137
bool setChannelMask(Xbee &xbee, uint32_t mask, unsigned int timeout=1000)
Enables or disable the specified channels. Channel 9 and 24 are always disabled due to regulatory lim...
Definition ATCommands.h:43
Driver for the VN100S IMU.