Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cabinet/Cabinet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define SERVICE_SLEEP_TIME_MILLISECONDS 1

using namespace std;
chrono::high_resolution_clock::time_point currentTime()
chrono::high_resolution_clock::time_point CurrentTime()
{
return chrono::high_resolution_clock::now();
}
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/HardwareDemo/CurrentTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


using namespace std::chrono;
high_resolution_clock::time_point currentTime()
high_resolution_clock::time_point CurrentTime()
{
return high_resolution_clock::now();
}
6 changes: 3 additions & 3 deletions Cabinet/TestCabinet/CodeCheckTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ TEST(CodeCheckTests, test_if_no_code_has_been_entered)
{

CodeCheck checker;
EXPECT_EQ(false, checker.inputCheck(""));
EXPECT_EQ(false, checker.InputCheck(""));
}

TEST(CodeCheckTests, test_if_incorrect_code_is_entered_returns_false)
{

CodeCheck checker;
EXPECT_EQ(false, checker.inputCheck("12364"));
EXPECT_EQ(false, checker.InputCheck("12364"));
}

TEST(CodeCheckTests, test_if_the_strings_match)
{
CodeCheck checker;
EXPECT_EQ(true, checker.inputCheck("1234"));
EXPECT_EQ(true, checker.InputCheck("1234"));
}

TEST(CodeCheckTests, test_if_key_input_is_valid_1234e)
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/TestCabinet/HTTPPostClientSpy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "HTTPPostClientSpy.h"

bool HTTPPostClientSpy::sendPostMsg(std::string URL, std::string data)
bool HTTPPostClientSpy::SendPostMsg(std::string URL, std::string data)
{
lastPOSTURL = URL;
lastPOSTData = data;
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/TestCabinet/HTTPPostClientSpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class HTTPPostClientSpy : public HTTPPostClient
{
public:
bool sendPostMsg(std::string URL, std::string data);
bool SendPostMsg(std::string URL, std::string data);
bool sendPostMsgResult = false;
std::string lastPOSTURL;
std::string lastPOSTData;
Expand Down
25 changes: 4 additions & 21 deletions Cabinet/TestCabinet/POSTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,28 @@

using namespace testing;

/*********************************
****Actual Libcurl Post**********/
/*TEST(LibCurlPOSTTests, Curl_send_attempt_to_HTTPBinOrg_returns_true)
{
LibCurlPostClient testClient;
EXPECT_EQ(true, testClient.sendPostMsg("http://httpbin.org/post", "TEST"));
}

TEST(LibCurlPOSTTests, Curl_send_attempt_to_GibberishInvalid_returns_false)
{
LibCurlPostClient testClient;
EXPECT_EQ(false, testClient.sendPostMsg("http://gibberish.invalid", "TEST"));
}*/

/*********************************
*******Postman Tests*************/

TEST(PostmanTests, Postman_returns_false_when_client_fails)
{
HTTPPostClientSpy testClient;
testClient.sendPostMsgResult = false;
Postman pat("http://gibberish.invalid", &testClient);
EXPECT_EQ(false, pat.sendEventNotification("AAE114", "Open", "Available"));
EXPECT_EQ(false, pat.SendEventNotification("AAE114", "Open", "Available"));
}

TEST(PostmanTests, Postman_returns_true_when_client_succeeds)
{
HTTPPostClientSpy testClient;
testClient.sendPostMsgResult = true;
Postman pat("http://gibberish.invalid", &testClient);
EXPECT_EQ(true, pat.sendEventNotification("AAE114", "Open", "Available"));
EXPECT_EQ(true, pat.SendEventNotification("AAE114", "Open", "Available"));
}

TEST(PostmanTests, Postman_sends_to_URL_given)
{
HTTPPostClientSpy testClient;
testClient.sendPostMsgResult = true;
Postman pat("http://gibberish.invalid", &testClient);
pat.sendEventNotification("AAE114", "Open", "Available");
pat.SendEventNotification("AAE114", "Open", "Available");
EXPECT_EQ("http://gibberish.invalid", testClient.lastPOSTURL);
}

Expand All @@ -58,6 +41,6 @@ TEST(PostmanTests, Postman_sends_data_formatted_correctly)
HTTPPostClientSpy testClient;
testClient.sendPostMsgResult = true;
Postman pat("http://gibberish.invalid", &testClient);
pat.sendEventNotification("AAE114", "Open", "Available");
pat.SendEventNotification("AAE114", "Open", "Available");
EXPECT_EQ(boxPOSTData, testClient.lastPOSTData);
}
2 changes: 1 addition & 1 deletion Cabinet/TestCabinet/TestTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using namespace ::std::chrono;

high_resolution_clock::time_point fakeTime;

high_resolution_clock::time_point currentTime()
high_resolution_clock::time_point CurrentTime()
{
return fakeTime;
}
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/Cabinet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool Cabinet::DoorEventCallback(bool doorOpen)

if(doorOpen)
{
return postie->sendEventNotification(boxID, "Open", "Available");
return postie->SendEventNotification(boxID, "Open", "Available");
}
return false;

Expand Down
8 changes: 4 additions & 4 deletions Cabinet/libCabinet/CodeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ CodeCheck::CodeCheck()

}

