Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Console version #34

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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 .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
submodules: recursive

- name: Install necessary packages
run: sudo apt install -y ninja-build curl libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config autoconf libudev-dev dh-autoreconf freeglut3-dev gdb make
run: sudo apt update && sudo apt-get install --fix-missing && sudo apt install -y ninja-build curl libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config autoconf libudev-dev dh-autoreconf freeglut3-dev gdb make

- uses: actions/checkout@v2.3.4

Expand Down
28 changes: 26 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
]
},
{
"name": "(gdb) Launch IBTConsole",
"name": "(gdb) Launch IBTConsoleTester",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/out/build/Linux-debug/IBTConsole",
"program": "${workspaceFolder}/out/build/Linux-debug/IBTConsoleTester",
"args": [ "~/RCX/firm0332.lgo" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
Expand All @@ -73,6 +73,30 @@
"ignoreFailures": true
}
]
},
{
"name": "(gdb) Launch ibt",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/out/build/Linux-debug/ibt",
"args": [ "--lasm" ],//"--firmware", "~/RCX/firm0332.lgo" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}

]
Expand Down
31 changes: 22 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ include_directories("${CMAKE_SOURCE_DIR}/lib/imgui_filebrowser/imgui-filebrowser

add_executable(
InfraredBrickTower
IBTController/IBTController.cpp
IBTController/main.cpp
IBTController/ControllerUI.h
IBTController/ControllerUI.cpp)

add_executable(
IBTConsole
ConsoleTester/ConsoleTester.cpp)
IBTConsoleTester
ConsoleTester/main.cpp)

add_executable(
ibt
IBTConsole/main.cpp)

target_link_libraries(InfraredBrickTower PRIVATE imgui::imgui)

Expand All @@ -74,20 +78,29 @@ target_link_libraries(InfraredBrickTower PRIVATE Common)
target_link_libraries(InfraredBrickTower PRIVATE TowerLogic)
target_link_libraries(InfraredBrickTower PRIVATE PBrickLogic)

target_link_libraries(IBTConsole PRIVATE Common)
target_link_libraries(IBTConsole PRIVATE TowerLogic)
target_link_libraries(IBTConsole PRIVATE PBrickLogic)
target_link_libraries(IBTConsoleTester PRIVATE Common)
target_link_libraries(IBTConsoleTester PRIVATE TowerLogic)
target_link_libraries(IBTConsoleTester PRIVATE PBrickLogic)

target_link_libraries(ibt PRIVATE Common)
target_link_libraries(ibt PRIVATE TowerLogic)
target_link_libraries(ibt PRIVATE PBrickLogic)

if (WIN32)
target_link_libraries(InfraredBrickTower PRIVATE winusb)
target_link_libraries(InfraredBrickTower PRIVATE cfgmgr32)
target_link_libraries(InfraredBrickTower PRIVATE opengl32.lib)

target_link_libraries(IBTConsole PRIVATE winusb)
target_link_libraries(IBTConsole PRIVATE cfgmgr32)
target_link_libraries(IBTConsoleTester PRIVATE winusb)
target_link_libraries(IBTConsoleTester PRIVATE cfgmgr32)

target_link_libraries(ibt PRIVATE winusb)
target_link_libraries(ibt PRIVATE cfgmgr32)
else()
target_link_libraries(InfraredBrickTower PRIVATE PkgConfig::libusb)
target_link_libraries(InfraredBrickTower PRIVATE OpenGL)

target_link_libraries(IBTConsole PRIVATE PkgConfig::libusb)
target_link_libraries(IBTConsoleTester PRIVATE PkgConfig::libusb)

target_link_libraries(ibt PRIVATE PkgConfig::libusb)
endif()
2 changes: 1 addition & 1 deletion ConsoleTester/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
file(GLOB SOURCE_C "ConsoleTester.cpp")
file(GLOB SOURCE_C "main.cpp")
63 changes: 2 additions & 61 deletions ConsoleTester/ConsoleTester.cpp → ConsoleTester/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@
#include <stdio.h>
#include <iostream>

bool StringsAreEqual(char* strOne, char* strTwo);
void MicroScoutCLI(Tower::RequestData* towerData);

void TestTower(Tower::RequestData* data);
void DriveMotors(Tower::RequestData* towerData);
void BeepRCX(Tower::RequestData* towerData);
void BeepMicroScout(Tower::RequestData* towerData);
void BeepRCXAndMicroScout(Tower::RequestData* towerData);
bool ParseAndSendLASM(Tower::RequestData* towerData);

static char* lasmInput = "";

Check warning on line 16 in ConsoleTester/main.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu

ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

Check warning on line 16 in ConsoleTester/main.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu

ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -81,63 +71,14 @@
//}
//}

lasmInput = "plays 1";

Check warning on line 74 in ConsoleTester/main.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu

ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

Check warning on line 74 in ConsoleTester/main.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu

ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
ParseAndSendLASM(towerData);
LASM::ParseAndSendLASM(lasmInput, towerData);

usbTowerInterface->Flush();
usbTowerInterface->Close();

delete usbTowerInterface;
delete towerData;

return 0;
}

enum LASMStatus
{
LASM_DEFAULT,
LASM_SUCCESS,
LASM_BAD_PARAMS,
LASM_NO_REPLY,
LASM_WRITE_FAILED,
LASM_FAILED_OTHER,
LASM_COMMAND_NOT_FOUND,
LASM_IN_PROGRESS
};
static LASMStatus lasmStatus = LASM_DEFAULT;
static bool lasmEntered = false;

