Skip to content

Commit

Permalink
Fixed a bug that caused incorrect step positions to be used
Browse files Browse the repository at this point in the history
Attempted to free up some memory
  • Loading branch information
NameOfTheDragon committed Jan 7, 2021
1 parent 8c1dc59 commit eaf683a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion SharedCode/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ inline Command::Command(const std::string &buffer)
if (bufferLength > 5 && buffer[4] == ',')
{
const auto position = buffer.substr(5);
const auto wholeSteps = std::strtoul(position.begin(), nullptr, 10);
const auto positionString = position.c_str();
const auto wholeSteps = std::strtoul(positionString, nullptr, 10);
StepPosition = (int32_t)wholeSteps;
}
}
Expand Down
2 changes: 1 addition & 1 deletion TA.NexDome.Rotator/CommandProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void CommandProcessor::responseToHost(const std::string& rxMessage)

void CommandProcessor::HandleZZ(const Command& command) const
{
void(*resetFunc) (void) = 0; //declare reset function at address 0
void(*resetFunc) (void) = nullptr; //declare reset function at address 0
resetFunc(); //call reset
}

Expand Down
4 changes: 3 additions & 1 deletion TA.NexDome.Rotator/TA.NexDome.Rotator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ihserialstream cin(host);

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

Expand All @@ -73,14 +74,15 @@ void HandleSerialCommunications()
{
const auto command = Command(hostReceiveBuffer);
DispatchCommand(command);
hostReceiveBuffer.clear();
if (ResponseBuilder::available())
std::cout
<< ResponseBuilder::header
<< ResponseBuilder::Message
<< ResponseBuilder::terminator
<< std::endl; // send response, if there is one.
}
// fall through to clear the host buffer
break;
case '@': // Start of new command
hostReceiveBuffer.clear();
default:
Expand Down
4 changes: 3 additions & 1 deletion TA.NexDome.Rotator/XBeeApiDetectShutterState.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class XBeeApiDetectShutterState : public IXBeeState
{
public:
explicit XBeeApiDetectShutterState(XBeeStateMachine& machine) : IXBeeState(machine) {}
std::string name() override { return "Detect"; }
std::string name() override { return stateName; }
void OnEnter() override;
void OnTimerExpired() override;
void OnApiRx64FrameReceived(const std::vector<byte>& payload) override;
private:
const char* stateName __ATTR_PROGMEM__ = "Detect";
};

#endif
Expand Down
3 changes: 2 additions & 1 deletion TA.NexDome.Rotator/XBeeConfigureState.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class XBeeConfigureState : public IXBeeState
{
public:
explicit XBeeConfigureState(XBeeStateMachine& machine) : IXBeeState(machine) { index = 0; };
std::string name() override { return "Config"; };
std::string name() override { return stateName; };
void OnTimerExpired() override;
void OnEnter() override;
void OnSerialLineReceived(const std::string& message) override;
Expand All @@ -24,6 +24,7 @@ class XBeeConfigureState : public IXBeeState
bool sendNextAtCommand();
unsigned short index;
const char* initSequence __ATTR_PROGMEM__ = "RE,WR,AC,MYFFFE,ID6FBF,CH0B,A17,A27,RR6,RN2,CA30,PL4,SM0,CE1,AP2,WR,FR,";
const char* stateName __ATTR_PROGMEM__ = "Config";
};

#endif
Expand Down
4 changes: 3 additions & 1 deletion TA.NexDome.Rotator/XBeeShutterOnlineState.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class XBeeShutterOnlineState : public IXBeeState
protected:
void OnTimerExpired() override;
public:
std::string name() override { return "Online"; };
std::string name() override { return stateName; };
explicit XBeeShutterOnlineState(XBeeStateMachine& machine) : IXBeeState(machine) {}
void OnEnter() override;
void OnApiRx64FrameReceived(const std::vector<byte>& payload) override;
void SendCommand(std::string& command) override;
private:
const char* stateName __ATTR_PROGMEM__ = "Online";
};


Expand Down
4 changes: 3 additions & 1 deletion TA.NexDome.Rotator/XBeeStartupState.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ constexpr Duration XbeeBootTime = Timer::Seconds(2);
class XBeeStartupState : public IXBeeState
{
public:
std::string name() override { return "Start"; }
std::string name() override { return stateName; }
void OnEnter() override;
void OnTimerExpired() override;
explicit XBeeStartupState(XBeeStateMachine& machine) : IXBeeState(machine) {}
private:
const char* stateName __ATTR_PROGMEM__ = "Start";
};

#endif
Expand Down
4 changes: 3 additions & 1 deletion TA.NexDome.Rotator/XBeeWaitForCommandModeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class XBeeWaitForCommandModeState : public IXBeeState
{
public:
explicit XBeeWaitForCommandModeState(XBeeStateMachine& machine):IXBeeState(machine){};
std::string name() override { return "WaitAT"; }
std::string name() override { return stateName; }
void OnTimerExpired() override;
void OnEnter() override;
void OnSerialLineReceived(const std::string& rxData) override;
private:
const char* stateName __ATTR_PROGMEM__ = "WaitAT";
};

0 comments on commit eaf683a

Please sign in to comment.