Skip to content

Commit

Permalink
Fixed an XBee configuration issue that appears to be an undocumented …
Browse files Browse the repository at this point in the history
…timing constraint in AT command mode. Inserted 100ms delay between each AT command.
  • Loading branch information
NameOfTheDragon committed Nov 28, 2019
1 parent 7e2bc8e commit c86eb5b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 24 deletions.
1 change: 1 addition & 0 deletions TA.NexDome.Rotator/TA.NexDome.Rotator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void onMotorStopped();
auto stepGenerator = CounterTimer1StepGenerator();
auto settings = PersistentSettings::Load();
auto stepper = MicrosteppingMotor(MOTOR_STEP_PIN, MOTOR_ENABLE_PIN, MOTOR_DIRECTION_PIN, stepGenerator, settings.motor);
//std::ohserialstream xout(Serial1);
auto& xbeeSerial = Serial1;
auto& host = Serial;
std::string hostReceiveBuffer;
Expand Down
4 changes: 2 additions & 2 deletions TA.NexDome.Rotator/TA.NexDome.Rotator.vcxproj

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions TA.NexDome.Rotator/XBeeConfigureState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

void XBeeConfigureState::OnTimerExpired()
{
#ifdef DEBUG_XBEE_CONFIG
std::cout << " timeout" << std::endl;
#endif
machine.ChangeState(new XBeeStartupState(machine));
}

Expand All @@ -24,9 +27,11 @@ bool XBeeConfigureState::sendNextAtCommand()
if (ch == 0) return false;
if (ch == ',')
{

#ifdef DEBUG_XBEE_CONFIG
std::cout << message;
#endif
delay(XbeeInterAtCommandDelay);
message.push_back('\r');
machine.sendToLocalXbee(message);
timer.SetDuration(XBEE_AT_COMMAND_TIMEOUT);
Expand Down
11 changes: 5 additions & 6 deletions TA.NexDome.Rotator/XBeeShutterOnlineState.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
//
//
//
//
//

#include "XBeeShutterOnlineState.h"
#include "XBeeApiDetectShutterState.h"
#include "XBeeStartupState.h"
#include "CommandProcessor.h"

void XBeeShutterOnlineState::OnEnter()
Expand All @@ -21,7 +21,7 @@ re-established and confirmed.
*/
void XBeeShutterOnlineState::OnTimerExpired()
{
machine.ChangeState(new XBeeApiDetectShutterState(machine));
machine.ChangeState(new XBeeStartupState(machine));
}


Expand All @@ -33,7 +33,6 @@ void XBeeShutterOnlineState::OnApiRx64FrameReceived(const std::vector<byte>& pay
const auto msgStart = payload.begin() + 10;
const auto msgEnd = payload.end();
const std::string rxMessage(msgStart, msgEnd);
std::cout << "rx " << rxMessage << std::endl;
if (rxMessage == XBEE_HELLO_MESSAGE)
{
machine.SetDestinationAddress(payload);
Expand Down
4 changes: 2 additions & 2 deletions TA.NexDome.Shutter/TA.NexDome.Shutter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<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>
<ForcedIncludeFiles>$(ProjectDir)__vm\.TA.NexDome.Shutter.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<WholeProgramOptimization>false</WholeProgramOptimization>
<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>
<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>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down Expand Up @@ -155,7 +155,7 @@
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<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" />
<UserProperties config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.FreeMemory="" debug.view.AnalogPins="1" arduino.upload.port="COM10" VM_ADDITIONAL_PREPROC="" />
</VisualStudio>
</ProjectExtensions>
</Project>
1 change: 1 addition & 0 deletions TA.NexDome.Shutter/XBeeConfigureState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bool XBeeConfigureState::sendNextAtCommand()
#ifdef DEBUG_XBEE_CONFIG
std::cout << message;
#endif
delay(XbeeInterAtCommandDelay);
message.push_back('\r');
machine.sendToLocalXbee(message);
timer.SetDuration(XBEE_AT_COMMAND_TIMEOUT);
Expand Down
2 changes: 2 additions & 0 deletions TA.NexDome.Shutter/XBeeOnlineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ void XBeeOnlineState::OnApiRx64FrameReceived(const std::vector<byte>& payload)
const auto msgStart = payload.begin() + 10;
const auto msgEnd = payload.end();
const std::string rxMessage(msgStart, msgEnd);
#ifdef DEBUG_XBEE_API
std::cout << "Rx64 " << rxMessage << std::endl;
#endif
// payload[10] is the first byte of the received data
if (length > 10 && payload[10] == '@')
{
Expand Down
9 changes: 6 additions & 3 deletions Timer/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#endif

/*
A simple timer that works correctly with Arduino's millis() function and
A simple timer that works correctly with Arduino's millis() function and
unsigned arithmetic, provided the timed interval is short compared to the
maximum value of millis(), which is about 49 days.
On an Arduino, millis() returns a 32-bit unsigned
integer, with maximum value of 4,294,967,295 (2^32 - 1). This represents
a duration of about 49 days, after which the value of millis() will wrap
Expand Down Expand Up @@ -61,8 +61,11 @@ class Timer
Duration Remaining() const;
bool Enabled() const;
void Stop();
static constexpr Duration Milliseconds(unsigned long millis) { return Duration(millis); }
static constexpr Duration Milliseconds(unsigned millis) { return Duration(millis); }
static constexpr Duration Milliseconds(int millis) { return Duration(unsigned(millis)); }
static constexpr Duration Seconds(float seconds) { return Duration(1000 * seconds); }
static constexpr Duration Minutes(float minutes) { return Duration(Seconds(60) * minutes); }
static constexpr Duration Minutes(float minutes) { return Duration(Seconds(60 * minutes)); }
private:
Duration startedAt;
Duration interval;
Expand Down
22 changes: 11 additions & 11 deletions XBeeStateMachine/XBeeStatemachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
#include <XBeeApi.h>
#include <Timer.h>


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

class IXBeeState;

Expand Down

0 comments on commit c86eb5b

Please sign in to comment.