bool CodeCheck::inputCheck(std::string inputCode)
bool CodeCheck::InputCheck(std::string inputCode)
{
std::string correctCode = "1234";
if((inputCode == correctCode))
std::string correctCode = "1234";
if((inputCode == correctCode))
{

if(unlockCallback)
Expand Down Expand Up @@ -54,7 +54,7 @@ void CodeCheck::keyPressed(int keyID)
}
else if (inputConversion[keyID] == 'E')
{
if (!inputCheck(codeEntered))
if (!InputCheck(codeEntered))
{
codeEntered = "";
}
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/CodeCheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CodeCheck
{
public:
CodeCheck();
bool inputCheck(std::string inputCode);
bool InputCheck(std::string inputCode);
void keyPressed(int keyID);
std::string getCodeEntered();
void SetUnlockCallback (std::function<void()> callback);
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/CurrentTime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define CURRENTTIME_H
#include <chrono>

std::chrono::high_resolution_clock::time_point currentTime();
std::chrono::high_resolution_clock::time_point CurrentTime();

#endif
4 changes: 2 additions & 2 deletions Cabinet/libCabinet/HBridgeLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void RunRequest(bool &requested, bool &inProgress,
{
requested = false;
inProgress = true;
startTime = currentTime();
startTime = CurrentTime();
pin->State(true);
}

if(inProgress && (currentTime() - startTime) >= milliseconds(500))
if(inProgress && (CurrentTime() - startTime) >= milliseconds(500))
{
inProgress = false;
pin->State(false);
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/HBridgeLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class HBridgeLock
{
public:
using current_time_point_t = decltype(currentTime());
using current_time_point_t = decltype(CurrentTime());
private:
OutputPin *openPin;
OutputPin *closePin;
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/HTTPPostClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class HTTPPostClient
{
public:
virtual bool sendPostMsg(std::string URL, std::string data) = 0;
virtual bool SendPostMsg(std::string URL, std::string data) = 0;
virtual ~HTTPPostClient(){};
protected:
private:
Expand Down
9 changes: 5 additions & 4 deletions Cabinet/libCabinet/LibCurlPostClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
#include "LibCurlPostClient.h"


size_t writeData(char *receivedBuffer, size_t receivedSize,
size_t WriteData(char *receivedBuffer, size_t receivedSize,
size_t newMemoryBytes, std::string *stringPointer)
{
stringPointer->append(receivedBuffer, newMemoryBytes);
return receivedSize * newMemoryBytes;
}

bool LibCurlPostClient::sendPostMsg(std::string URL, std::string data)
bool LibCurlPostClient::SendPostMsg(std::string URL, std::string data)
{
/* get a curl handle */
curl = curl_easy_init();
if(curl)
{

std::string receivedData;

/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &receivedData);

curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());

/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());

Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/LibCurlPostClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class LibCurlPostClient : public HTTPPostClient
{
public:
bool sendPostMsg(std::string URL, std::string data);
bool SendPostMsg(std::string URL, std::string data);
protected:
private:
CURL *curl;
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/MatrixKeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void MatrixKeypad::SetKeyPressedCallback(key_pressed_callback_t callback)
void MatrixKeypad::Service()
{
uint16_t states = reader->Read();
time_point_t now = currentTime();
time_point_t now = CurrentTime();

for(size_t key = 0; key < numberOfKeys; key++)
{
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/MatrixKeypad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MatrixKeypad
{
public:
using key_pressed_callback_t = std::function<void(int)>;
using time_point_t = decltype(currentTime());
using time_point_t = decltype(CurrentTime());

static const size_t numberOfKeys{12};
private:
Expand Down
4 changes: 2 additions & 2 deletions Cabinet/libCabinet/Postman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Postman::Postman(std::string serverAddress, HTTPPostClient *client)
this->serverAddress = serverAddress;
}

bool Postman::sendEventNotification(std::string boxID, std::string doorStatus, std::string defibStatus)
bool Postman::SendEventNotification(std::string boxID, std::string doorStatus, std::string defibStatus)
{

std::string boxPOSTData = "{\n"
Expand All @@ -15,6 +15,6 @@ bool Postman::sendEventNotification(std::string boxID, std::string doorStatus, s
" \"defib_status\" : \"" + defibStatus + "\" \n"
"}";

return postClient->sendPostMsg(serverAddress, boxPOSTData);
return postClient->SendPostMsg(serverAddress, boxPOSTData);

}
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/Postman.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Postman
{
public:
Postman(std::string serverAddress, HTTPPostClient *client);
bool sendEventNotification(std::string boxID, std::string doorStatus, std::string defibStatus);
bool SendEventNotification(std::string boxID, std::string doorStatus, std::string defibStatus);
protected:
private:
std::string serverAddress;
Expand Down
12 changes: 6 additions & 6 deletions Cabinet/libCabinet/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ Switch::Switch(InputPin *switchPin, doorCallback doorEventCallback)
doorCallbackFunction = doorEventCallback;
pin = switchPin;
previouslyPressed = false;
PressedState = false;
pressedState = false;
}

bool Switch::IsPressed()
{
return PressedState;
return pressedState;
}

void Switch::StateCheck()
{

if(pin->State() == false)
{
PressedState = false;
pressedState = false;
previouslyPressed = false;
}
else
{

if (previouslyPressed == false)
{
firstTime = currentTime();
firstTime = CurrentTime();

}
else
{
if (((currentTime() - firstTime) >= milliseconds(10)) && !PressedState)
if (((CurrentTime() - firstTime) >= milliseconds(10)) && !pressedState)
{
doorCallbackFunction(true);
PressedState = true;
pressedState = true;
}
}
previouslyPressed = true;
Expand Down
2 changes: 1 addition & 1 deletion Cabinet/libCabinet/Switch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Switch
void Service();
private:
InputPin *pin;
bool PressedState;
bool pressedState;
bool previouslyPressed;
std::chrono::high_resolution_clock::time_point firstTime;
doorCallback doorCallbackFunction;
Expand Down