Skip to content

Commit c86eb5b

Browse files
Fixed an XBee configuration issue that appears to be an undocumented timing constraint in AT command mode. Inserted 100ms delay between each AT command.
1 parent 7e2bc8e commit c86eb5b

File tree

9 files changed

+35
-24
lines changed

9 files changed

+35
-24
lines changed

TA.NexDome.Rotator/TA.NexDome.Rotator.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void onMotorStopped();
2222
auto stepGenerator = CounterTimer1StepGenerator();
2323
auto settings = PersistentSettings::Load();
2424
auto stepper = MicrosteppingMotor(MOTOR_STEP_PIN, MOTOR_ENABLE_PIN, MOTOR_DIRECTION_PIN, stepGenerator, settings.motor);
25+
//std::ohserialstream xout(Serial1);
2526
auto& xbeeSerial = Serial1;
2627
auto& host = Serial;
2728
std::string hostReceiveBuffer;

TA.NexDome.Rotator/TA.NexDome.Rotator.vcxproj

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

TA.NexDome.Rotator/XBeeConfigureState.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
void XBeeConfigureState::OnTimerExpired()
77
{
8+
#ifdef DEBUG_XBEE_CONFIG
9+
std::cout << " timeout" << std::endl;
10+
#endif
811
machine.ChangeState(new XBeeStartupState(machine));
912
}
1013

