Skip to content

Commit b020d60

Browse files
Added Dry Run Mode for testing.
1 parent b24a61d commit b020d60

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

ArduinoStrike/ArduinoStrike/Arduino.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "Logger.h"
22
#include "Arduino.h"
3-
43
extern volatile bool g_shouldExit;
54

65
Arduino::~Arduino()
@@ -12,8 +11,13 @@ Arduino::~Arduino()
1211
}
1312
}
1413

15-
Arduino::Arduino(LPCSTR name) : io_context(), serial_port(io_context)
14+
Arduino::Arduino(LPCSTR name, bool dry_run) : io_context(), serial_port(io_context), dry_run(dry_run)
1615
{
16+
if (dry_run)
17+
{
18+
return;
19+
}
20+
1721
char port[100] = "\\.\\";
1822
Logger::LogMessage("Searching for device...");
1923

@@ -275,6 +279,12 @@ bool Arduino::SelectDevice(const vector<DeviceInfo>& devices, LPSTR port)
275279

276280
bool Arduino::WriteMessage(const string& message)
277281
{
282+
if (dry_run)
283+
{
284+
Logger::LogMessage("Message sent: " + message);
285+
return true;
286+
}
287+
278288
if (!serial_port.is_open())
279289
{
280290
Logger::LogMessage("Attempt to write to a closed serial port");

ArduinoStrike/ArduinoStrike/Arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "Utils.h"
55
#include <devguid.h>
66
#include <SetupAPI.h>
7-
87
using namespace std;
98
using namespace std::chrono;
109
using namespace this_thread;
@@ -21,10 +20,11 @@ class Arduino
2120
{
2221
public:
2322
~Arduino();
24-
Arduino(LPCSTR name);
23+
Arduino(LPCSTR name, bool dry_run = false);
2524
bool WriteMessage(const string& message);
2625

2726
private:
27+
bool dry_run;
2828
io_context io_context;
2929
serial_port serial_port;
3030

ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,32 @@ static BOOL WINAPI ConsoleHandler(DWORD dwCtrlType)
2626
return FALSE;
2727
}
2828

29-
int main()
29+
int main(int argc, char* argv[])
3030
{
3131
Logger::Init();
3232

3333
Utils utils;
3434
Config config;
35-
35+
36+
Logger::LogMessage("Main: argc = " + to_string(argc));
37+
for (int i = 0; i < argc; i++)
38+
{
39+
Logger::LogMessage("Main: argv[" + to_string(i) + "] = " + string(argv[i]));
40+
}
41+
42+
bool dry_run = false;
43+
for (int i = 1; i < argc; i++)
44+
{
45+
string arg = argv[i];
46+
Logger::LogMessage("Main: Checking argument: " + arg);
47+
48+
if (arg == "--dry-run" || arg == "-d")
49+
{
50+
dry_run = true;
51+
Logger::LogMessage("Main: Dry run mode enabled via command line argument!");
52+
}
53+
}
54+
3655
if (!SetConsoleCtrlHandler(ConsoleHandler, TRUE))
3756
{
3857
Logger::LogMessage("Failed to set console control handler!", boost::log::trivial::error);
@@ -44,7 +63,7 @@ int main()
4463

4564
try
4665
{
47-
arduino = new Arduino("Arduino Leonardo");
66+
arduino = new Arduino("Arduino Leonardo", dry_run);
4867
}
4968
catch (const runtime_error& e)
5069
{

0 commit comments

Comments
 (0)