aboutsummaryrefslogtreecommitdiff
path: root/tools/hex.sh
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-08-05 16:21:34 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-08-05 16:21:34 +1200
commitee9ee82211684ee3de6dc9b3425411fdb28fbdb3 (patch)
tree04c52c85f0611d5a322ce9f47defb86efee5fdba /tools/hex.sh
parentc790266c87a165d1fc5b2ef3b13a07ec692f5f54 (diff)
downloadtrackermap-server-ee9ee82211684ee3de6dc9b3425411fdb28fbdb3.tar.gz
trackermap-server-ee9ee82211684ee3de6dc9b3425411fdb28fbdb3.tar.bz2
trackermap-server-ee9ee82211684ee3de6dc9b3425411fdb28fbdb3.zip
Update test scripts in tools
Diffstat (limited to 'tools/hex.sh')
-rwxr-xr-xtools/hex.sh35
1 files changed, 28 insertions, 7 deletions
diff --git a/tools/hex.sh b/tools/hex.sh
index 2a7b55901..cd880e13e 100755
--- a/tools/hex.sh
+++ b/tools/hex.sh
@@ -1,14 +1,35 @@
#!/bin/sh
#
-# This test data assumes device "352964051908664" exists.
+# Script to send convert HEX string into binary and send it to specified local port
#
-# INSERT INTO device ( name, uniqueid )
-# VALUES ( 'Test Device for hex.sh', 352964051908664 );
+# Example usage:
#
-# Note: Not all shells support "echo -e" (e.g., dash - default on Ubuntu).
-# This will cause an unknown device error for "-e".
+# hex.sh 5039 3e52505631393535352b343533383431382d303733393531383530303032303231323b49443d393939393b2a37423c0d0a
#
-echo 3e52505631393535352b343533383431382d303733393531383530303032303231323b49443d393939393b2a37423c0d0a | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie' | nc -v -w 10 localhost 5039
-#echo 3e52505631393535352b343533383431382d303733393531383530303032303231323b49443d393939393b2a37423c0d0a | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie' > /dev/udp/localhost/5057
+if [[ $# -lt 2 ]]
+then
+ echo "USAGE: $0 <port> <hex>"
+ exit 1
+fi
+
+send_hex_udp () {
+ echo $2 | xxd -r -p | nc -u localhost $1
+}
+
+send_hex_tcp () {
+ echo $2 | xxd -r -p | nc localhost $1
+}
+
+send_text_udp () {
+ echo -n -e $2 | nc -u localhost $1
+}
+
+send_text_tcp () {
+ echo -n -e $2 | nc localhost $1
+}
+
+send_hex_tcp $1 $2
+
+exit $?