-
Notifications
You must be signed in to change notification settings - Fork 0
/
femtocom
executable file
·89 lines (73 loc) · 1.96 KB
/
femtocom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
### Documentation (sort of)
#
# config sample of ~/.femtocomrc by hardcoded variable CONF
# $ cat ~/.femtocomrc
#
#
# ; options from this section will be applied to ALL configurations
# [GLOBAL]
# echo=
# ; turns into `--echo' for picocom command line
#
#
# ; GLOBAL options + classic default: 115200@8N1 on ttyUSB0
# [default]
# baud=115200
# ; turns into `--baud 115200' for picocom command line and so on
# databits=8
# parity=n
# flow=n
# stopbits=1
# port=/dev/ttyUSB0
# ; turns into `picocom OPTIONS /dev/ttyUSB0`
#
#
# [myhwtool]
# baud=9600
# databits=8
# parity=n
# flow=n
# stopbits=1
#
# $
#
# ; hence, the usage will be just as easy as:
#
# $ femtocom myhwtool
#
# which will turns into
#
# $ picocom --echo --baud 9600 --databits 8 --parity n --flow n --stopbits 1 /dev/myhwtool
#
### init
CONF=~/.femtocomrc
set -e
test -n "${DEBUG}" && set -x
### main
# extract global settings
globals="$(sed -e '1,/^\[GLOBAL\]/d;/^ *$/,$d;' -e $'s/^\t*//g;' -e 's/^ *//g; s/=$//g; s/=/ /g; /^;/d; /^#/d; s/^/--/g;' ${CONF})"
if [ -n "${1}" ]; then
section="${1}"
else
section="default"
fi;
# extract settings for provided config section name
options="$(sed -e '1,/^\['"${section}"'\]/d;/^ *$/,$d;' -e $'s/^\t*//g;' -e 's/^ *//g; s/=$//g; s/=/ /g; /^;/d; /^#/d; s/^/--/g;' ${CONF})"
# port value processing:
# if port is not provided, then use ttyUSB0 for default section
# if port is not provided and section is not default, then use name of section for port (must be pre-configured using udev)
if [ -z "`echo ${options} | grep "/dev/"`" ]; then
if [ "${section}" = "default" ]; then
args="${globals} ${options} /dev/ttyUSB0"
else
args="${globals} ${options} /dev/${section}"
fi;
else
args="${globals} "`echo "${options}" | sed 's,--port,,'`""
fi;
pretty_args="`echo ${args} | tr '\n' ' '`"
echo -ne "\n====>>>> exit: hold CTRL and press: A X\n\n"
echo -ne "====>>>> picocom ${pretty_args} \n\n"
picocom ${pretty_args}
exit 0