-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 51cf9ae
Showing
14 changed files
with
4,577 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=binary | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
*.vcxproj | ||
*.sln | ||
*.vcxproj.filters | ||
|
||
CMakeCache.txt | ||
CMakeFiles | ||
CMakeScripts | ||
Testing | ||
Makefile | ||
cmake_install.cmake | ||
install_manifest.txt | ||
compile_commands.json | ||
CTestTestfile.cmake | ||
|
||
/Debug/ | ||
/Release/ | ||
/RelWithDebInfo/ | ||
/MinSizeRel/ | ||
/Win32/ | ||
/x64/ | ||
|
||
/usbclient.dir/ | ||
|
||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
## | ||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# User-specific files (MonoDevelop/Xamarin Studio) | ||
*.userprefs | ||
|
||
# Visual Studio 2015 cache/options directory | ||
.vs/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
# NUNIT | ||
*.VisualState.xml | ||
TestResult.xml | ||
|
||
# Build Results of an ATL Project | ||
[Dd]ebugPS/ | ||
[Rr]eleasePS/ | ||
dlldata.c | ||
|
||
# Benchmark Results | ||
BenchmarkDotNet.Artifacts/ | ||
|
||
# .NET Core | ||
project.lock.json | ||
project.fragment.lock.json | ||
artifacts/ | ||
**/Properties/launchSettings.json | ||
|
||
*_i.c | ||
*_p.c | ||
*_i.h | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.svclog | ||
*.scc | ||
|
||
# Chutzpah Test files | ||
_Chutzpah* | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opendb | ||
*.opensdf | ||
*.sdf | ||
*.cachefile | ||
*.VC.db | ||
*.VC.VC.opendb | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
*.sap | ||
|
||
# Visual Studio Trace Files | ||
*.e2e | ||
|
||
# Visual Studio code coverage results | ||
*.coverage | ||
*.coveragexml | ||
|
||
# Click-Once directory | ||
publish/ | ||
|
||
# Visual Studio cache files | ||
# files ending in .cache can be ignored | ||
*.[Cc]ache | ||
# but keep track of directories ending in .cache | ||
!*.[Cc]ache/ | ||
|
||
# Others | ||
ClientBin/ | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.dbproj.schemaview | ||
*.jfm | ||
*.pfx | ||
*.publishsettings | ||
orleans.codegen.cs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright (c) 2017, Niklas Gürtler | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
# following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
# disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
# following disclaimer in the documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
|
||
project(usbclient) | ||
|
||
if(MSVC) | ||
set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1 /MP /W4") | ||
set(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D DNDEBUG /MP /W4") | ||
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D DNDEBUG /MP /W4") | ||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /Zi /O2 /Ob1 /D DNDEBUG /MP /W4") | ||
endif() | ||
if(CMAKE_COMPILER_IS_GNUCXX) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -ffunction-sections -fdata-sections") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pthread") | ||
|
||
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -flto") | ||
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -s -flto") | ||
|
||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto") | ||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto") | ||
endif() | ||
|
||
set (USE_PKG_CONFIG "false") | ||
|
||
find_package(PkgConfig) | ||
if(PKG_CONFIG_FOUND) | ||
pkg_check_modules(LIBUSB libusb-1.0>=1.0.20) | ||
if(LIBUSB_FOUND) | ||
set (USE_PKG_CONFIG "true") | ||
endif() | ||
endif() | ||
|
||
if(NOT USE_PKG_CONFIG) | ||
if(MSVC) | ||
if (${CMAKE_SIZEOF_VOID_P} EQUAL "8") | ||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:libusb-msvc\\MS64\\dll") | ||
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LIBPATH:libusb-msvc\\MS64\\dll") | ||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /LIBPATH:libusb-msvc\\MS64\\static") | ||
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG /LIBPATH:libusb-msvc\\MS64\\static") | ||
|
||
set(CMAKE_MSVCIDE_RUN_PATH "libusb-msvc\\MS64\\dll") | ||
else() | ||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:libusb-msvc\\MS32\\dll") | ||
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LIBPATH:libusb-msvc\\MS32\\dll") | ||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /LIBPATH:libusb-msvc\\MS32\\static") | ||
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG /LIBPATH:libusb-msvc\\MS32\\static") | ||
|
||
set(CMAKE_MSVCIDE_RUN_PATH "libusb-msvc\\MS32\\dll") | ||
endif() | ||
else() | ||
message(STATUS "LIBUSB not found!") | ||
endif() | ||
endif() | ||
|
||
add_executable(usbclient src/main.cc) | ||
set_property(TARGET usbclient PROPERTY CXX_STANDARD 11) | ||
|
||
if(USE_PKG_CONFIG) | ||
include_directories(${LIBUSB_INCLUDE_DIRS}) | ||
target_link_libraries(usbclient ${LIBUSB_LDFLAGS}) | ||
target_include_directories(usbclient PUBLIC ${usbclient_INCLUDE_DIRS}) | ||
target_compile_options(usbclient PUBLIC ${usbclient_CFLAGS_OTHER}) | ||
else() | ||
include_directories("libusb-msvc\\include\\libusb-1.0") | ||
target_link_libraries(usbclient "libusb-1.0.lib") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2017, Niklas Gürtler | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# usbclient | ||
Dies ist ein simples PC-Programm zur Ansteuerung des USB-Gerätes welches im Projekt [f1usb](https://github.com/Erlkoenig90/f1usb) entwickelt wurde. Es basiert auf [libusb](http://libusb.info) und funktioniert unter Linux und Windows. Auf der [Releases](https://github.com/Erlkoenig90/usbclient/releases)-Seite können fertig kompilierte Dateien heruntergeladen werden. | ||
|
||
## Kompilieren | ||
Das Projekt nutzt [CMake](https://cmake.org/) als Build-System. Unter Linux kann es so kompiliert werden: | ||
```shell | ||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release | ||
make | ||
``` | ||
Statt "Release" kann auch "Debug" angegeben werden um Optimierungen aus- und Debuginformationen einzuschalten. | ||
|
||
Unter Windows kann mit CMake ein Visual Studio-Projekt für 64bit erzeugt werden: | ||
```shell | ||
cmake -G "Visual Studio 15 2017 Win64" | ||
``` | ||
Alternativ für 32bit: | ||
```shell | ||
cmake -G "Visual Studio 15 2017" | ||
``` | ||
|
||
Das Visual Studio-Projekt enthält vier Konfigurationen: | ||
|
||
Name | Beschreibung | ||
-----|------------- | ||
Debug | Unoptimierte Debug-Version, dynamisch gelinkt (libusb-DLL wird zur Ausführung gebraucht) | ||
Release | Optimiertes Programm mit statisch gelinkten Bibliotheken (keine DLLs benötigt) | ||
MinSizeRel | Auf Größe optimiertes Programm mit dynamisch gelinkten Bibliotheken (libusb-DLL wird zur Ausführung gebraucht) | ||
RelWithDebInfo | Wie Release, mit Debug-Informationen | ||
|
||
Unter Linux wird pkg-config genutzt, um libusb zu finden, welches per Paketmanager installiert werden muss. Für Windows enthält das Projekt fertig kompilierte Binaries im "libusb-msvc"-Verzeichnis, die automatisch mit gelinkt werden. Diese wurden mit und für Visual Studio 15 2017 erstellt. Für ältere Versionen können die Bibliotheksdateien von der libusb-Website heruntergeladen werden. Die statische Version davon funktioniert dann aber nicht mit der aktuellen Visual Studio-Version. | ||
|
||
## Funktion | ||
Das Programm greift via libusb direkt auf ein am PC angeschlossenes Gerät zu, welches mit dem "USB-Hello-World" [f1usb](https://github.com/Erlkoenig90/f1usb) erstellt sein sollte. Es zeigt zunächst die Adressen und ID's aller angeschlossenen Geräte an, öffnet falls möglich das mit der passenden ID, und zeigt dessen String-Deskriptoren an. Es fragt den aktuellen Zustand der LED's ab, und erlaubt das Setzen der LED's auf die über zwei Kommandozeilen-Argumente anzugebenden Zustände, welche 1 oder 0 sein müssen. Außerdem sendet es eine zufällige Folge an Bytes an den Bulk Endpoint 1, empfängt die gleich lange Antwort, zeigt beide an und prüft, ob in der Antwort wie gewünscht jedes Byte umgedreht wurde. Ein Beispiel-Lauf des Programms ist (gekürzt): | ||
```shell | ||
$ ./usbclient 0 1 | ||
Angeschlossene Geräte: | ||
2:8:5 04f2:b336 | ||
2:5:9 04ca:300b | ||
2:2:10 dead:beef | ||
2:4:6 046d:0a1f | ||
[...] | ||
Manufacturer: ACME Corp. | ||
Product: Fluxkompensator | ||
Serial: 42-1337-47/11 | ||
LED1: 1 | ||
LED2: 0 | ||
Sende Daten : de, c8, 1d, a0, 7b, 33, 65, f0 [...] | ||
Empfangene Daten: 7b, 13, b8, 05, de, cc, a6, 0f [...] | ||
Daten stimmen überein: true | ||
``` | ||
|
||
## Lizenz | ||
Dieser Code steht unter der BSD-Lizenz, siehe dazu die Datei [LICENSE](LICENSE). |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.