Skip to content

Commit eaf683a

Browse files
Fixed a bug that caused incorrect step positions to be used
Attempted to free up some memory
1 parent 8c1dc59 commit eaf683a

File tree

8 files changed

+20
-8
lines changed

8 files changed

+20
-8
lines changed

SharedCode/Command.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ inline Command::Command(const std::string &buffer)
4040
if (bufferLength > 5 && buffer[4] == ',')
4141
{
4242
const auto position = buffer.substr(5);
43-
const auto wholeSteps = std::strtoul(position.begin(), nullptr, 10);
43+
const auto positionString = position.c_str();
44+
const auto wholeSteps = std::strtoul(positionString, nullptr, 10);
4445
StepPosition = (int32_t)wholeSteps;
4546
}
4647
}

TA.NexDome.Rotator/CommandProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void CommandProcessor::responseToHost(const std::string& rxMessage)
2525

2626
void CommandProcessor::HandleZZ(const Command& command) const
2727
{
28-
void(*resetFunc) (void) = 0; //declare reset function at address 0
28+
void(*resetFunc) (void) = nullptr; //declare reset function at address 0
2929
resetFunc(); //call reset
3030
}
3131

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ihserialstream cin(host);
4747

4848
void DispatchCommand(const Command& command)
4949
{
50+
//std::cout << command.RawCommand << "V=" << command.Verb << ", T=" << command.TargetDevice << ", P=" << command.StepPosition << std::endl;
5051
commandProcessor.HandleCommand(command);
5152
}
5253

@@ -73,14 +74,15 @@ void HandleSerialCommunications()
7374
{
7475
const auto command = Command(hostReceiveBuffer);
7576
DispatchCommand(command);
77+
hostReceiveBuffer.clear();
7678
if (ResponseBuilder::available())
7779
std::cout
7880
<< ResponseBuilder::header
7981
<< ResponseBuilder::Message
8082
<< ResponseBuilder::terminator
8183
<< std::endl; // send response, if there is one.
8284
}
83-
// fall through to clear the host buffer
85+
break;
8486
case '@': // Start of new command
8587
hostReceiveBuffer.clear();
8688
default:

TA.NexDome.Rotator/XBeeApiDetectShutterState.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class XBeeApiDetectShutterState : public IXBeeState
1515
{
1616
public:
1717
explicit XBeeApiDetectShutterState(XBeeStateMachine& machine) : IXBeeState(machine) {}
18-
std::string name() override { return "Detect"; }
18+
std::string name() override { return stateName; }
1919
void OnEnter() override;
2020
void OnTimerExpired() override;
2121
void OnApiRx64FrameReceived(const std::vector<byte>& payload) override;
22+
private:
23+
const char* stateName __ATTR_PROGMEM__ = "Detect";
2224
};
2325

2426
#endif

TA.NexDome.Rotator/XBeeConfigureState.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class XBeeConfigureState : public IXBeeState
1515
{
1616
public:
1717
explicit XBeeConfigureState(XBeeStateMachine& machine) : IXBeeState(machine) { index = 0; };
18-
std::string name() override { return "Config"; };
18+
std::string name() override { return stateName; };
1919
void OnTimerExpired() override;
2020
void OnEnter() override;
2121
void OnSerialLineReceived(const std::string& message) override;
@@ -24,6 +24,7 @@ class XBeeConfigureState : public IXBeeState
2424
bool sendNextAtCommand();
2525
unsigned short index;
2626
const char* initSequence __ATTR_PROGMEM__ = "RE,WR,AC,MYFFFE,ID6FBF,CH0B,A17,A27,RR6,RN2,CA30,PL4,SM0,CE1,AP2,WR,FR,";
27+
const char* stateName __ATTR_PROGMEM__ = "Config";
2728
};
2829

2930
#endif

TA.NexDome.Rotator/XBeeShutterOnlineState.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ class XBeeShutterOnlineState : public IXBeeState
1616
protected:
1717
void OnTimerExpired() override;
1818
public:
19-
std::string name() override { return "Online"; };
19+
std::string name() override { return stateName; };
2020
explicit XBeeShutterOnlineState(XBeeStateMachine& machine) : IXBeeState(machine) {}
2121
void OnEnter() override;
2222
void OnApiRx64FrameReceived(const std::vector<byte>& payload) override;
2323
void SendCommand(std::string& command) override;
24+
private:
25+
const char* stateName __ATTR_PROGMEM__ = "Online";
2426
};
2527

2628

TA.NexDome.Rotator/XBeeStartupState.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ constexpr Duration XbeeBootTime = Timer::Seconds(2);
1616
class XBeeStartupState : public IXBeeState
1717
{
1818
public:
19-
std::string name() override { return "Start"; }
19+
std::string name() override { return stateName; }
2020
void OnEnter() override;
2121
void OnTimerExpired() override;
2222
explicit XBeeStartupState(XBeeStateMachine& machine) : IXBeeState(machine) {}
23+
private:
24+
const char* stateName __ATTR_PROGMEM__ = "Start";
2325
};
2426

2527
#endif

TA.NexDome.Rotator/XBeeWaitForCommandModeState.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class XBeeWaitForCommandModeState : public IXBeeState
1111
{
1212
public:
1313
explicit XBeeWaitForCommandModeState(XBeeStateMachine& machine):IXBeeState(machine){};
14-
std::string name() override { return "WaitAT"; }
14+
std::string name() override { return stateName; }
1515
void OnTimerExpired() override;
1616
void OnEnter() override;
1717
void OnSerialLineReceived(const std::string& rxData) override;
18+
private:
19+
const char* stateName __ATTR_PROGMEM__ = "WaitAT";
1820
};

0 commit comments

Comments
 (0)