@@ -24,9 +27,11 @@ bool XBeeConfigureState::sendNextAtCommand()
2427
if (ch == 0) return false;
2528
if (ch == ',')
2629
{
30+
2731
#ifdef DEBUG_XBEE_CONFIG
2832
std::cout << message;
2933
#endif
34+
delay(XbeeInterAtCommandDelay);
3035
message.push_back('\r');
3136
machine.sendToLocalXbee(message);
3237
timer.SetDuration(XBEE_AT_COMMAND_TIMEOUT);

TA.NexDome.Rotator/XBeeShutterOnlineState.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//
2-
//
3-
//
1+
//
2+
//
3+
//
44

55
#include "XBeeShutterOnlineState.h"
6-
#include "XBeeApiDetectShutterState.h"
6+
#include "XBeeStartupState.h"
77
#include "CommandProcessor.h"
88

99
void XBeeShutterOnlineState::OnEnter()
@@ -21,7 +21,7 @@ re-established and confirmed.
2121
*/
2222
void XBeeShutterOnlineState::OnTimerExpired()
2323
{
24-
machine.ChangeState(new XBeeApiDetectShutterState(machine));
24+
machine.ChangeState(new XBeeStartupState(machine));
2525
}
2626

2727

@@ -33,7 +33,6 @@ void XBeeShutterOnlineState::OnApiRx64FrameReceived(const std::vector<byte>& pay
3333
const auto msgStart = payload.begin() + 10;
3434
const auto msgEnd = payload.end();
3535
const std::string rxMessage(msgStart, msgEnd);
36-
std::cout << "rx " << rxMessage << std::endl;
3736
if (rxMessage == XBEE_HELLO_MESSAGE)
3837
{
3938
machine.SetDestinationAddress(payload);

TA.NexDome.Shutter/TA.NexDome.Shutter.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<AdditionalIncludeDirectories>$(ProjectDir)..\TA.NexDome.Shutter;$(ProjectDir)..\SharedCode;F:\OneDrive\Documents\Arduino\libraries\ArduinoSTL\src;$(ProjectDir)..\XBeeApi;$(ProjectDir)..\XBeeStatemachine;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src;$(ProjectDir)..\Timer;$(ProjectDir)..\AdvancedStepper;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.2\include;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.2\include;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
102102
<ForcedIncludeFiles>$(ProjectDir)__vm\.TA.NexDome.Shutter.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
103103
<WholeProgramOptimization>false</WholeProgramOptimization>
104-
<PreprocessorDefinitions>__AVR_atmega32u4__;__AVR_ATmega32U4__;__AVR_ATmega32u4__;DEBUG_XBEE_API;DEBUG_XBEE_CONFIG;F_CPU=16000000L;ARDUINO=108010;ARDUINO_AVR_LEONARDO;ARDUINO_ARCH_AVR;USB_VID=0x2341;USB_PID=0x8036;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
104+
<PreprocessorDefinitions>__AVR_atmega32u4__;__AVR_ATmega32U4__;__AVR_ATmega32u4__;F_CPU=16000000L;ARDUINO=108010;ARDUINO_AVR_LEONARDO;ARDUINO_ARCH_AVR;USB_VID=0x2341;USB_PID=0x8036;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
105105
</ClCompile>
106106
<Link>
107107
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -155,7 +155,7 @@
155155
</ImportGroup>
156156
<ProjectExtensions>
157157
<VisualStudio>
158-
<UserProperties config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.FreeMemory="" debug.view.AnalogPins="1" arduino.upload.port="COM10" VM_ADDITIONAL_PREPROC="DEBUG_XBEE_API;DEBUG_XBEE_CONFIG" />
158+
<UserProperties config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.FreeMemory="" debug.view.AnalogPins="1" arduino.upload.port="COM10" VM_ADDITIONAL_PREPROC="" />
159159
</VisualStudio>
160160
</ProjectExtensions>
161161
</Project>

TA.NexDome.Shutter/XBeeConfigureState.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bool XBeeConfigureState::sendNextAtCommand()
3131
#ifdef DEBUG_XBEE_CONFIG
3232
std::cout << message;
3333
#endif
34+
delay(XbeeInterAtCommandDelay);
3435
message.push_back('\r');
3536
machine.sendToLocalXbee(message);
3637
timer.SetDuration(XBEE_AT_COMMAND_TIMEOUT);

TA.NexDome.Shutter/XBeeOnlineState.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ void XBeeOnlineState::OnApiRx64FrameReceived(const std::vector<byte>& payload)
4646
const auto msgStart = payload.begin() + 10;
4747
const auto msgEnd = payload.end();
4848
const std::string rxMessage(msgStart, msgEnd);
49+
#ifdef DEBUG_XBEE_API
4950
std::cout << "Rx64 " << rxMessage << std::endl;
51+
#endif
5052
// payload[10] is the first byte of the received data
5153
if (length > 10 && payload[10] == '@')
5254
{

Timer/Timer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#endif
1616

1717
/*
18-
A simple timer that works correctly with Arduino's millis() function and
18+
A simple timer that works correctly with Arduino's millis() function and
1919
unsigned arithmetic, provided the timed interval is short compared to the
2020
maximum value of millis(), which is about 49 days.
21-
21+
2222
On an Arduino, millis() returns a 32-bit unsigned
2323
integer, with maximum value of 4,294,967,295 (2^32 - 1). This represents
2424
a duration of about 49 days, after which the value of millis() will wrap
@@ -61,8 +61,11 @@ class Timer
6161
Duration Remaining() const;
6262
bool Enabled() const;
6363
void Stop();
64+
static constexpr Duration Milliseconds(unsigned long millis) { return Duration(millis); }
65+
static constexpr Duration Milliseconds(unsigned millis) { return Duration(millis); }
66+
static constexpr Duration Milliseconds(int millis) { return Duration(unsigned(millis)); }
6467
static constexpr Duration Seconds(float seconds) { return Duration(1000 * seconds); }
65-
static constexpr Duration Minutes(float minutes) { return Duration(Seconds(60) * minutes); }
68+
static constexpr Duration Minutes(float minutes) { return Duration(Seconds(60 * minutes)); }
6669
private:
6770
Duration startedAt;
6871
Duration interval;

XBeeStateMachine/XBeeStatemachine.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
#include <XBeeApi.h>
88
#include <Timer.h>
99

10-
11-
#define XBEE_AT_GUARD_TIME (1200UL) // Wait time before sending AT attention string and receiving "OK"
12-
#define XBEE_AT_COMMAND_TIMEOUT (5000UL) // Time to wait for "OK" response to AT command before giving up
13-
#define XBEE_REMOTE_HANDSHAKE_TIMEOUT (3000UL) // Maximum time to wait for rotator to acknowledge the hello message.
14-
#define XBEE_ASSOCIATE_TIMEOUT (20000UL) // Maximum time to wait for shutter to associate with a coordinator.
15-
#define XBEE_DETECT_SHUTTER_TIMEOUT (60000UL) // Maximum time to wait for the shutter to say hello.
16-
#define XBEE_HEARTBEAT_INTERVAL (8000UL) // How often the shutter sends a 'heartbeat' message
17-
#define XBEE_NO_HEARTBEAT_TIMEOUT ( 17000UL) // How long to wait for a heartbeat before assuming the link is down
18-
#define XBEE_HELLO_MESSAGE "Yoohoo" // A retro shout-out to FidoNet era mailer called dBridge.
19-
#define XBEE_HELLO_ACK "2U2" // (yes I am old enough to remember FidoNet).
20-
#define XBEE_ATTENTION "+++" // Guard Time + Attention + Guard Time reverts XBee to AT Command Mode
10+
constexpr Duration XBEE_AT_GUARD_TIME = Timer::Milliseconds(1200); // Wait time before sending AT attention string and receiving "OK"
11+
constexpr Duration XBEE_AT_COMMAND_TIMEOUT = Timer::Seconds(5); // Time to wait for "OK" response to AT command before giving up
12+
constexpr Duration XbeeInterAtCommandDelay = Timer::Milliseconds(100);
13+
constexpr Duration XBEE_REMOTE_HANDSHAKE_TIMEOUT = Timer::Seconds(3); // Maximum time to wait for rotator to acknowledge the hello message.
14+
constexpr Duration XBEE_ASSOCIATE_TIMEOUT = Timer::Seconds(20); // Maximum time to wait for shutter to associate with a coordinator.
15+
constexpr Duration XBEE_DETECT_SHUTTER_TIMEOUT = Timer::Seconds(60); // Maximum time to wait for the shutter to say hello.
16+
constexpr Duration XBEE_HEARTBEAT_INTERVAL = Timer::Seconds(8); // How often the shutter sends a 'heartbeat' message
17+
constexpr Duration XBEE_NO_HEARTBEAT_TIMEOUT = Timer::Seconds(17); // How long to wait for a heartbeat before assuming the link is down
18+
#define XBEE_HELLO_MESSAGE "Yoohoo" // A retro shout-out to FidoNet era mailer called dBridge.
19+
#define XBEE_HELLO_ACK "2U2" // (yes I am old enough to remember FidoNet).
20+
#define XBEE_ATTENTION "+++" // Guard Time + Attention + Guard Time reverts XBee to AT Command Mode
2121

2222
class IXBeeState;
2323

0 commit comments

Comments
 (0)