Skip to content

Commit

Permalink
Add rename by empty name
Browse files Browse the repository at this point in the history
  • Loading branch information
nkh-lab committed Apr 19, 2023
1 parent 28cea63 commit 9a8e2f6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app-cli/src/SetRelayWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool SetRelayWorker::RenameModule(const std::string& module, const std::string&

m->GetNameAndChannels(module_name, channels);

if (module_name == module)
if (module_name == module || module.empty())
{
ret = m->SetName(new_module);
out.clear();
Expand Down
2 changes: 1 addition & 1 deletion app-cli/src/TextUserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const char* TextUserInterface::kGetRelayHelp =
const char* TextUserInterface::kSetRelayHelp =
"Usage:\n"
" <ModuleName>_<ChannelNumber>=<StateToSet> Set the state 0 or 1 of the specified channel (numbering starts from 1)\n"
" <ModuleName>=<NewModuleName> Rename module\n"
" <ModuleName>=<NewModuleName> Rename module. If <ModuleName> is empty, will rename the first detected\n"
"\n"
"Service commands:\n"
" -h | --help Display this help text\n"
Expand Down
34 changes: 34 additions & 0 deletions app-cli/tests/unit/SetRelayWorkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,40 @@ TEST_F(SetRelayWorkerTest, RenameModule)
std::cout << "=================================================\n";
*/

EXPECT_TRUE(out.empty());
EXPECT_TRUE(ret);
}
//
// Should be renamed first detected
//
TEST_F(SetRelayWorkerTest, RenameModuleEmptyName)
{
const char* argv[] = {"", "=module1_new"};
int argc = ARRAY_SIZE(argv);
std::string module1_name{"module1"};
std::vector<bool> module1_channels{0, 1};
std::string module2_name{"module2"};
std::vector<bool> module2_channels{0, 1, 0, 1, 0, 1, 0, 1};

EXPECT_CALL(*relay_manager_, GetModules()).Times(1).WillOnce(Return(relay_modules_size2_));
EXPECT_CALL(*module1_, GetNameAndChannels(_, _))
.Times(1)
.WillOnce(DoAll(
SetArgReferee<0>(module1_name), SetArgReferee<1>(module1_channels), Return(true)));
EXPECT_CALL(*module1_, SetName("module1_new")).Times(1).WillOnce(Return(true));

SetRelayWorker worker(std::move(relay_manager_));

std::string out;

bool ret = worker.Run(argc, argv, out);

/* Debug
std::cout << "=================================================\n";
std::cout << out;
std::cout << "=================================================\n";
*/

EXPECT_TRUE(out.empty());
EXPECT_TRUE(ret);
}
13 changes: 13 additions & 0 deletions doc/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,18 @@ sudo udevadm control --reload-rules

In the [examples](examples) folder you can find an example of udev rules file [91-usbrelay.rules](examples/linux/udev/91-usbrelay.rules).

## Corrupted module name
**Issue:**

The module name is corrupted and cannot be used for renaming.

**Fix:**

Leave only this module connected and use an empty name for renaming, for example:
```
./setrelay =R8
```
In this example, the first detetected module (in our case, only the one with the corrupted name) is renamed to "R8".

---
Go to [Contents](Contents.md)
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

add_subdirectory(cpp-utils)
add_subdirectory(hidapi)
if(${PROJECT_NAME}_BUILD_SIMU OR ${PROJECT_NAME}_BUILD_GUI)
if(${PROJECT_NAME}_BUILD_SIMU OR ${PROJECT_NAME}_BUILD_GUI OR ${PROJECT_NAME}_BUILD_UTESTS)
set(JSONCPP_WITH_TESTS OFF CACHE BOOL "")
set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "")
set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "")
Expand Down

0 comments on commit 9a8e2f6

Please sign in to comment.