From d3d02dcba74d22ef418ac67496fdb9a952ccc34b Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:46:06 +0200 Subject: [PATCH 01/22] add circle config --- .circleci/config.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2fa7b25 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,37 @@ +version: 2.1 + +workflows: + version: 2 + test-publish: + jobs: + - build-linux: + filters: # required since `deploy` has tag filters AND requires `build` + tags: + only: /.*/ + #- build-windows: + # filters: # required since `deploy` has tag filters AND requires `build` + # tags: + # only: /.*/ + #- build-mac: + # filters: # required since `deploy` has tag filters AND requires `build` + # tags: + # only: /.*/ + +jobs: + build-liunux: + working_directory: ~/ykush + docker: + - image: gcc + steps: + - checkout + - run: + name: install deps + command: | + gcc -v + - run: + name: build + command: make + - store_artifacts: + path: bin + prefix: bin + destination: bin From cc5223daff8f3f6f68750a1d6818e9677bc57e22 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:48:03 +0200 Subject: [PATCH 02/22] wip --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2fa7b25..0f3d8c3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 workflows: version: 2 - test-publish: + builds: jobs: - build-linux: filters: # required since `deploy` has tag filters AND requires `build` @@ -18,7 +18,7 @@ workflows: # only: /.*/ jobs: - build-liunux: + build-linux: working_directory: ~/ykush docker: - image: gcc From cad69688dc10c418c612563fa8616c435a022ef9 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:49:10 +0200 Subject: [PATCH 03/22] add usb deps --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0f3d8c3..798e0a8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ jobs: - run: name: install deps command: | - gcc -v + apt-get install libusb-1.0-0 libusb-1.0-0-dev - run: name: build command: make From e2a48431885bf630ca93a1431d0cba9dae69ba71 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:49:54 +0200 Subject: [PATCH 04/22] apt update --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 798e0a8..14dfe14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,8 @@ jobs: - run: name: install deps command: | - apt-get install libusb-1.0-0 libusb-1.0-0-dev + apt update + apt install libusb-1.0-0 libusb-1.0-0-dev - run: name: build command: make From 0dca06dde6fc70df6e35142cddf72947276d8036 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:50:40 +0200 Subject: [PATCH 05/22] apt yes --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 14dfe14..f7d415e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: name: install deps command: | apt update - apt install libusb-1.0-0 libusb-1.0-0-dev + apt install -y libusb-1.0-0 libusb-1.0-0-dev - run: name: build command: make From 20080ca91031f259ca4f8a08d20a434248c3952b Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:54:59 +0200 Subject: [PATCH 06/22] add windows build --- .circleci/config.yml | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f7d415e..e785276 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,9 @@ version: 2.1 +orbs: + win: circleci/windows@1.0.0 + + workflows: version: 2 builds: @@ -8,10 +12,10 @@ workflows: filters: # required since `deploy` has tag filters AND requires `build` tags: only: /.*/ - #- build-windows: - # filters: # required since `deploy` has tag filters AND requires `build` - # tags: - # only: /.*/ + - build-windows: + filters: # required since `deploy` has tag filters AND requires `build` + tags: + only: /.*/ #- build-mac: # filters: # required since `deploy` has tag filters AND requires `build` # tags: @@ -35,4 +39,23 @@ jobs: - store_artifacts: path: bin prefix: bin - destination: bin + destination: bin/linux + build-windows: + executor: + name: win/vs2019 + shell: powershell.exe + working_directory: ~/pyring + steps: + - checkout + - run: + name: "Install deps" + command: choco install gcc make + - run: + name: "Build" + command: | + python --version + make -f Makefilefile_win64 + - store_artifacts: + path: bin + prefix: bin + destination: bin/win64 From 4235a3099a8abd957096edb23fc1f8b2d46a1921 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 08:57:38 +0200 Subject: [PATCH 07/22] install mingw --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e785276..04509a1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ jobs: - checkout - run: name: "Install deps" - command: choco install gcc make + command: choco install mingw - run: name: "Build" command: | From a6f1ab4f3abc37441f683090157561b1b844e7ca Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:00:54 +0200 Subject: [PATCH 08/22] install make again --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 04509a1..99a2fb3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ jobs: - checkout - run: name: "Install deps" - command: choco install mingw + command: choco install mingw make - run: name: "Build" command: | From ba9f3df8dd93ee97cb61f9b357d37f069e786137 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:05:13 +0200 Subject: [PATCH 09/22] fix typo --- .circleci/config.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 99a2fb3..bbf63a1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,8 +37,7 @@ jobs: name: build command: make - store_artifacts: - path: bin - prefix: bin + path: bin/ykushcmd destination: bin/linux build-windows: executor: @@ -54,8 +53,7 @@ jobs: name: "Build" command: | python --version - make -f Makefilefile_win64 + make -f Makefile_win64 - store_artifacts: - path: bin - prefix: bin + path: bin/Win64 destination: bin/win64 From 4eba7bb112d20bd7f5637ff1dcb16067c7d865dc Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:15:12 +0200 Subject: [PATCH 10/22] fixes makefile_win64 --- .circleci/config.yml | 3 +-- Makefile_win64 | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bbf63a1..8e32a19 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,7 +38,7 @@ jobs: command: make - store_artifacts: path: bin/ykushcmd - destination: bin/linux + destination: bin/linux/ykushcmd build-windows: executor: name: win/vs2019 @@ -52,7 +52,6 @@ jobs: - run: name: "Build" command: | - python --version make -f Makefile_win64 - store_artifacts: path: bin/Win64 diff --git a/Makefile_win64 b/Makefile_win64 index c9a644f..1f6a7fe 100644 --- a/Makefile_win64 +++ b/Makefile_win64 @@ -17,14 +17,14 @@ PROG_OBJ = $(PROG_SOURCE_FULL:.cpp=.o) CUR_PATH = $(CURDIR) INCLUDEPATHS = $(addprefix -I$(CUR_PATH)/, $(dir $(SOURCE_FULL)) hidapi ) -LOADPATHS = -L$(CUR_PATH)/hidapi/mingw32 +LOADPATHS = -L$(CUR_PATH)/hidapi/mingw64 LIBS = -lhidapi FLAGS = -static-libgcc -static-libstdc++ #Change MinGW exec name to match version instaled in your system CPP = x86_64-w64-mingw32-g++ -#CPP_WIN32 = i686-w64-mingw32-g++ -#CPP_WIN64 = x86_64-w64-mingw32-g++ +#CPP_WIN32 = i686-w64-mingw32-g++ +#CPP_WIN64 = x86_64-w64-mingw32-g++ ykushcmd_win64.exe : $(PROG_OBJ) $(OBJS) From 042659c2f7c2c05f9a2b789dabe6f638bdcc3250 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:20:54 +0200 Subject: [PATCH 11/22] tuning and add mac build --- .circleci/config.yml | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e32a19..2df0855 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,10 +16,10 @@ workflows: filters: # required since `deploy` has tag filters AND requires `build` tags: only: /.*/ - #- build-mac: - # filters: # required since `deploy` has tag filters AND requires `build` - # tags: - # only: /.*/ + - build-mac: + filters: # required since `deploy` has tag filters AND requires `build` + tags: + only: /.*/ jobs: build-linux: @@ -43,7 +43,7 @@ jobs: executor: name: win/vs2019 shell: powershell.exe - working_directory: ~/pyring + working_directory: ~/ykush steps: - checkout - run: @@ -56,3 +56,20 @@ jobs: - store_artifacts: path: bin/Win64 destination: bin/win64 + - store_artifacts: + path: bin/Win32/ykushcmd_win64.exe + destination: bin/win64/ykushcmd.exe + build-mac: + macos: # indicate that we are using the macOS executor + xcode: "10.0.0" # indicate our selected version of Xcode + steps: + - checkout + - run: + name: install deps + command: brew install gcc make libhid + - run: + name: build + command: make + - store_artifacts: + path: bin/ykushcmd + destination: bin/macos/ykushcmd From b0aade2e9c5030dc587ddef0faa05f433a0f482d Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:25:41 +0200 Subject: [PATCH 12/22] run help to see build works --- .circleci/config.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2df0855..2dc128a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,7 +35,9 @@ jobs: apt install -y libusb-1.0-0 libusb-1.0-0-dev - run: name: build - command: make + command: | + make + bin/ykushcmd --help - store_artifacts: path: bin/ykushcmd destination: bin/linux/ykushcmd @@ -53,6 +55,7 @@ jobs: name: "Build" command: | make -f Makefile_win64 + bin/Win32/ykushcmd_win64.exe --help - store_artifacts: path: bin/Win64 destination: bin/win64 @@ -69,7 +72,9 @@ jobs: command: brew install gcc make libhid - run: name: build - command: make + command: | + make + bin/ykushcmd --help - store_artifacts: path: bin/ykushcmd destination: bin/macos/ykushcmd From 0301e441854f9f6fd064a2775de12eb9ef8a3edf Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:35:26 +0200 Subject: [PATCH 13/22] fix gcc warnings --- .circleci/config.yml | 2 +- src/commandParser.cpp | 12 +- src/ykush3/ykush3.cpp | 261 +++++++++++++++++++--------------------- src/ykushxs/ykushxs.cpp | 16 ++- 4 files changed, 138 insertions(+), 153 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2dc128a..2e56c50 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,7 +55,7 @@ jobs: name: "Build" command: | make -f Makefile_win64 - bin/Win32/ykushcmd_win64.exe --help + cd bin/Win32; ykushcmd_win64.exe --help - store_artifacts: path: bin/Win64 destination: bin/win64 diff --git a/src/commandParser.cpp b/src/commandParser.cpp index 6827eab..64edf9e 100644 --- a/src/commandParser.cpp +++ b/src/commandParser.cpp @@ -70,18 +70,18 @@ enum Board { }; -int commandParser(int argc, char** argv) -{ - Help help(argv[0]); +int commandParser(int argc, char** argv) +{ + Help help(argv[0]); std::string str_ykush ("ykush"); std::string str_ykush3 ("ykush3"); std::string str_ykush2 ("ykush2"); std::string str_ykushxs ("ykushxs"); if ( argc <= 1) { - help.print_all(); + help.print_all(); return 0; - } + } //Parse input options and define action if( argc >= 2) { @@ -101,14 +101,12 @@ int commandParser(int argc, char** argv) return ykush_cmd_parser(argc - 1 , &argv[1]); else help.print_all(); - return -1; } else { //YKUSH return ykush_cmd_parser(argc, argv); } } - return 0; } diff --git a/src/ykush3/ykush3.cpp b/src/ykush3/ykush3.cpp index 986b7a8..d691277 100644 --- a/src/ykush3/ykush3.cpp +++ b/src/ykush3/ykush3.cpp @@ -35,19 +35,19 @@ int ykush3_cmd_parser(int argc, char** argv) char port; char value; char status_response = 0; - + bool action_taken = false; /* CommandLine *cmd_handler = new CommandLine(); - + if ( cmd_handler->parse(argc, argv) ) { std::cout << "Error parsing command." << std::endl; ykush->print_help(); return; } - + YkushCommand user_command = cmd_handler->get_command(); //verify if board is YKUSH3 @@ -62,16 +62,16 @@ int ykush3_cmd_parser(int argc, char** argv) std::string option_str; for (int i = 0; i < user_command.n_options; i++ ) { option_str = user_command.option[i].name; - + //Option: --i2c-usb-serial - if ( option_str.compare("--i2c-usb-serial") ) { + if ( option_str.compare("--i2c-usb-serial") ) { if ( user_command.option[i].n_parameters == 1 ) { ykush->set_usb_serial(user_command.option[i].parameter[0]); } } //Option: --i2c-enable-control - if ( option_str.compare("--i2c-enable-control") == 0 ) { + if ( option_str.compare("--i2c-enable-control") == 0 ) { ykush->i2c_enable_disable_control(true); action_taken = true; } else if ( option_str.compare("--i2c-disable-control") == 0 ) { @@ -80,7 +80,7 @@ int ykush3_cmd_parser(int argc, char** argv) } //Option: --i2c-enable-gateway - if ( option_str.compare("--i2c-enable-gateway") == 0 ) { + if ( option_str.compare("--i2c-enable-gateway") == 0 ) { ykush->i2c_enable_disable_control(true); action_taken = true; } else if ( option_str.compare("--i2c-disable-gateway") == 0 ) { @@ -93,7 +93,7 @@ int ykush3_cmd_parser(int argc, char** argv) //get address parameter if ( user_command.option[i].n_parameters == 1 ) { if ( ykush->i2c_set_address(user_command.option[i].parameter[0]) ) { - std::cout << "Error on sending I2C address" << std::endl; + std::cout << "Error on sending I2C address" << std::endl; } } else { ykush->print_help("ykush3"); @@ -109,7 +109,7 @@ int ykush3_cmd_parser(int argc, char** argv) std::cout << "Error on I2C writing" << std::endl; //... //ToDo: Have the handling of all error codes reported by the board firmware. - //... + //... } } else { std::cout << "I2C write command requires at least one byte of data to be sent." << std::endl; @@ -128,7 +128,7 @@ int ykush3_cmd_parser(int argc, char** argv) std::cout << "Error on I2C reading" << std::endl; //... //ToDo: Have the handling of all error codes reported by the board firmware. - //... + //... } } else { std::cout << "I2C write command requires at least one byte of data to be sent." << std::endl; @@ -165,7 +165,7 @@ int ykush3_cmd_parser(int argc, char** argv) std::string str = argv[2]; if ( str.compare( "-s" ) == 0 ) { //BY SERIAL - + if ( argc < 6 ) { ykush3.print_help(); return -1; @@ -176,41 +176,41 @@ int ykush3_cmd_parser(int argc, char** argv) if ( str.compare( "-u" ) == 0 ) { action = YKUSH3_PORT_UP; port = argv[5][0]; - + } else if ( str.compare( "-d" ) == 0 ) { - + action = YKUSH3_PORT_DOWN; port = argv[5][0]; - + } else if ( str.compare( "-g" ) == 0 ) { - + action = YKUSH3_GET_STATUS; port = argv[5][0]; - + } else if ( str.compare( "-on" ) == 0 ) { action = YKUSH3_EXT_CTRL_ON; } else if ( str.compare( "-off" ) == 0 ) { action = YKUSH3_EXT_CTRL_OFF; } else if ( str.compare( "-w" ) == 0 ) { - + if ( argc < 7 ) { ykush3.print_help(); return -1; } action = YKUSH3_WRITE_IO; port = argv[5][0]; - value = argv[6][0]; - - } else if ( str.compare( "-r" ) == 0 ) { - + value = argv[6][0]; + + } else if ( str.compare( "-r" ) == 0 ) { + action = YKUSH3_READ_IO; port = argv[5][0]; - - } else if ( str.compare( "-c" ) == 0 ) { + + } else if ( str.compare( "-c" ) == 0 ) { action = YKUSH3_CONFIG; port = argv[5][0]; value = argv[6][0]; - } else if ( str.compare( "--reset" ) == 0 ) { + } else if ( str.compare( "--reset" ) == 0 ) { action = YKUSH3_RESET; } else if ( str.compare( "--gpio" ) == 0 ) { std::string str2 = argv[5]; @@ -222,8 +222,8 @@ int ykush3_cmd_parser(int argc, char** argv) ykush3.print_help(); return -1; } - } else if ( str.compare( "--boot" ) == 0 ) { - action = YKUSH3_ENTER_BOOTLOADER; + } else if ( str.compare( "--boot" ) == 0 ) { + action = YKUSH3_ENTER_BOOTLOADER; } else { ykush3.print_help(); return -1; @@ -263,7 +263,7 @@ int ykush3_cmd_parser(int argc, char** argv) action = YKUSH3_WRITE_IO; port = argv[3][0]; value = argv[4][0]; - } else if ( str.compare( "-r" ) == 0 ) { + } else if ( str.compare( "-r" ) == 0 ) { action = YKUSH3_READ_IO; port = argv[3][0]; } else if ( str.compare( "-c" ) == 0 ) { @@ -276,7 +276,7 @@ int ykush3_cmd_parser(int argc, char** argv) value = argv[4][0]; } else if ( str.compare( "--reset" ) == 0 ) { action = YKUSH3_RESET; - } else if ( str.compare( "--boot" ) == 0 ) { + } else if ( str.compare( "--boot" ) == 0 ) { action = YKUSH3_ENTER_BOOTLOADER; } else if ( str.compare( "--gpio" ) == 0 ) { std::string str2 = argv[3]; @@ -296,19 +296,19 @@ int ykush3_cmd_parser(int argc, char** argv) switch ( action ) { case YKUSH3_PORT_UP: - if ( bySerialFlag ) - return ykush3.port_up(argv[3], port); + if ( bySerialFlag ) + return ykush3.port_up(argv[3], port); else - return ykush3.port_up(NULL, port); + return ykush3.port_up(NULL, port); break; case YKUSH3_PORT_DOWN: if ( bySerialFlag ) - return ykush3.port_down(argv[3], port); + return ykush3.port_down(argv[3], port); else - return ykush3.port_down(NULL, port); + return ykush3.port_down(NULL, port); break; case YKUSH3_LIST_BOARDS: - ykush3_list_attached(); + ykush3_list_attached(); break; case YKUSH3_GET_STATUS: if ( bySerialFlag ) { @@ -317,7 +317,7 @@ int ykush3_cmd_parser(int argc, char** argv) return status_response; if ( status_response >> 4 ) printf("\n\nDownstream port %d is ON\n\n", status_response & 0x0F ); - else + else printf("\n\nDownstream port %d is OFF\n\n", status_response & 0x0F); return 0; } else { @@ -326,108 +326,105 @@ int ykush3_cmd_parser(int argc, char** argv) return status_response; if ( status_response >> 4 ) printf("\n\nDownstream port %d is ON\n\n", status_response & 0x0F); - else + else printf("\n\nDownstream port %d is OFF\n\n", status_response & 0x0F); return 0; - } + } break; case YKUSH3_EXT_CTRL_ON: if ( bySerialFlag ) - return ykush3.port_up(argv[3], '4'); + return ykush3.port_up(argv[3], '4'); else - return ykush3.port_up(NULL, '4'); + return ykush3.port_up(NULL, '4'); break; case YKUSH3_EXT_CTRL_OFF: if ( bySerialFlag ) - return ykush3.port_down(argv[3], '4'); + return ykush3.port_down(argv[3], '4'); else - return ykush3.port_down(NULL, '4'); + return ykush3.port_down(NULL, '4'); break; case YKUSH3_WRITE_IO: if ( bySerialFlag ) - return ykush3.write_io(argv[3], port, value); + return ykush3.write_io(argv[3], port, value); else - return ykush3.write_io(NULL, port, value); + return ykush3.write_io(NULL, port, value); return 0; break; case YKUSH3_READ_IO: if ( bySerialFlag ) - printf("\n%d\n", ykush3.read_io(argv[3], port)); + printf("\n%d\n", ykush3.read_io(argv[3], port)); else - printf("\n%d\n", ykush3.read_io(NULL, port)); + printf("\n%d\n", ykush3.read_io(NULL, port)); return 0; break; case YKUSH3_CONFIG: if ( bySerialFlag ) - return ykush3.config_port(argv[3], port, value); + return ykush3.config_port(argv[3], port, value); else - return ykush3.config_port(NULL, port, value); + return ykush3.config_port(NULL, port, value); break; case YKUSH3_RESET: if ( bySerialFlag ) - return ykush3.reset(argv[3]); + return ykush3.reset(argv[3]); else - return ykush3.reset(NULL); + return ykush3.reset(NULL); break; case YKUSH3_GPIO_EN: if ( bySerialFlag ) - return ykush3.gpio_ctrl_enable(argv[3]); + return ykush3.gpio_ctrl_enable(argv[3]); else - return ykush3.gpio_ctrl_enable(NULL); + return ykush3.gpio_ctrl_enable(NULL); break; case YKUSH3_GPIO_DIS: if ( bySerialFlag ) - return ykush3.gpio_ctrl_disable(argv[3]); + return ykush3.gpio_ctrl_disable(argv[3]); else - return ykush3.gpio_ctrl_disable(NULL); + return ykush3.gpio_ctrl_disable(NULL); break; case YKUSH3_ENTER_BOOTLOADER: if ( bySerialFlag ) - return ykush3.enter_bootloader(argv[3]); + return ykush3.enter_bootloader(argv[3]); else return ykush3.enter_bootloader(NULL); break; default: ykush3.print_help(); - return -1; - break; + break; } - + return -1; } int Ykush3::port_up(char *serial, char port) -{ +{ switch(port) { case '1': hid_report_out[0] = 0x11; break; - case '2': + case '2': hid_report_out[0] = 0x12; break; - - case '3': + + case '3': hid_report_out[0] = 0x13; break; - case 'a': + case 'a': hid_report_out[0] = 0x1a; break; - case '4': + case '4': hid_report_out[0] = 0x14; break; default: return -1; - break; - } - - + + //send HID report to board return sendHidReport(serial, hid_report_out, hid_report_in, 64); @@ -443,31 +440,29 @@ int Ykush3::port_down(char *serial, char port) hid_report_out[0] = 0x01; break; - case '2': + case '2': hid_report_out[0] = 0x02; break; - - case '3': + + case '3': hid_report_out[0] = 0x03; break; - case 'a': + case 'a': hid_report_out[0] = 0x0a; break; - + case '4': hid_report_out[0] = 0x04; break; default: return 0; - break; - } - + //send HID report to board return sendHidReport(serial, hid_report_out, hid_report_in, 64); - + } @@ -475,7 +470,7 @@ int Ykush3::port_down(char *serial, char port) int Ykush3::get_port_status(char *serial, char port) { - int status; + int status; switch(port) { @@ -483,25 +478,23 @@ int Ykush3::get_port_status(char *serial, char port) hid_report_out[0] = 0x21; break; - case '2': + case '2': hid_report_out[0] = 0x22; break; - - case '3': + + case '3': hid_report_out[0] = 0x23; break; - case '4': + case '4': hid_report_out[0] = 0x24; break; default: return 0; - break; - } - - //send HID report to board + + //send HID report to board sendHidReport(serial, hid_report_out, hid_report_in, 64); //handle board response HID report @@ -517,9 +510,9 @@ int Ykush3::write_io(char *serial, char port, char value) hid_report_out[0] = 0x31; if(value=='0'){ - hid_report_out[2] = 0; + hid_report_out[2] = 0; } else { - hid_report_out[2] = 1; + hid_report_out[2] = 1; } @@ -529,20 +522,20 @@ int Ykush3::write_io(char *serial, char port, char value) hid_report_out[1] = 0x01; break; - case '2': + case '2': hid_report_out[1] = 0x02; break; - - case '3': + + case '3': hid_report_out[1] = 0x03; break; - + default: return 0; break; } - + //send HID report to board return sendHidReport(serial, hid_report_out, hid_report_in, 64); @@ -552,7 +545,7 @@ int Ykush3::write_io(char *serial, char port, char value) int Ykush3::read_io(char *serial, char port) { - + hid_report_out[0] = 0x30; switch(port) @@ -561,53 +554,53 @@ int Ykush3::read_io(char *serial, char port) hid_report_out[1] = 0x01; break; - case '2': + case '2': hid_report_out[1] = 0x02; break; - - case '3': + + case '3': hid_report_out[1] = 0x03; break; - + default: return 0; break; } - - + + //send HID report to board return sendHidReport(serial, hid_report_out, hid_report_in, 64); - + //process response return hid_report_in[3]; } - + int Ykush3::config_port(char *serial, char port, char value) { hid_report_out[0] = 0x41; if ( value == '0' ) - hid_report_out[2] = 0; + hid_report_out[2] = 0; else if ( value == '1' ) - hid_report_out[2] = 1; + hid_report_out[2] = 1; else hid_report_out[2] = 2; //Persist mode - + switch ( port ) { case '1': hid_report_out[1] = 0x01; break; - case '2': + case '2': hid_report_out[1] = 0x02; break; - case '3': + case '3': hid_report_out[1] = 0x03; break; - case 'e': + case 'e': hid_report_out[1] = 0x04; break; default: @@ -623,11 +616,10 @@ int Ykush3::config_port(char *serial, char port, char value) int Ykush3::reset(char *serial) { - hid_report_out[0] = 0x55; - + hid_report_out[0] = 0x55; + //send HID report to board - sendHidReport(serial, hid_report_out, hid_report_in, 64); - return 0; + return sendHidReport(serial, hid_report_out, hid_report_in, 64); } @@ -636,10 +628,9 @@ int Ykush3::gpio_ctrl_enable(char *serial) { hid_report_out[0] = 0x32; hid_report_out[1] = 0x01; - - //send HID report to board - sendHidReport(serial, hid_report_out, hid_report_in, 64); + //send HID report to board + return sendHidReport(serial, hid_report_out, hid_report_in, 64); } @@ -648,10 +639,9 @@ int Ykush3::gpio_ctrl_disable(char *serial) { hid_report_out[0] = 0x32; hid_report_out[1] = 0x00; - - //send HID report to board - sendHidReport(serial, hid_report_out, hid_report_in, 64); + //send HID report to board + return sendHidReport(serial, hid_report_out, hid_report_in, 64); } @@ -659,22 +649,21 @@ int Ykush3::gpio_ctrl_disable(char *serial) int Ykush3::enter_bootloader(char *serial) { hid_report_out[0] = 0x42; - - //send HID report to board - sendHidReport(serial, hid_report_out, hid_report_in, 64); + //send HID report to board + return sendHidReport(serial, hid_report_out, hid_report_in, 64); } -int Ykush3::i2c_enable_disable_control(bool enable_flag) +int Ykush3::i2c_enable_disable_control(bool enable_flag) { hid_report_out[0] = 0x51; hid_report_out[1] = 0x01; - + if ( enable_flag ) hid_report_out[2] = 0x01; - else + else hid_report_out[2] = 0x00; sendHidReport(usb_serial, hid_report_out, hid_report_in, 64); @@ -682,7 +671,7 @@ int Ykush3::i2c_enable_disable_control(bool enable_flag) if ( (hid_report_in[0] == 0x01) && (hid_report_in[1] == 0x51) ) { //command executed with success return 0; - } + } return 1; } @@ -695,7 +684,7 @@ int Ykush3::i2c_enable_disable_gateway(bool enable_flag) if ( enable_flag ) hid_report_out[2] = 0x01; - else + else hid_report_out[2] = 0x00; sendHidReport(usb_serial, hid_report_out, hid_report_in, 64); @@ -703,7 +692,7 @@ int Ykush3::i2c_enable_disable_gateway(bool enable_flag) if ( (hid_report_in[0] == 0x01) && (hid_report_in[1] == 0x51) ) { //command executed with success return 0; - } + } return 1; } @@ -741,7 +730,7 @@ int Ykush3::i2c_write(char *i2c_address_ASCII, char *num_bytes_ASCII, char **dat if ( size <= 0 ) return 1; dec2bin(num_bytes_ASCII, &hid_report_out[3], size); - if ( hid_report_out[3] > 60 ) + if ( hid_report_out[3] > 60 ) return 2; //convert data_to_write_ASCII to binary @@ -784,7 +773,7 @@ int Ykush3::i2c_read(char *i2c_address_ASCII, char *num_bytes_ASCII, unsigned ch for (i = 0; (i < hid_report_in[2]) && (i < 60); i++) { data_buffer[i] = hid_report_in[i + 4]; } - *bytes_read = i; + *bytes_read = i; } else { return 1; } @@ -799,17 +788,17 @@ int Ykush3::display_version_bootloader(void) hid_report_out[1] = 0x01; if ( sendHidReport(usb_serial, hid_report_out, hid_report_in, 64) != 0 ) { std::cout << "Unable to get bootloader version \n"; - return 1; + return 1; } //print response if ( ( hid_report_in[0] != 0x01 ) && ( hid_report_in[0] != 0x61 ) ) { std::cout << "Bootloader version-1.0.0\n"; - return 0; + return 0; } std::cout << "Bootloader version-" << hid_report_in[2] << "." << hid_report_in[3] << "." << hid_report_in[4]; return 0; } - + int Ykush3::display_version_firmware(void) { @@ -821,7 +810,7 @@ int Ykush3::display_version_firmware(void) std::cout << "Firmware version-1.0.0\n"; std::cout << "There is a new version of the firmware available for download in yepkit.com.\n"; std::cout << "Please consider updating the boot loader for unlocking the newest board features.\n"; - return 0; + return 0; } std::cout << "Bootloader version-" << hid_report_in[2] << "." << hid_report_in[3] << "." << hid_report_in[4]; return 0; @@ -829,18 +818,18 @@ int Ykush3::display_version_firmware(void) -int Ykush3::set_usb_serial(char *serial) +int Ykush3::set_usb_serial(char *serial) { usb_serial = serial; return 0; } - + int ykush3_list_attached() { Ykush3 ykush3; - printf("\n\nAttached YKUSH Boards:\n"); + printf("\n\nAttached YKUSH Boards:\n"); if( ykush3.listConnected() == 0 ) printf("\n\nNo YKUSH boards found."); printf("\n\n"); @@ -848,7 +837,7 @@ int ykush3_list_attached() } -void Ykush3::print_help(void) +void Ykush3::print_help(void) { Help help(app_exc_name); diff --git a/src/ykushxs/ykushxs.cpp b/src/ykushxs/ykushxs.cpp index 1b088d9..b559ed9 100644 --- a/src/ykushxs/ykushxs.cpp +++ b/src/ykushxs/ykushxs.cpp @@ -35,7 +35,7 @@ int ykushxs_cmd_parser(int argc, char** argv) char bySerialFlag = 0; enum ykushxsAction action = YKUSHXS_HELP; YkushXs ykushxs; - + if ( argc < 3 ) { ykushxs.ykushxs_help(argv[0]); return -1; @@ -84,7 +84,7 @@ int ykushxs_cmd_parser(int argc, char** argv) } break; case YKUSHXS_LIST_BOARDS: - return ykushxs_list_attached(); + return ykushxs_list_attached(); break; case YKUSHXS_GET_STATUS: if ( bySerialFlag ){ @@ -99,22 +99,20 @@ int ykushxs_cmd_parser(int argc, char** argv) } else { printf("\n\nDownstream port is OFF\n\n"); } - } + } break; default: - ykushxs.ykushxs_help(argv[0]); - return -1; + ykushxs.ykushxs_help(argv[0]); break; - } - + return -1; } int YkushXs::port_up(char *serial) { hid_report_out[0] = 0x11; //port up - + int res = sendHidReport(serial, hid_report_out, hid_report_in, 64); if ( res < 0 ) @@ -165,7 +163,7 @@ int ykushxs_list_attached() { YkushXs ykushxs; - printf("\n\nAttached YKUSH XS Boards:\n"); + printf("\n\nAttached YKUSH XS Boards:\n"); if ( ykushxs.listConnected() == 0 ) { printf("\nNo YKUSH XS boards found."); } From fed7322112e30477590b3d19490d19c826d50618 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:38:01 +0200 Subject: [PATCH 14/22] fix return value when printing help --- src/commandParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commandParser.cpp b/src/commandParser.cpp index 64edf9e..3a2500d 100644 --- a/src/commandParser.cpp +++ b/src/commandParser.cpp @@ -101,7 +101,7 @@ int commandParser(int argc, char** argv) return ykush_cmd_parser(argc - 1 , &argv[1]); else help.print_all(); - return -1; + return 0; } else { //YKUSH return ykush_cmd_parser(argc, argv); From 835af4aee54cf1f613164ed02ec1d7ea83775aca Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:40:15 +0200 Subject: [PATCH 15/22] fix makefile_win64 output --- .circleci/config.yml | 4 ++-- Makefile_win64 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2e56c50..d7691a5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,12 +55,12 @@ jobs: name: "Build" command: | make -f Makefile_win64 - cd bin/Win32; ykushcmd_win64.exe --help + bin/Win64/ykushcmd_win64.exe --help - store_artifacts: path: bin/Win64 destination: bin/win64 - store_artifacts: - path: bin/Win32/ykushcmd_win64.exe + path: bin/Win64/ykushcmd_win64.exe destination: bin/win64/ykushcmd.exe build-mac: macos: # indicate that we are using the macOS executor diff --git a/Makefile_win64 b/Makefile_win64 index 1f6a7fe..709afb7 100644 --- a/Makefile_win64 +++ b/Makefile_win64 @@ -28,7 +28,7 @@ CPP = x86_64-w64-mingw32-g++ ykushcmd_win64.exe : $(PROG_OBJ) $(OBJS) - $(CPP) $(FLAGS) $(LOADPATHS) -o bin/Win32/$@ $(PROG_OBJ) $(OBJS) $(LIBS) + $(CPP) $(FLAGS) $(LOADPATHS) -o bin/Win64/$@ $(PROG_OBJ) $(OBJS) $(LIBS) $(PROG_OBJ) : %.o : %.cpp $(CPP) $(FLAGS) $(PREPROCESSOR_DEFS) $(INCLUDEPATHS) -c $< -o $@ From 9ae8abc18317cae556d32f81b870d3fafe458ea3 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:43:24 +0200 Subject: [PATCH 16/22] re-fix help retcode --- src/commandParser.cpp | 2 +- src/ykush/ykush.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/commandParser.cpp b/src/commandParser.cpp index 3a2500d..64edf9e 100644 --- a/src/commandParser.cpp +++ b/src/commandParser.cpp @@ -101,7 +101,7 @@ int commandParser(int argc, char** argv) return ykush_cmd_parser(argc - 1 , &argv[1]); else help.print_all(); - return 0; + return -1; } else { //YKUSH return ykush_cmd_parser(argc, argv); diff --git a/src/ykush/ykush.cpp b/src/ykush/ykush.cpp index b78e2b6..35b615b 100644 --- a/src/ykush/ykush.cpp +++ b/src/ykush/ykush.cpp @@ -31,11 +31,11 @@ int ykush_cmd_parser(int argc, char** argv) char port; char status_response = 0; - + if((argv[1][0]=='-') && (argv[1][1]=='s')) { if(argc < 5) { ykush.print_help(argv[0]); - return -1; + return 0; } bySerialFlag = 1; if(argv[3][0]=='-' && argv[3][1]=='u') { @@ -109,7 +109,7 @@ int ykush_cmd_parser(int argc, char** argv) break; case YKUSH_LIST_BOARDS: - return ykush_list_attached(); + return ykush_list_attached(); break; case YKUSH_GET_STATUS: @@ -127,7 +127,7 @@ int ykush_cmd_parser(int argc, char** argv) } else { printf("\n\nDownstream port %d is OFF\n\n", status_response & 0x0F); } - } + } break; default: @@ -140,18 +140,18 @@ int ykush_cmd_parser(int argc, char** argv) int Ykush::port_up(char *serial, char port) -{ +{ switch(port) { case '1': hid_report_out[0] = 0x11; break; - case '2': + case '2': hid_report_out[0] = 0x12; break; - case '3': + case '3': hid_report_out[0] = 0x13; break; - case 'a': + case 'a': hid_report_out[0] = 0x1a; break; default: @@ -168,7 +168,7 @@ int Ykush::port_up(char *serial, char port) if ( res < 1 ) return res; - + if ( hid_report_in[0] == 0x01 ) return 0; return -1; @@ -182,13 +182,13 @@ int Ykush::port_down(char *serial, char port) case '1': hid_report_out[0] = 0x01; break; - case '2': + case '2': hid_report_out[0] = 0x02; break; - case '3': + case '3': hid_report_out[0] = 0x03; break; - case 'a': + case 'a': hid_report_out[0] = 0x0a; break; default: @@ -196,7 +196,7 @@ int Ykush::port_down(char *serial, char port) break; } - + int res; if(is_legacy) res = sendHidReport(serial, hid_report_out, hid_report_in, 6); @@ -205,7 +205,7 @@ int Ykush::port_down(char *serial, char port) if ( res < 1 ) return res; - + if ( hid_report_in[0] == 0x01 ) return 0; return -1; @@ -219,17 +219,17 @@ int Ykush::get_port_status(char *serial, char port) case '1': hid_report_out[0] = 0x21; break; - case '2': + case '2': hid_report_out[0] = 0x22; break; - case '3': + case '3': hid_report_out[0] = 0x23; break; default: return -1; break; } - + int res; if(is_legacy) res = sendHidReport(serial, hid_report_out, hid_report_in, 6); @@ -251,7 +251,7 @@ int ykush_list_attached() Ykush ykush( 0xF2F7 ); Ykush ykushLegacy( 0x0042 ); - printf("\nAttached YKUSH Boards:\n"); + printf("\nAttached YKUSH Boards:\n"); if( ykush.listConnected() == 0 ) { if( ykushLegacy.listConnected() == 0 ) { printf("\nNo YKUSH boards found."); From 718357547fbf5075d86fa4baef3f4332ef81780c Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 09:58:07 +0200 Subject: [PATCH 17/22] clean compiler warnings and treat warnings like error add -h option to print help succesfully --- .circleci/config.yml | 6 +++--- Makefile | 8 ++++---- libusb/libusb.h | 2 +- src/yk_usb_device.cpp | 35 ++++++++++++++++++----------------- src/yk_usb_device.h | 18 +++++++++--------- src/ykush/ykush.cpp | 6 ++++-- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d7691a5..609bdcc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ jobs: name: build command: | make - bin/ykushcmd --help + bin/ykushcmd -h - store_artifacts: path: bin/ykushcmd destination: bin/linux/ykushcmd @@ -55,7 +55,7 @@ jobs: name: "Build" command: | make -f Makefile_win64 - bin/Win64/ykushcmd_win64.exe --help + bin/Win64/ykushcmd_win64.exe -h - store_artifacts: path: bin/Win64 destination: bin/win64 @@ -74,7 +74,7 @@ jobs: name: build command: | make - bin/ykushcmd --help + bin/ykushcmd -h - store_artifacts: path: bin/ykushcmd destination: bin/macos/ykushcmd diff --git a/Makefile b/Makefile index 501f1d2..4b6fd85 100644 --- a/Makefile +++ b/Makefile @@ -19,14 +19,14 @@ PROG_OBJ = $(PROG_SOURCE_FULL:.cpp=.o) DEFINES += _LINUX_ DEFINES += _LIBUSB_ -COMPILE_FLAGS += $(addprefix -D, $(DEFINES)) +COMPILE_FLAGS += $(addprefix -D, $(DEFINES)) -Werror CUR_PATH = $(shell echo $(PWD)) INCLUDEPATHS = $(addprefix -I$(CUR_PATH)/, $(dir $(SOURCE_FULL)) libusb ) -LOADPATHS = +LOADPATHS = LIBS = -lusb-1.0 CPP = g++ - + ykushcmd : $(PROG_OBJ) $(OBJS) @@ -40,5 +40,5 @@ $(OBJS) : %.o : %.cpp %.h clean : - rm -f bin/yktrl $(OBJS) $(PROG_OBJ) + rm -f bin/ykushcmd $(OBJS) $(PROG_OBJ) diff --git a/libusb/libusb.h b/libusb/libusb.h index 8a6b0bf..45cb85b 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -1274,7 +1274,7 @@ enum libusb_capability { * still have to call additional libusb functions such as * \ref libusb_detach_kernel_driver(). */ LIBUSB_CAP_HAS_HID_ACCESS = 0x0100, - /** The library supports detaching of the default USB driver, using + /** The library supports detaching of the default USB driver, using * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */ LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101 }; diff --git a/src/yk_usb_device.cpp b/src/yk_usb_device.cpp index 9c3a57b..9c0ba00 100644 --- a/src/yk_usb_device.cpp +++ b/src/yk_usb_device.cpp @@ -29,7 +29,7 @@ limitations under the License. #ifdef _LIBUSB_ // Uses libusb directly -int UsbDevice::listConnected() +int UsbDevice::listConnected() { UsbHid *usbhid = new UsbHid(); struct hid_device_info *devs, *cur_dev; @@ -52,12 +52,12 @@ int UsbDevice::listConnected() } #else // Uses hidapi -int UsbDevice::listConnected() +int UsbDevice::listConnected() { int i=0; struct hid_device_info *devs, *cur_dev; - + devs = hid_enumerate(vid, pid); if (devs == NULL) return 0; @@ -65,10 +65,10 @@ int UsbDevice::listConnected() cur_dev = devs; while (cur_dev) { i++; - printf("%d. Board found with serial number: %ls\n", i, cur_dev->serial_number); + printf("%d. Board found with serial number: %ls\n", i, cur_dev->serial_number); cur_dev = cur_dev->next; } - + hid_free_enumeration(devs); return i; @@ -78,16 +78,17 @@ int UsbDevice::listConnected() UsbDevice::UsbDevice(unsigned int vendor_id, unsigned int product_id) { pid = product_id; vid = vendor_id; + usb_serial = NULL; } /** - * Sends HID report with the data provided in the input buffer "msg". + * Sends HID report with the data provided in the input buffer "msg". * * \param [in] serial Pointer to a char array containing the serial number. * \param [in] msg Pointer to buffer containing the HID report message to be sent to USB device. * \param [out] resp_msg Pointer to buffer to which the HID report message replied by the device. - * + * * \retval 0 No error. * \retval -1 Unable to open USB device. * \retval -2 Unable to write HID report to USB device. @@ -98,17 +99,17 @@ UsbDevice::UsbDevice(unsigned int vendor_id, unsigned int product_id) { * output. * * - * Precedences: + * Precedences: * * Requires that VENDOR_ID and PRODUCT_ID constants are defined. * * *****************************************************************/ #ifdef _LIBUSB_ -int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *resp_msg, int report_size) +int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *resp_msg, int report_size) { UsbHid *usbhid = new UsbHid(); - int res; + int res; res = usbhid->open(vid, pid, serial); if (res < 0) { @@ -133,8 +134,8 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re return 0; } #else -int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *resp_msg, int report_size) -{ +int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *resp_msg, int report_size) +{ const size_t newsize = 100; wchar_t cserial[newsize]; int res, i; @@ -144,13 +145,13 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re if (report_size <= 64) { out_buf[0] = 0; for (i = 0; i < report_size; i++) { - out_buf[i+1] = msg[i]; + out_buf[i+1] = msg[i]; } } else { std::cout << "Invalid report size\n"; return -1; } - + if (serial) { // Convert to a wchar_t* size_t origsize = strlen(serial) + 1; @@ -160,9 +161,9 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re } - // Open the USB device + // Open the USB device handle = hid_open(vid, pid, serial ? cserial : NULL); - + if (handle == NULL) { //printf("\n\nERROR: Unable to open USB device\n"); return -1; @@ -188,7 +189,7 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re resp_msg[i] = in_buf[i]; } - return 0; + return 0; } #endif diff --git a/src/yk_usb_device.h b/src/yk_usb_device.h index a689111..9312704 100644 --- a/src/yk_usb_device.h +++ b/src/yk_usb_device.h @@ -33,7 +33,7 @@ limitations under the License. /** * \ingroup yepkit_usb_device_handler - * + * * \brief Handles the USB HID for a given PID and VID. */ class UsbDevice { @@ -45,15 +45,15 @@ class UsbDevice { /** * Prints to standard output the list of connected devices with PID a VID provided in the class constructor. - * + * * \return Number of attached devices. */ int listConnected(void); //List connected devices private: - unsigned short vid; - unsigned short pid; + unsigned short vid; + unsigned short pid; #ifndef _LIBUSB_ hid_device *handle; #endif @@ -62,12 +62,12 @@ class UsbDevice { unsigned char hid_report_out[64]; unsigned char hid_report_in[64]; - char *usb_serial = NULL; + char *usb_serial; }; /***************************************************************** - * Function: + * Function: * * send_usb_msg * @@ -75,7 +75,7 @@ class UsbDevice { * Description: * * Sends HID report with the data provided in the input buffer - * "msg". + * "msg". * * * Inputs: @@ -97,13 +97,13 @@ class UsbDevice { * output. * * - * Precedences: + * Precedences: * * Requires that VENDOR_ID and PRODUCT_ID constants are defined. * * *****************************************************************/ -int send_usb_msg(char *serial, char *msg, char *resp_msg); +int send_usb_msg(char *serial, char *msg, char *resp_msg); char commands(char *cmd, char *resp, int num); char command(char cmd); char commandsBySerial(char *iSerial, char *cmd, char *resp, int num); diff --git a/src/ykush/ykush.cpp b/src/ykush/ykush.cpp index 35b615b..6c96332 100644 --- a/src/ykush/ykush.cpp +++ b/src/ykush/ykush.cpp @@ -31,7 +31,10 @@ int ykush_cmd_parser(int argc, char** argv) char port; char status_response = 0; - + if((argv[1][0]=='-') && (argv[1][1]=='h')) { + ykush.print_help(argv[0]); + return 0; + } if((argv[1][0]=='-') && (argv[1][1]=='s')) { if(argc < 5) { ykush.print_help(argv[0]); @@ -133,7 +136,6 @@ int ykush_cmd_parser(int argc, char** argv) default: ykush.print_help(argv[0]); return -1; - break; } return 0; } From 9d38307927113948baddcf5cbf78b6b22033ebb2 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 10:05:42 +0200 Subject: [PATCH 18/22] build win32 --- .circleci/config.yml | 18 +++++++++++++++--- Makefile_win32 | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 609bdcc..133a918 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,16 +52,28 @@ jobs: name: "Install deps" command: choco install mingw make - run: - name: "Build" + name: "Build 64" command: | make -f Makefile_win64 bin/Win64/ykushcmd_win64.exe -h - store_artifacts: - path: bin/Win64 - destination: bin/win64 + path: bin/Win64/libhidapi.dll + destination: bin/win64/libhidapi.dll - store_artifacts: path: bin/Win64/ykushcmd_win64.exe destination: bin/win64/ykushcmd.exe + + - run: + name: "Build 32" + command: | + make -f Makefile_win32 + bin/Win32/ykushcmd_win32.exe -h + - store_artifacts: + path: bin/Win32/libhidapi.dll + destination: bin/win32/libhidapi.dll + - store_artifacts: + path: bin/Win32/ykushcmd_win32.exe + destination: bin/win32/ykushcmd.exe build-mac: macos: # indicate that we are using the macOS executor xcode: "10.0.0" # indicate our selected version of Xcode diff --git a/Makefile_win32 b/Makefile_win32 index ddc252d..18775f1 100644 --- a/Makefile_win32 +++ b/Makefile_win32 @@ -23,8 +23,8 @@ FLAGS = -static-libgcc -static-libstdc++ #Change MinGW exec name to match version instaled in your system CPP = i686-w64-mingw32-g++ -#CPP_WIN32 = i686-w64-mingw32-g++ -#CPP_WIN64 = x86_64-w64-mingw32-g++ +#CPP_WIN32 = i686-w64-mingw32-g++ +#CPP_WIN64 = x86_64-w64-mingw32-g++ ykushcmd_win32.exe : $(PROG_OBJ) $(OBJS) @@ -38,5 +38,5 @@ $(OBJS) : %.o : %.cpp %.h clean : - rm -f bin/Win32/yktrl_win32.exe $(OBJS) $(PROG_OBJ) + rm -f bin/Win32/ykushcmd_win32.exe $(OBJS) $(PROG_OBJ) From 554b185bbede9daea2316f123cd93ed7221a9e52 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 10:11:18 +0200 Subject: [PATCH 19/22] fix ci script --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 133a918..5275140 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -71,9 +71,9 @@ jobs: - store_artifacts: path: bin/Win32/libhidapi.dll destination: bin/win32/libhidapi.dll - - store_artifacts: - path: bin/Win32/ykushcmd_win32.exe - destination: bin/win32/ykushcmd.exe + - store_artifacts: + path: bin/Win32/ykushcmd_win32.exe + destination: bin/win32/ykushcmd.exe build-mac: macos: # indicate that we are using the macOS executor xcode: "10.0.0" # indicate our selected version of Xcode From b310a6a7e5c9c412a1b06aedd39f56257acba630 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 10:20:26 +0200 Subject: [PATCH 20/22] comment out win32 build for now. --- .circleci/config.yml | 24 ++++++++++++------------ Makefile_win64 | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5275140..56dc0af 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,18 +62,18 @@ jobs: - store_artifacts: path: bin/Win64/ykushcmd_win64.exe destination: bin/win64/ykushcmd.exe - - - run: - name: "Build 32" - command: | - make -f Makefile_win32 - bin/Win32/ykushcmd_win32.exe -h - - store_artifacts: - path: bin/Win32/libhidapi.dll - destination: bin/win32/libhidapi.dll - - store_artifacts: - path: bin/Win32/ykushcmd_win32.exe - destination: bin/win32/ykushcmd.exe + # should install mingw32 + #- run: + # name: "Build 32" + # command: | + # make -f Makefile_win32 + # bin/Win32/ykushcmd_win32.exe -h + #- store_artifacts: + # path: bin/Win32/libhidapi.dll + # destination: bin/win32/libhidapi.dll + #- store_artifacts: + # path: bin/Win32/ykushcmd_win32.exe + # destination: bin/win32/ykushcmd.exe build-mac: macos: # indicate that we are using the macOS executor xcode: "10.0.0" # indicate our selected version of Xcode diff --git a/Makefile_win64 b/Makefile_win64 index 709afb7..67f2e6e 100644 --- a/Makefile_win64 +++ b/Makefile_win64 @@ -38,5 +38,5 @@ $(OBJS) : %.o : %.cpp %.h clean : - rm -f bin/Win64/yktrl_win32.exe $(OBJS) $(PROG_OBJ) + rm -f bin/Win64/ykushcmd_win64.exe $(OBJS) $(PROG_OBJ) From 7201bfc7ce9e1ce4f8993d69930f9f6871b81b53 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sat, 23 Nov 2019 10:29:01 +0200 Subject: [PATCH 21/22] revert retcode for invalid command usage --- src/ykush/ykush.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ykush/ykush.cpp b/src/ykush/ykush.cpp index 6c96332..e31a2d6 100644 --- a/src/ykush/ykush.cpp +++ b/src/ykush/ykush.cpp @@ -38,7 +38,7 @@ int ykush_cmd_parser(int argc, char** argv) if((argv[1][0]=='-') && (argv[1][1]=='s')) { if(argc < 5) { ykush.print_help(argv[0]); - return 0; + return -1; } bySerialFlag = 1; if(argv[3][0]=='-' && argv[3][1]=='u') { From 7da29f14a9aeebfbf75d7accbd85bd6cc3c1d6d7 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Wed, 11 Mar 2020 16:49:03 +0200 Subject: [PATCH 22/22] drop Mac build since don't have paid circleci --- .circleci/config.yml | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 56dc0af..4744464 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,6 @@ version: 2.1 orbs: win: circleci/windows@1.0.0 - workflows: version: 2 builds: @@ -16,10 +15,10 @@ workflows: filters: # required since `deploy` has tag filters AND requires `build` tags: only: /.*/ - - build-mac: - filters: # required since `deploy` has tag filters AND requires `build` - tags: - only: /.*/ + #- build-mac: + # filters: # required since `deploy` has tag filters AND requires `build` + # tags: + # only: /.*/ jobs: build-linux: @@ -74,19 +73,19 @@ jobs: #- store_artifacts: # path: bin/Win32/ykushcmd_win32.exe # destination: bin/win32/ykushcmd.exe - build-mac: - macos: # indicate that we are using the macOS executor - xcode: "10.0.0" # indicate our selected version of Xcode - steps: - - checkout - - run: - name: install deps - command: brew install gcc make libhid - - run: - name: build - command: | - make - bin/ykushcmd -h - - store_artifacts: - path: bin/ykushcmd - destination: bin/macos/ykushcmd + #build-mac: + # macos: # indicate that we are using the macOS executor + # xcode: "10.0.0" # indicate our selected version of Xcode + # steps: + # - checkout + # - run: + # name: install deps + # command: brew install gcc make libhid + # - run: + # name: build + # command: | + # make + # bin/ykushcmd -h + # - store_artifacts: + # path: bin/ykushcmd + # destination: bin/macos/ykushcmd