From 510939199c0ea017b8a552150b5e240adaed93be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20C=C3=ADfka?= Date: Tue, 9 Jun 2020 13:59:43 +0200 Subject: [PATCH] added automated build & run into sdk/run.sh, README update --- README.md | 18 ++---------------- sdk/run.sh | 42 +++++++++++++++++++++++++++++++++++++++--- sdk/telnet.exp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 19 deletions(-) create mode 100755 sdk/telnet.exp diff --git a/README.md b/README.md index f1dfd7e..51dcaa2 100644 --- a/README.md +++ b/README.md @@ -30,23 +30,9 @@ Copy autorun.ash to the micro SD card root. Then connect over telnet (user: root cd sdk -Build a Docker container with the development environment and compile a "hello world" executable by running - - ./run.sh - -Then copy the resulting binary to the camera: - - - run on the computer: - - - nc -l 1234 < hello - - - - then run on the camera: - - - nc 192.168.42.5 1234 > /tmp/hello && chmod +x /tmp/hello && /tmp/hello +By running script run.sh, build a Docker container with the development environment and compile a "hello world" executable (-b option), then copy and run it directly on the camera (-r option): + ./run.sh -br # Running the script on Android (5.0+) diff --git a/sdk/run.sh b/sdk/run.sh index e56eb85..2331eac 100755 --- a/sdk/run.sh +++ b/sdk/run.sh @@ -1,4 +1,40 @@ -#!/bin/sh -euxo pipefail +#!/bin/bash +set -euo pipefail + +sources="hello.cpp" +headers="" +outfile="hello" + + +build=false +run=false +usage=$(echo -e "Usage: run.sh [OPTIONS] \n\t-b build \n\t-r copy to camera and run") + +if [ $# -eq 0 ]; then + echo "$usage" + exit 1 +fi + +while getopts "br" opt; do + case ${opt} in + b ) build=true + ;; + r ) run=true + ;; + \? ) echo "$usage" + ;; + esac +done + + +if [ "$build" = true ] ; then + sudo docker build -t mi_camera_sdk . + sudo docker run -it --rm -v "$PWD":/workdir mi_camera_sdk bash -c "cp $sources $headers /tmp && arm-linux-gnueabihf-c++ -o /workdir/$outfile $sources" + echo -e "\n" +fi + +if [ "$run" = true ] ; then + sleep 1 && nc 192.168.42.1 1234 -w2 <"$outfile" & + ./telnet.exp /tmp/"$outfile" +fi -docker build -t mi_camera_sdk . -docker run -it --rm -v "$PWD":/workdir mi_camera_sdk bash -c 'cp hello.cpp /tmp && arm-linux-gnueabihf-c++ -o /workdir/hello /tmp/hello.cpp' diff --git a/sdk/telnet.exp b/sdk/telnet.exp new file mode 100755 index 0000000..d2afbe9 --- /dev/null +++ b/sdk/telnet.exp @@ -0,0 +1,39 @@ +#!/usr/bin/expect + + + +set timeout 5 +set filepath [lindex $argv 0] + +spawn telnet 192.168.42.1 +match_max 10000 + +expect "Trying 192.168.42.1...\r" +expect { + "Connected to 192.168.42.1.\r" {} + timeout {puts "timed out during connecting" ; exit 1} + } +expect "Escape character is '^\]'.\r" +expect "\r\r" +expect "a12 login: " + +send -- "root\r" +expect -exact "root\r +~ # " + +send -- "nc -w3 -l -p 1234 >$filepath\r" +expect -exact "nc -w3 -l -p 1234 >$filepath\r +~ # " + +send -- "chmod +x $filepath\r" +expect -exact "chmod +x $filepath\r +~ # " + + +send -- "$filepath\r" +expect -exact "$filepath\r" + + +#send -- "exit\r" +#expect eof +interact -- GitLab