bool ParseAndSendLASM(Tower::RequestData* towerData)
{
lasmStatus = LASM_IN_PROGRESS;

std::string inputString(lasmInput);
std::string inputParts[5];
int partIndex = 0;

size_t partLength = 0;
while ((partLength = inputString.find(" ")) != std::string::npos) {
inputParts[partIndex++] = inputString.substr(0, partLength);
inputString.erase(0, partLength + 1);
}
inputParts[partIndex] = inputString;

static LASM::CommandData lasmCommand;
if (LASM::GetCommandFromCode(inputParts[0].c_str(), inputParts + 1, partIndex, &lasmCommand))
{
if (LASM::SendCommand(&lasmCommand, towerData))
{
lasmStatus = LASM_SUCCESS;
return true;
}
else
{
lasmStatus = LASM_FAILED_OTHER;
}
}
else
{
lasmStatus = LASM_COMMAND_NOT_FOUND;
}

return false;
}
4 changes: 4 additions & 0 deletions IBTConsole/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file(GLOB SOURCE_H "ControllerUI.h")
file(GLOB SOURCE_C
"main.cpp"
"ControllerUI.cpp")
157 changes: 157 additions & 0 deletions IBTConsole/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#if defined(WIN32)
#include "WinUsbTowerInterface.h"

#elif defined(__linux)
#include "LinuxUsbTowerInterface.h"

#endif
#include "TowerController.h"
#include "VLL.h"
#include "LASM.h"
#include "PBrick.h"
#include <assert.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
// #include <string>

using namespace LASM;

int main(int argc, char* argv[])
{
HostTowerCommInterface* usbTowerInterface;

#if defined(WIN32)
bool gotInterface = OpenWinUsbTowerInterface(usbTowerInterface);
#elif defined(__linux)
bool gotInterface = OpenLinuxUSBTowerInterface(usbTowerInterface);
#endif

if (!gotInterface)
{
fprintf(stderr, "Error getting USB interface!\n");
return 1;
}

Tower::RequestData* towerData = new Tower::RequestData(usbTowerInterface);
Tower::SetCommMode(Tower::CommMode::IR, towerData);

Tower::Flush(Tower::CommBuffer::ALL_BUFFERS, towerData);
usbTowerInterface->Flush();

CommandData lasmCommand;
Cmd_PBAliveOrNot(lasmCommand);
SendCommand(&lasmCommand, towerData);

if (argc < 2)
{
printf("Not enough parameters provided.\n");
return 1;
}

bool verbose = false;
char* firmwarePath = NULL;
char* prgmToCompilePath = NULL;
char* prgmToDownloadPath = NULL;
bool lasm = false;

int result = 0;
for (int i = 1; i < argc; i++)
{
char* prior = argv[i - 1];
char* arg = argv[i];
if (strcmp(prior, "-v") == 0)
{
verbose = true;
}
else if (strcmp(prior, "--firmware") == 0)
{
firmwarePath = arg;
}
else if (strcmp(prior, "--download") == 0)
{
prgmToDownloadPath = arg;
}
else if (strcmp(prior, "--compile") == 0)
{
prgmToCompilePath = arg;
}
else if (strcmp(arg, "--lasm") == 0 && i == argc - 1)
{
printf("Enter LASM commands or exit to exit:\n");

LASMStatus status;
char* input;
std::string inputString;
size_t len = 0;
// size_t read = 0;
while (std::getline(std::cin, inputString))
{
printf(">");
// read = getline(&input, &len, stdin);
// std::getline(std::cin, inputString);

// To account for the newline added at the end
inputString.resize(inputString.length() - 1);
// input[read - 1] = 0;

// if (strncmp(input, "exit", read - 1) == 0)
if (inputString == "exit")
{
break;
}
else
{
status = ParseAndSendLASM(input, towerData);

Check warning on line 105 in IBTConsole/main.cpp

View workflow job for this annotation

GitHub Actions / build-windows

uninitialized local variable 'input' used [D:\a\InfraredBrickTower\InfraredBrickTower\out\build\Windows-release\ibt.vcxproj]

Check warning on line 105 in IBTConsole/main.cpp

View workflow job for this annotation

GitHub Actions / build-windows

uninitialized local variable 'input' used [D:\a\InfraredBrickTower\InfraredBrickTower\out\build\Windows-release\ibt.vcxproj]
switch (status)
{
case LASM_BAD_PARAMS:
printf("Incorrect parameters provided.");
break;
case LASM_NO_REPLY:
printf("No reply received from brick.");
break;
case LASM_WRITE_FAILED:
printf("Failed to send command.");
break;
case LASM_FAILED_OTHER:
printf("Command failed.");
break;
case LASM_COMMAND_NOT_FOUND:
printf("Unknown LASM command.");
break;
}
printf("\n");
}
}
break;
}
}

if (verbose)
{
// idk
}

if (firmwarePath)
{
result = RCX::DownloadFirmware(firmwarePath, towerData) ? 0 : 1;
}

if (prgmToDownloadPath)
{
result = RCX::DownloadProgram(prgmToDownloadPath, 1, towerData) ? 0 : 1;
}

if (prgmToCompilePath)
{
// call nqc and compile???
}

usbTowerInterface->Close();

delete usbTowerInterface;
delete towerData;

return 0;
}
2 changes: 1 addition & 1 deletion IBTController/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file(GLOB SOURCE_H "ControllerUI.h")
file(GLOB SOURCE_C
"IBTController.cpp"
"main.cpp"
"ControllerUI.cpp")
Loading
Loading