Skip to content

Commit

Permalink
Merge branch 'api-v3-fix' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
AJIOB committed Sep 4, 2017
2 parents c1343c5 + 4f4f9f4 commit e5f7a27
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
5 changes: 4 additions & 1 deletion code/Arduino/peripheral/ConnectionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void ConnectionController::waitForConnection()
//check first part of command (if that command is connection command)
if (readInfo.length() < sizeof (connectCommand) || (readInfo.substring(0, sizeof(connectCommand) - 1) != connectCommand))
{
DEBUG_PRINTLN("Bad info");
DEBUG_PRINT("Bad info: ");
DEBUG_PRINTLNHEX(readInfo);
continue;
}

Expand Down Expand Up @@ -143,6 +144,7 @@ String ConnectionController::getCommand()
{
isConnected = false;
waitForConnection();
timer.reset();
continue;
}

Expand All @@ -162,6 +164,7 @@ String ConnectionController::getCommand()
{
isConnected = false;
waitForConnection();
timer.reset();
continue;
}

Expand Down
1 change: 1 addition & 0 deletions code/c++/cxx-api/AutoConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void AutoConnector::stop() {
isRepeat.store(false);
pConnectingThread->join();
delete pConnectingThread;
pConnectingThread = nullptr;
}
}

Expand Down
2 changes: 1 addition & 1 deletion code/c++/cxx-api/AutoConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AutoConnector {
uint32_t frequency;

public:
AutoConnector(std::function<void()> c, uint32_t f = 500);
AutoConnector(std::function<void()> c, uint32_t f);
~AutoConnector();
void start();
void stop();
Expand Down
8 changes: 7 additions & 1 deletion code/c++/cxx-api/TrackPlatform_BasicConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@ void TrackPlatform_BasicConnector::sendStartCommand()
std::string command = std::string() + static_cast<char>(communicationControllerID) + static_cast<char>(startCommunicationCommand) + static_cast<char>(APIWithAutoDiconnect);
isConnectedToArduino = true;
sendOneCommand(command);
autoConnector->start();
}
void TrackPlatform_BasicConnector::sendStopCommand()
{
if (!isConnected())
{
throw NoConnectionException();
}
autoConnector->stop();
std::string command = std::string() + static_cast<char>(communicationControllerID) + static_cast<char>(stopCommunicationCommand);
sendOneCommand(command);
isConnectedToArduino = false;
}

TrackPlatform_BasicConnector::TrackPlatform_BasicConnector()
TrackPlatform_BasicConnector::TrackPlatform_BasicConnector() :
autoConnector(new AutoConnector([this]()
{
this->sendOneCommand(std::string() + static_cast<char>(communicationControllerID) + static_cast<char>(refreshConnectionCommunicationCommand));
}, timeoutToAutoreconnectInMs))
{
}

Expand Down
3 changes: 3 additions & 0 deletions code/c++/cxx-api/TrackPlatform_BasicConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
#define _TRACKPLATFORM_BASICCONNECTOR_H_

#include <string>
#include "AutoConnector.h"

class TrackPlatform_BasicConnector
{
bool isConnectedToArduino = false;
AutoConnector* autoConnector = nullptr;

protected:
static const char stopSymbol = '|';
static const uint8_t timesToAutoreconnect = 3;
static const uint32_t timeoutToNextConnectInMs = 500;
static const uint32_t timeoutToAutoreconnectInMs = 1000;
static const std::string correctAnswer;

virtual void write(const std::string& s) = 0;
Expand Down
1 change: 0 additions & 1 deletion code/c++/cxx-api/TrackPlatform_BasicManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TrackPlatform_BasicManagement
protected:
static const uint8_t minSpeed = 0;
static const uint8_t maxSpeed = 255;
static const uint32_t reconnectTime = 500;
static const char delimiter = ';';

void sendMove(const std::string& additionalInfo);
Expand Down
11 changes: 0 additions & 11 deletions code/c++/cxx-api/TrackPlatform_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,13 @@ TrackPlatform_BasicConnector* TrackPlatform_Manager::createConnectorByMode(Conne
TrackPlatform_Manager::TrackPlatform_Manager(ConnectionModes mode, const CommunicationInfoStruct& info) :
TrackPlatform_BasicManagement(createConnectorByMode(mode, info))
{
std::function<void()> callback = [this]() { this->refreshConnection(); };
pAutoConnector = new AutoConnector(callback, reconnectTime);
pAutoConnector->start();
}

TrackPlatform_Manager::~TrackPlatform_Manager()
{
if (pAutoConnector) delete pAutoConnector;
TrackPlatform_BasicConnector* connector = getConnector();
if (connector)
{
delete connector;
}
}

void TrackPlatform_Manager::startAutoConnection() {
pAutoConnector->start();
}
void TrackPlatform_Manager::stopAutoConnection() {
pAutoConnector->stop();
}
4 changes: 0 additions & 4 deletions code/c++/cxx-api/TrackPlatform_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
class TrackPlatform_Manager : public TrackPlatform_BasicManagement
{
static TrackPlatform_BasicConnector* createConnectorByMode(ConnectionModes mode, const CommunicationInfoStruct& info);
AutoConnector* pAutoConnector = nullptr;

public:
TrackPlatform_Manager(ConnectionModes mode, const CommunicationInfoStruct& info);
~TrackPlatform_Manager();

void startAutoConnection();
void stopAutoConnection();
};

#endif /* _TRACKPLATFORM_MANAGER_H_ */

0 comments on commit e5f7a27

Please sign in to comment.