Update docs, add scripts and tests
authorAndrew 'Necromant' Andrianov <andrew@ncrmnt.org>
Sat, 14 Feb 2015 10:03:02 +0000 (13:03 +0300)
committerAndrew 'Necromant' Andrianov <andrew@ncrmnt.org>
Sat, 14 Feb 2015 10:03:02 +0000 (13:03 +0300)
Signed-off-by: Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>
.gitignore [new file with mode: 0644]
10-pl2303_cp210x_userspace.rules [new file with mode: 0755]
10-pl2303userspace.rules [deleted file]
Makefile
README.md
etc/serverd.conf [new file with mode: 0644]
extra/serverctl
extra/serverd.lua
tests/blink.sh [new file with mode: 0755]
tests/kitt.sh [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..bcc7e17
--- /dev/null
@@ -0,0 +1,5 @@
+*~
+*.o
+cp2103gpio
+pl3203gpio
+
diff --git a/10-pl2303_cp210x_userspace.rules b/10-pl2303_cp210x_userspace.rules
new file mode 100755 (executable)
index 0000000..15fb336
--- /dev/null
@@ -0,0 +1,5 @@
+# PL2303 rules to allow userspace access to the dongle
+# Copy this file to /etc/udev/rules.d, reload udev rules and replug
+
+SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="67b",  ATTR{idProduct}=="2303", GROUP="users", MODE="0666"
+SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="10c4", ATTR{idProduct}=="ea60", GROUP="users", MODE="0666"
diff --git a/10-pl2303userspace.rules b/10-pl2303userspace.rules
deleted file mode 100755 (executable)
index 15fb336..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# PL2303 rules to allow userspace access to the dongle
-# Copy this file to /etc/udev/rules.d, reload udev rules and replug
-
-SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="67b",  ATTR{idProduct}=="2303", GROUP="users", MODE="0666"
-SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="10c4", ATTR{idProduct}=="ea60", GROUP="users", MODE="0666"
index 1fa1faa..f008d56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,4 +18,12 @@ clean:
 install: pl2303gpio cp2103gpio
        cp pl2303gpio $(PREFIX)/bin
        cp cp2103gpio $(PREFIX)/bin
-       cp 10-pl2303userspace.rules /etc/udev/rules.d
+
+install-rules: 
+       cp 10-pl2303_cp210x_userspace.rules /etc/udev/rules.d
+       udevadm control --reload-rules
+
+install-scripts:
+       cp extra/serverctl   $(PREFIX)/bin/
+       cp extra/serverd.lua $(PREFIX)/bin/
+       cp etc/serverd.conf  $(PREFIX)/etc/
index 112efa8..a5f6e77 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,14 +1,16 @@
-# PL2303 Userspace GPIO control tool
+# PL2303 and CP2103 Userspace GPIO control tools
+
+This is a set of small tools for linux userspace that allows you to interact
+with GPIO lines on PL2303HX and CP2103 devices. 
+PL2303: It has only been tested on PL2303HXA, but may work for other revisions. 
+CP2103: It has only been tested on CP2103, but may work for other revisions/versions.
 
-This is a small tool for linux userspace that allows you to interact
-with GPIO lines on PL2303HX devices. 
-It has only been tested on PL2303HXA, but may work for other revisions. 
 Since no common GPIO driver for those exists at the time of writing in
 the linux kernel - this should serve as a placeholder till upstream guys 
-fix that.  
+fix that. 
 
 
-## Compiling & installing
+# Compiling & installing
 
 You'll need libusb-1.0-dev, gcc and pkg-config. Just run 
 
@@ -16,10 +18,19 @@ You'll need libusb-1.0-dev, gcc and pkg-config. Just run
 make 
 sudo make install
 ```
+##Installing udev rules (Linux only)
 
-pl2303gpio comes with udev rules that will be dropped into your
+This package comes with udev rules that will be dropped into your
 /etc/udev/rules.d/
-Just reload udev after installing it
+
+To automagically install and reload rules run
+
+```
+sudo make install-rules
+```
+
+and replug your pl2303/cp2103 dongles. You should no longer need root
+permissions to access gpio in them. 
 
 ## Do I have to close minicom / rmmod pl2303 to use this tool ? 
 
@@ -27,25 +38,91 @@ Nope. Just run it in a separate terminal whenever you need it
 
 ## Can I chose which of 70 PL2303 devices plugged this will work with?
 
-Nope, you can't. Patches welcome. 
+Yep. You can specify --product, --serial and --manuf strings to match
+the device you want. 
+These must _precede_ any other options. Example: 
 
-## Using
+```
+./cp2303gpio --product=PowerUART --serial=fireblade --gpio 0 --out 1
+```
 
+## Usage
+
+CP2103
 ```
-pl2303gpio --help
-PL2303HXA userspace GPIO control tool
+PL2303HXA/CP2103 userspace GPIO control tool
+(c) Andrew 'Necromant' Andrianov 2014, License: GPLv3
+Usage: ./cp2103gpio [action1] [action2] ...
+Options are: 
+         --product=blah    - Use device with this 'product' string
+         --serial=blah     - Use device with this 'serial' string
+         --manuf=blah      - Use device with this 'manufacturer' string
+         -g/--gpio  n      - select GPIO, n=0, 1
+         -i/--in           - configure GPIO as input
+         -o/--out v        - configure GPIO as output with value v
+         -r/--read v       - Read current GPIO value
+
+         -s/--sleep v      - Delay for v ms
+
+Examples: 
+        ./cp2103gpio --gpio=1 --out 1
+        ./cp2103gpio --gpio=0 --out 0 --gpio=1 --in
+
+All arguments are executed from left to right, you can add 
+delays using --sleep v option. e.g. 
+        ./cp2103gpio --gpio=0 --out 0 --sleep 1000 --gpio=0 --out 1
+```
+
+PL2303
+```
+PL2303HXA/CP2103 userspace GPIO control tool
 (c) Andrew 'Necromant' Andrianov 2014, License: GPLv3
 Usage: ./pl2303gpio [action1] [action2] ...
 Options are: 
-         -g/--gpio  n  - select GPIO, n=0, 1
-         -i/--in       - configure GPIO as input
-         -o/--out v    - configure GPIO as output with value v
-         -r/--read v   - Read current GPIO value
+         --product=blah    - Use device with this 'product' string
+         --serial=blah     - Use device with this 'serial' string
+         --manuf=blah      - Use device with this 'manufacturer' string
+         -g/--gpio  n      - select GPIO, n=0, 1
+         -i/--in           - configure GPIO as input
+         -o/--out v        - configure GPIO as output with value v
+         -r/--read v       - Read current GPIO value
+
+         -s/--sleep v      - Delay for v ms
 
 Examples: 
         ./pl2303gpio --gpio=1 --out 1
         ./pl2303gpio --gpio=0 --out 0 --gpio=1 --in
+
+All arguments are executed from left to right, you can add 
+delays using --sleep v option. e.g. 
+        ./pl2303gpio --gpio=0 --out 0 --sleep 1000 --gpio=0 --out 1
+```
+
+## Limitations
+cp2303 code misses magic required for 'input' mode of GPIO lines. 
+
+## Tips and tricks
+The arguments are executed from left to right. Therefore you can use only one 
+call to pl2303gpio/cp2303gpio to execute a sequence of actions. If the gpio line 
+stays the same, you can omit subsequent --gpio arguments. 
+You can use --sleep to add arbitary delays (in milliseconds)
+
+Example (sets the gpio3 line to 1, sleeps for one second, sets the gpio3 to 0: 
 ```
+./cp2303gpio --gpio=3 --out=1 --sleep=1000 --out=0
+```
+
+##Bonus scripts
+The 'extra' directory contains a few scripts I use on my OpenWRT box to manage a few
+SBC servers. They are installed via install-scripts. 
+
+serverctl - is a bach script that allows quickly to power on/power off/reboot/access minicom on any of the boxes by just supplying the hostname (which is also wired into cp2303 onboard eeprom as 'serial number').  
+serverd   - is a lua daemon that pings servers in round-robin fasion and displays their state on LEDs 
+
+## Mac OS X hint
+These tools have been reported to work on Mac OS X. For obvious reasons you
+don't need udev rules on a mac. 
+
 
 ## License
 
diff --git a/etc/serverd.conf b/etc/serverd.conf
new file mode 100644 (file)
index 0000000..a571ade
--- /dev/null
@@ -0,0 +1,8 @@
+hosts = { 
+   {"192.168.0.1",  "windblade"},
+   {"192.168.0.20", "iceblade"},
+}
+
+sleep_interval=1
+
+
index cb6dd9f..1d756bf 100755 (executable)
@@ -51,7 +51,7 @@ case $action in
        shift
        miniargs=$*
        [ -z "$*" ] && miniargs="-b 115200"
-       tty=/dev/`list_servers|cut -d";" -f3`
+       tty=/dev/`list_servers|grep $node|cut -d";" -f3`
        minicom -o -D $tty $miniargs
        ;;
     *)
@@ -60,8 +60,8 @@ case $action in
        echo "Valid actions are: "
        echo "                   list"
        echo "                   reboot"
-       echo "                   shutdown"
-       echo "                   poweron"
+       echo "                   on"
+       echo "                   off"
        echo "                   term"
        ;;
 esac
index 5d61408..3946c35 100644 (file)
@@ -1,14 +1,7 @@
 #!/usr/bin/lua
 
-
---TODO: host.conf
-hosts = { 
-   {"192.168.0.1", "windblade"},
-   {"192.168.0.20", "iceblade"},
-}
-sleep_interval=1
-
---dofile("/etc/serverd.conf")
+-- Read the config
+dofile("/etc/serverd.conf")
 
 function gpio(host, n,o)
    local str="cp2103gpio --serial="..host.." --gpio="..n.." --out="..o
diff --git a/tests/blink.sh b/tests/blink.sh
new file mode 100755 (executable)
index 0000000..e2b99b4
--- /dev/null
@@ -0,0 +1,10 @@
+while true; do 
+sudo ./cp2103gpio --gpio=0 --out 0
+sleep 0.3
+sudo ./cp2103gpio --gpio=0 --out 1
+sleep 0.3
+sudo ./cp2103gpio --gpio=0 --out 0
+sleep 0.3
+sudo ./cp2103gpio --gpio=0 --out 1
+sleep 1
+done
diff --git a/tests/kitt.sh b/tests/kitt.sh
new file mode 100755 (executable)
index 0000000..6523249
--- /dev/null
@@ -0,0 +1,11 @@
+while true; do 
+./cp2103gpio --gpio=0 --out 1 --gpio 1 --out 0 --sleep 300
+./cp2103gpio --gpio=1 --out 1 --gpio 2 --out 0 --sleep 300
+./cp2103gpio --gpio=2 --out 1 --gpio 1 --out 0 --sleep 300
+./cp2103gpio --gpio=1 --out 1 --gpio 0 --out 0 --sleep 300
+
+
+
+
+
+done