Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

configure 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. #!/bin/bash
  2. # This version is heavily based on the work of mz-fuzzy (https://github.com/mz-fuzzy)
  3. # adapted to work with MySensors project.
  4. # Original work: https://github.com/TMRh20/RF24/blob/master/configure
  5. function help {
  6. cat <<EOF
  7. configure script for MySensors gateway.
  8. Options:
  9. Help:
  10. -h, --help print this message
  11. SPI driver options:
  12. --spi-driver=[BCM|SPIDEV]
  13. --spi-spidev-device=<DEVICE>
  14. Device path. [/dev/spidev0.0]
  15. Building options:
  16. --soc=[BCM2835|BCM2836|BCM2837|AM33XX|A10|A13|A20|H3]
  17. SoC type to be used. [configure autodetected]
  18. --cpu-flags=<CPUFLAGS> CPU defining/optimizing flags to be used. [configure autodetected]
  19. --extra-cflags=<CFLAGS> Extra C flags passed to C compilation. []
  20. --extra-cxxflags=<CXXFLAGS> Extra C++ flags passed to C++ compilation. []
  21. Example: --extra-cxxflags="-DMY_RX_MESSAGE_BUFFER_SIZE=\(32\) -DMY_RF24_DATARATE=\(RF24_2MBPS\)"
  22. --extra-ldflags=<LDFLAGS> Extra C flags passed to linking. []
  23. --c_compiler=<CC> C compiler. [arm-linux-gnueabihf-gcc][gcc]
  24. --cxx_compiler=<CXX> C++ compiler. [arm-linux-gnueabihf-g++][g++]
  25. --build-dir=<DIR> Compiler directory to store object files. [build]
  26. --bin-dir=<DIR> Compiler directory to store binary files. [bin]
  27. --arduino-lib-dir=<DIR> Arduino library directory.
  28. --no-clean Don't clean previous build artifacts.
  29. Installation options:
  30. --prefix=<PREFIX> Installation prefix path. [/usr/local]
  31. --gateway-dir=<DIR> Gateway files installation directory. [PREFIX/bin]
  32. MySensors options:
  33. --my-debug=[enable|disable] Enables or disables MySensors core debugging. [enable]
  34. --my-config-file=<FILE> Config file path. [/etc/mysensors.conf]
  35. --my-gateway=[none|ethernet|serial|mqtt]
  36. Set the protocol used to communicate with the controller. [ethernet]
  37. --my-node-id=<ID> Disable gateway feature and run as a node with the specified id.
  38. --my-controller-url-address=<URL>
  39. Controller or MQTT broker url.
  40. --my-controller-ip-address=<IP>
  41. Controller or MQTT broker ip.
  42. --my-port=<PORT> The port to keep open on gateway mode.
  43. If gateway is set to mqtt, it sets the broker port.
  44. --my-serial-port=<PORT> Serial port.
  45. --my-serial-baudrate=<BAUD> Serial baud rate. [115200]
  46. --my-serial-is-pty Set the serial port to be a pseudo terminal. Use this if you want
  47. to connect to a controller running on the same device.
  48. You also need to set the symlink name for the PTY device with
  49. the --my-serial-port option.
  50. --my-serial-groupname=<GROUP>
  51. Grant access to the specified system group for the serial device.
  52. --my-mqtt-client-id=<ID> MQTT client id.
  53. --my-mqtt-user=<UID> MQTT user id.
  54. --my-mqtt-password=<PASS> MQTT password.
  55. --my-mqtt-publish-topic-prefix=<PREFIX>
  56. MQTT publish topic prefix.
  57. --my-mqtt-subscribe-topic-prefix=<PREFIX>
  58. MQTT subscribe topic prefix.
  59. --my-transport=[none|rf24|rs485|rfm95|rfm69]
  60. Set the transport to be used to communicate with other nodes. [rf24]
  61. --my-rf24-channel=<0-125> RF channel for the sensor net. [76]
  62. --my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_LOW]
  63. RF24 PA level. [RF24_PA_MAX]
  64. --my-rf24-ce-pin=<PIN> Pin number to use for rf24 Chip-Enable.
  65. --my-rf24-cs-pin=<PIN> Pin number to use for rf24 Chip-Select.
  66. --my-rf24-irq-pin=<PIN> Pin number connected to nRF24L01P IRQ pin.
  67. --my-rf24-encryption-enabled
  68. Enables RF24 encryption.
  69. All nodes and gateway must have this enabled, and all must be
  70. personalized with the same AES key.
  71. --my-rx-message-buffer-size=<SIZE>
  72. Buffer size for incoming messages when using rf24 interrupts. [20]
  73. --my-rfm69-frequency=[315|433|865|868|915]
  74. RFM69 Module Frequency. [868]
  75. --my-is-rfm69hw Enable high-powered rfm69hw.
  76. --my-rfm69-irq-pin=<PIN> Pin number connected to RFM69 IRQ pin.
  77. --my-rfm69-cs-pin=<PIN> Pin number to use for RFM69 Chip-Select.
  78. --my-rfm69-encryption-enabled
  79. Enables RFM69 encryption.
  80. All nodes and gateway must have this enabled, and all must be
  81. personalized with the same AES key.
  82. --my-rfm95-frequency=[169|315|434|868|915]
  83. RFM95 Module Frequency. [868]
  84. --my-rfm95-irq-pin=<PIN> Pin number connected to RFM95 IRQ pin.
  85. --my-rfm95-cs-pin=<PIN> Pin number to use for RFM95 Chip-Select.
  86. --my-rfm95-encryption-enabled
  87. Enables RFM95 encryption.
  88. All nodes and gateway must have this enabled, and all must be
  89. personalized with the same AES key.
  90. --my-rs485-serial-port=<PORT>
  91. RS485 serial port. You must provide a port.
  92. --my-rs485-baudrate=<BAUD> RS485 baudrate. [9600]
  93. --my-rs485-de-pin=<PIN> Pin number connected to RS485 driver enable pin.
  94. --my-rs485-max-msg-length=<LENGTH>
  95. The maximum message length used for RS485. [40]
  96. --my-leds-err-pin=<PIN> Error LED pin.
  97. --my-leds-rx-pin=<PIN> Receive LED pin.
  98. --my-leds-tx-pin=<PIN> Transmit LED pin.
  99. --my-leds-blinking-inverse Inverse the blinking feature.
  100. --my-signing=[none|software|password]
  101. Message signing. [none]
  102. --my-signing-debug Enable signing related debug.
  103. --my-signing-request-signatures
  104. Enable signature request from nodes that in turn requested
  105. gateway signature.
  106. --my-signing-weak_security Enable this to permit downgrade of security preferences and
  107. relaxed gateway signing requirements.
  108. --my-signing-whitelist=<WHITELIST>
  109. If you want to use a whitelist, provide it here, make sure to avoid
  110. spaces in the <whitelist> expression.
  111. --my-signing-verification-timeout-ms=<TIMEOUT>
  112. Signing timeout. [5000]
  113. --my-security-password=<PASSWORD>
  114. If you are using password for signing/encryption, set your password here.
  115. EOF
  116. }
  117. # Colors
  118. GREEN='\033[0;32m'
  119. RED='\033[0;31m'
  120. YELLOW='\033[1;33m'
  121. LIGHT_BLUE='\033[1;34m'
  122. NO_COLOR='\033[0m'
  123. OK="${GREEN}[OK]${NO_COLOR}"
  124. ERROR="${RED}[ERROR]${NO_COLOR}"
  125. FAILED="${YELLOW}[FAILED]${NO_COLOR}"
  126. SECTION="${LIGHT_BLUE}[SECTION]${NO_COLOR}"
  127. function die {
  128. printf "${ERROR} $1 \n"
  129. exit $2
  130. }
  131. function detect_rpi_revision {
  132. # get PI Revision from cpuinfo
  133. local pirev=$(eval "cat /proc/cpuinfo 2>/dev/null | grep Revision | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$$//'")
  134. echo ${pirev}
  135. }
  136. function detect_machine {
  137. local cpu=$(eval "uname -m 2>/dev/null")
  138. local machine=$(eval "cat /sys/firmware/devicetree/base/model 2>/dev/null |tr -d '\0'")
  139. local hardware=$(eval "grep sunxi_platform /sys/class/sunxi_info/sys_info 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
  140. if [ -z "$hardware" ]; then
  141. local hardware=$(eval "grep Hardware /proc/cpuinfo 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
  142. fi
  143. local soc="unknown"
  144. local tp="unknown"
  145. if [ -z "$cpu" ]; then
  146. cpu="unknown"
  147. fi
  148. case $hardware in
  149. BCM*)
  150. if [[ $machine == "Raspberry"* ]]; then
  151. # Calculation done by joolswills(https://github.com/joolswills) for the RetroPie-Setup project
  152. # and based on information from https://github.com/AndrewFromMelbourne/raspberry_pi_revision
  153. local rev="0x$(sed -n '/^Revision/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo)"
  154. # if bit 23 is not set, we are on a rpi1 (bit 23 means the revision is a bitfield)
  155. if [[ $((($rev >> 23) & 1)) -eq 0 ]]; then
  156. soc="BCM2835"
  157. tp="rpi1"
  158. else
  159. # if bit 23 is set, get the cpu from bits 12-15
  160. case "$((($rev >> 12) & 15))" in
  161. 0)
  162. soc="BCM2835"
  163. tp="rpi1"
  164. ;;
  165. 1)
  166. soc="BCM2836"
  167. tp="rpi2"
  168. ;;
  169. 2)
  170. soc="BCM2837"
  171. tp="rpi3"
  172. ;;
  173. esac
  174. fi
  175. elif [[ $hardware == "BCM2708"* ]]; then
  176. soc="BCM2835"
  177. elif [[ $hardware == "BCM2709"* ]]; then
  178. soc="BCM2836"
  179. elif [[ $hardware == "BCM2710"* ]]; then
  180. soc="BCM2837"
  181. fi
  182. ;;
  183. *sun4i*|*Sun4iw1p1*)
  184. soc="A10"
  185. ;;
  186. *sun5i*|*Sun4iw2p1*)
  187. soc="A13"
  188. ;;
  189. *Sun4iw2p2*)
  190. soc="A12"
  191. ;;
  192. *Sun4iw2p3*)
  193. soc="A10s"
  194. ;;
  195. *sun6i*|*Sun8iw1p1*)
  196. soc="A31"
  197. ;;
  198. *Sun8iw1p2*)
  199. soc="A31s"
  200. ;;
  201. *sun7i*|*Sun8iw2p1*)
  202. soc="A20"
  203. if [[ $machine == "Banana Pi"* ]]; then
  204. tp="BananaPi"
  205. elif [[ $machine == "Banana Pro"* ]]; then
  206. tp="BananaPro"
  207. fi
  208. ;;
  209. *sun8i*|*Sun8iw7p1*)
  210. soc="H3"
  211. ;;
  212. *Sun8iw3p1*)
  213. soc="A23"
  214. ;;
  215. *Sun8iw5p1*)
  216. soc="A33"
  217. ;;
  218. *Sun8iw6p1*)
  219. soc="A83t"
  220. ;;
  221. *sun9i*|*Sun9iw1p1*)
  222. soc="A80"
  223. ;;
  224. *Sun9iw1p2*)
  225. soc="A80t"
  226. ;;
  227. *sun50i*|*Sun50iw1p1*)
  228. soc="A64"
  229. ;;
  230. 'Generic AM33XX'*)
  231. soc="AM33XX"
  232. ;;
  233. *)
  234. soc="unknown"
  235. esac
  236. echo "${soc} ${tp} ${cpu}"
  237. }
  238. function gcc_cpu_flags {
  239. local soc=$1
  240. case $soc in
  241. BCM2835)
  242. flags="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard"
  243. ;;
  244. BCM2836)
  245. flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
  246. ;;
  247. BCM2837)
  248. flags="-march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard"
  249. ;;
  250. AM33XX)
  251. flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
  252. ;;
  253. A10)
  254. flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
  255. ;;
  256. A13)
  257. flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
  258. ;;
  259. A20)
  260. flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
  261. ;;
  262. H3)
  263. flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
  264. ;;
  265. *)
  266. flags=""
  267. esac
  268. echo ${flags}
  269. }
  270. # Default values
  271. debug=enable
  272. gateway_type=ethernet
  273. transport_type=rf24
  274. signing=none
  275. signing_request_signatures=false
  276. encryption=false
  277. params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER"
  278. for opt do
  279. if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
  280. help
  281. exit 0
  282. fi
  283. optarg="${opt#*=}"
  284. case "$opt" in
  285. --spi-driver=*)
  286. SPI_DRIVER="$optarg"
  287. ;;
  288. --spi-spidev-device=*)
  289. CPPFLAGS="-DSPI_SPIDEV_DEVICE=\\\"${optarg}\\\" $CPPFLAGS"
  290. ;;
  291. --soc=*)
  292. SOC="$optarg"
  293. ;;
  294. --platform-type=*)
  295. PT="$optarg"
  296. ;;
  297. --cpu-flags=*)
  298. CPUFLAGS="$optarg"
  299. ;;
  300. --extra-cflags=*)
  301. CFLAGS="$optarg"
  302. ;;
  303. --extra-cxxflags=*)
  304. CXXFLAGS="$optarg"
  305. ;;
  306. --extra-ldflags=*)
  307. LDFLAGS="$optarg"
  308. ;;
  309. --c_compiler=*)
  310. CC="$optarg"
  311. ;;
  312. --cxx_compiler=*)
  313. CXX="$optarg"
  314. ;;
  315. --arduino-lib-dir=*)
  316. ARDUINO_LIB_DIR=$optarg
  317. ;;
  318. --build-dir=*)
  319. BUILDDIR="$optarg"
  320. ;;
  321. --bin-dir=*)
  322. BINDIR="$optarg"
  323. ;;
  324. --no-clean*)
  325. NO_CLEAN="1"
  326. ;;
  327. --prefix=*)
  328. PREFIX="$optarg"
  329. ;;
  330. --exec-prefix=*)
  331. PREFIX="$optarg"
  332. ;;
  333. --no_init_system*)
  334. NO_INIT="1"
  335. ;;
  336. --gateway-dir=*)
  337. GATEWAY_DIR="$optarg"
  338. ;;
  339. --my-debug=*)
  340. debug=${optarg}
  341. ;;
  342. --my-gateway=*)
  343. gateway_type=${optarg}
  344. ;;
  345. --my-node-id=*)
  346. gateway_type="none";
  347. CPPFLAGS="-DMY_NODE_ID=${optarg} $CPPFLAGS"
  348. ;;
  349. --my-config-file=*)
  350. CPPFLAGS="-DMY_LINUX_CONFIG_FILE=\\\"${optarg}\\\" $CPPFLAGS"
  351. ;;
  352. --my-transport=*)
  353. transport_type=${optarg}
  354. ;;
  355. --my-serial-port=*)
  356. CPPFLAGS="-DMY_LINUX_SERIAL_PORT=\\\"${optarg}\\\" $CPPFLAGS"
  357. ;;
  358. --my-serial-baudrate=*)
  359. CPPFLAGS="-DMY_BAUD_RATE=${optarg} $CPPFLAGS"
  360. ;;
  361. --my-serial-is-pty*)
  362. CPPFLAGS="-DMY_LINUX_SERIAL_IS_PTY $CPPFLAGS"
  363. ;;
  364. --my-serial-pty=*)
  365. echo "Warning: --my-serial-pty is deprecated, please use --my-serial-port"
  366. CPPFLAGS="-DMY_LINUX_SERIAL_PORT=\\\"${optarg}\\\" $CPPFLAGS"
  367. ;;
  368. --my-serial-groupname=*)
  369. CPPFLAGS="-DMY_LINUX_SERIAL_GROUPNAME=\\\"${optarg}\\\" $CPPFLAGS"
  370. ;;
  371. --my-rf24-channel=*)
  372. CPPFLAGS="-DMY_RF24_CHANNEL=${optarg} $CPPFLAGS"
  373. ;;
  374. --my-rf24-pa-level=*)
  375. CPPFLAGS="-DMY_RF24_PA_LEVEL=${optarg} $CPPFLAGS"
  376. ;;
  377. --my-rf24-ce-pin=*)
  378. CPPFLAGS="-DMY_RF24_CE_PIN=${optarg} $CPPFLAGS"
  379. ;;
  380. --my-rf24-cs-pin=*)
  381. CPPFLAGS="-DMY_RF24_CS_PIN=${optarg} $CPPFLAGS"
  382. ;;
  383. --my-controller-url-address=*)
  384. CPPFLAGS="-DMY_CONTROLLER_URL_ADDRESS=\\\"${optarg}\\\" $CPPFLAGS"
  385. ;;
  386. --my-controller-ip-address=*)
  387. controller_ip=`echo ${optarg//./,}`
  388. CPPFLAGS="-DMY_CONTROLLER_IP_ADDRESS=${controller_ip} $CPPFLAGS"
  389. ;;
  390. --my-port=*)
  391. CPPFLAGS="-DMY_PORT=${optarg} $CPPFLAGS"
  392. ;;
  393. --my-mqtt-client-id=*)
  394. CPPFLAGS="-DMY_MQTT_CLIENT_ID=\\\"${optarg}\\\" $CPPFLAGS"
  395. ;;
  396. --my-mqtt-user=*)
  397. CPPFLAGS="-DMY_MQTT_USER=\\\"${optarg}\\\" $CPPFLAGS"
  398. ;;
  399. --my-mqtt-password=*)
  400. CPPFLAGS="-DMY_MQTT_PASSWORD=\\\"${optarg}\\\" $CPPFLAGS"
  401. ;;
  402. --my-mqtt-publish-topic-prefix=*)
  403. CPPFLAGS="-DMY_MQTT_PUBLISH_TOPIC_PREFIX=\\\"${optarg}\\\" $CPPFLAGS"
  404. ;;
  405. --my-mqtt-subscribe-topic-prefix=*)
  406. CPPFLAGS="-DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\\\"${optarg}\\\" $CPPFLAGS"
  407. ;;
  408. --my-rf24-irq-pin=*)
  409. CPPFLAGS="-DMY_RX_MESSAGE_BUFFER_FEATURE -DMY_RF24_IRQ_PIN=${optarg} $CPPFLAGS"
  410. ;;
  411. --my-rf24-encryption-enabled*)
  412. encryption=true
  413. CPPFLAGS="-DMY_RF24_ENABLE_ENCRYPTION $CPPFLAGS"
  414. ;;
  415. --my-rx-message-buffer-size=*)
  416. CPPFLAGS="-DMY_RX_MESSAGE_BUFFER_SIZE=${optarg} $CPPFLAGS"
  417. ;;
  418. --my-rfm69-frequency=*)
  419. if [[ ${optarg} == "315" ]]; then
  420. CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_315MHZ $CPPFLAGS"
  421. elif [[ ${optarg} == "433" ]]; then
  422. CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_433MHZ $CPPFLAGS"
  423. elif [[ ${optarg} == "865" ]]; then
  424. CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_865MHZ $CPPFLAGS"
  425. elif [[ ${optarg} == "868" ]]; then
  426. CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_868MHZ $CPPFLAGS"
  427. elif [[ ${optarg} == "915" ]]; then
  428. CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_915MHZ $CPPFLAGS"
  429. else
  430. echo "[WARNING] Illegal value for --my-rfm69-frequency=${optarg}, ignored"
  431. fi
  432. ;;
  433. --my-is-rfm69hw*)
  434. CPPFLAGS="-DMY_IS_RFM69HW $CPPFLAGS"
  435. ;;
  436. --my-rfm69-irq-pin=*)
  437. CPPFLAGS="-DMY_RFM69_IRQ_PIN=${optarg} $CPPFLAGS"
  438. ;;
  439. --my-rfm69-cs-pin=*)
  440. CPPFLAGS="-DMY_RFM69_CS_PIN=${optarg} $CPPFLAGS"
  441. ;;
  442. --my-rfm69-encryption-enabled*)
  443. encryption=true
  444. CPPFLAGS="-DMY_RFM69_ENABLE_ENCRYPTION $CPPFLAGS"
  445. ;;
  446. --my-rfm95-frequency=*)
  447. if [[ ${optarg} == "169" ]]; then
  448. CPPFLAGS="-DMY_RFM95_FREQUENCY=RFM95_169MHZ $CPPFLAGS"
  449. elif [[ ${optarg} == "315" ]]; then
  450. CPPFLAGS="-DMY_RFM95_FREQUENCY=RFM95_315MHZ $CPPFLAGS"
  451. elif [[ ${optarg} == "434" ]]; then
  452. CPPFLAGS="-DMY_RFM95_FREQUENCY=RFM95_434MHZ $CPPFLAGS"
  453. elif [[ ${optarg} == "868" ]]; then
  454. CPPFLAGS="-DMY_RFM95_FREQUENCY=RFM95_868MHZ $CPPFLAGS"
  455. elif [[ ${optarg} == "915" ]]; then
  456. CPPFLAGS="-DMY_RFM95_FREQUENCY=RFM95_915MHZ $CPPFLAGS"
  457. else
  458. echo "[WARNING] Illegal value for --my-rfm95-frequency=${optarg}, ignored"
  459. fi
  460. ;;
  461. --my-rfm95-irq-pin=*)
  462. CPPFLAGS="-DMY_RFM95_IRQ_NUM=${optarg} $CPPFLAGS"
  463. ;;
  464. --my-rfm95-cs-pin=*)
  465. CPPFLAGS="-DMY_RFM95_CS_PIN=${optarg} $CPPFLAGS"
  466. ;;
  467. --my-rfm95-encryption-enabled*)
  468. encryption=true
  469. CPPFLAGS="-DMY_RFM95_ENABLE_ENCRYPTION $CPPFLAGS"
  470. ;;
  471. --my-rs485-serial-port=*)
  472. CPPFLAGS="-DMY_RS485_HWSERIAL=\\\"${optarg}\\\" $CPPFLAGS"
  473. ;;
  474. --my-rs485-baudrate=*)
  475. CPPFLAGS="-DMY_RS485_BAUD_RATE=${optarg} $CPPFLAGS"
  476. ;;
  477. --my-rs485-de-pin=*)
  478. CPPFLAGS="-DMY_RS485_DE_PIN=${optarg} $CPPFLAGS"
  479. ;;
  480. --my-rs485-max-msg-length=*)
  481. CPPFLAGS="-DMY_RS485_MAX_MESSAGE_LENGTH=${optarg} $CPPFLAGS"
  482. ;;
  483. --my-leds-err-pin=*)
  484. CPPFLAGS="-DMY_DEFAULT_ERR_LED_PIN=${optarg} $CPPFLAGS"
  485. ;;
  486. --my-leds-rx-pin=*)
  487. CPPFLAGS="-DMY_DEFAULT_RX_LED_PIN=${optarg} $CPPFLAGS"
  488. ;;
  489. --my-leds-tx-pin=*)
  490. CPPFLAGS="-DMY_DEFAULT_TX_LED_PIN=${optarg} $CPPFLAGS"
  491. ;;
  492. --my-leds-blinking-inverse*)
  493. CPPFLAGS="-DMY_WITH_LEDS_BLINKING_INVERSE $CPPFLAGS"
  494. ;;
  495. --my-signing=*)
  496. signing=${optarg}
  497. ;;
  498. --my-signing-debug*)
  499. CPPFLAGS="-DMY_DEBUG_VERBOSE_SIGNING $CPPFLAGS"
  500. ;;
  501. --my-signing-request-signatures*)
  502. signing_request_signatures=true
  503. ;;
  504. --my-signing-weak_security*)
  505. CPPFLAGS="-DMY_SIGNING_WEAK_SECURITY $CPPFLAGS"
  506. ;;
  507. --my-signing-whitelist*)
  508. CPPFLAGS="-DMY_SIGNING_NODE_WHITELISTING=${optarg} $CPPFLAGS"
  509. ;;
  510. --my-signing-verification-timeout-ms*)
  511. CPPFLAGS="-DMY_VERIFICATION_TIMEOUT_MS=${optarg} $CPPFLAGS"
  512. ;;
  513. --my-security-password=*)
  514. security_password=${optarg}
  515. ;;
  516. *)
  517. echo "[WARNING] Unknown option detected:$opt, ignored"
  518. ;;
  519. esac
  520. done
  521. PREFIX=${PREFIX:-/usr/local}
  522. BUILDDIR=${BUILDDIR:-build}
  523. BINDIR=${BINDIR:-bin}
  524. GATEWAY_DIR=${GATEWAY_DIR:-${PREFIX}/bin}
  525. CC=${CC:-gcc}
  526. CXX=${CXX:-g++}
  527. if [ -z "${SOC}" ]; then
  528. printf "${SECTION} Detecting target machine.\n"
  529. info=($(detect_machine))
  530. SOC=${info[0]}
  531. TYPE=${info[1]}
  532. CPU=${info[2]}
  533. printf " ${OK} machine detected: SoC=${SOC}, Type=${TYPE}, CPU=${CPU}.\n"
  534. fi
  535. if [ -z "${CPUFLAGS}" ]; then
  536. CPUFLAGS=$(gcc_cpu_flags $SOC)
  537. fi
  538. if [[ $SOC == "BCM2835" || $SOC == "BCM2836" || $SOC == "BCM2837" ]]; then
  539. CPPFLAGS="-DLINUX_ARCH_RASPBERRYPI $CPPFLAGS"
  540. else
  541. printf "${SECTION} Checking GPIO Sysfs.\n"
  542. if [[ $(eval 'ls /sys/class/gpio/export 2>/dev/null') ]]; then
  543. printf " ${OK} /sys/class/gpio/export found.\n"
  544. else
  545. echo " [WARNING] /sys/class/gpio/export not found."
  546. fi
  547. fi
  548. if [ -z "${SPI_DRIVER}" ]; then
  549. printf "${SECTION} Detecting SPI driver.\n"
  550. if [[ $SOC == "BCM2835" || $SOC == "BCM2836" || $SOC == "BCM2837" ]]; then
  551. SPI_DRIVER=BCM
  552. elif [[ $(eval 'ls /dev/spidev* 2>/dev/null') ]]; then
  553. SPI_DRIVER=SPIDEV
  554. fi
  555. if [ -n "${SPI_DRIVER}" ]; then
  556. printf " ${OK} SPI driver detected:${SPI_DRIVER}.\n"
  557. else
  558. echo " [WARNING] No supported SPI driver detected. Using SPIDEV."
  559. SPI_DRIVER=SPIDEV
  560. fi
  561. fi
  562. if [ -n "${SPI_DRIVER}" ]; then
  563. case ${SPI_DRIVER} in
  564. BCM)
  565. if [[ $SOC != "BCM2835" && $SOC != "BCM2836" && $SOC != "BCM2837" ]]; then
  566. die "BCM SPI driver is only supported for SOCs BCM2835, BCM2836 or BCM2837" 5
  567. fi
  568. CPPFLAGS="-DLINUX_SPI_BCM $CPPFLAGS"
  569. ;;
  570. SPIDEV)
  571. CPPFLAGS="-DLINUX_SPI_SPIDEV $CPPFLAGS"
  572. ;;
  573. *)
  574. die "Unsupported SPI driver: ${SPI_DRIVER}." 1
  575. ;;
  576. esac
  577. fi
  578. printf "${SECTION} Gateway configuration.\n"
  579. if [[ ${debug} == "enable" ]]; then
  580. CPPFLAGS="-DMY_DEBUG $CPPFLAGS"
  581. fi
  582. if [[ ${gateway_type} == "none" ]]; then
  583. # Node mode selected
  584. :
  585. elif [[ ${gateway_type} == "ethernet" ]]; then
  586. CPPFLAGS="-DMY_GATEWAY_LINUX $CPPFLAGS"
  587. elif [[ ${gateway_type} == "serial" ]]; then
  588. CPPFLAGS="-DMY_GATEWAY_SERIAL $CPPFLAGS"
  589. elif [[ ${gateway_type} == "mqtt" ]]; then
  590. CPPFLAGS="-DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT $CPPFLAGS"
  591. else
  592. die "Invalid gateway type." 2
  593. fi
  594. printf " ${OK} Type: ${gateway_type}.\n"
  595. if [[ ${transport_type} == "none" ]]; then
  596. # Transport disabled
  597. :
  598. elif [[ ${transport_type} == "rf24" ]]; then
  599. CPPFLAGS="-DMY_RADIO_RF24 $CPPFLAGS"
  600. elif [[ ${transport_type} == "rfm69" ]]; then
  601. CPPFLAGS="-DMY_RADIO_RFM69 -DMY_RFM69_NEW_DRIVER $CPPFLAGS"
  602. elif [[ ${transport_type} == "rs485" ]]; then
  603. CPPFLAGS="-DMY_RS485 $CPPFLAGS"
  604. elif [[ ${transport_type} == "rfm95" ]]; then
  605. CPPFLAGS="-DMY_RADIO_RFM95 $CPPFLAGS"
  606. else
  607. die "Invalid transport type." 3
  608. fi
  609. printf " ${OK} Transport: ${transport_type}.\n"
  610. if [[ ${signing} == "none" ]]; then
  611. # Signing disabled
  612. printf " ${OK} Signing: Disabled.\n"
  613. elif [[ ${signing} == "software" ]]; then
  614. CPPFLAGS="-DMY_SIGNING_SOFT $CPPFLAGS"
  615. if [[ ${signing_request_signatures} == true ]]; then
  616. CPPFLAGS="-DMY_SIGNING_REQUEST_SIGNATURES $CPPFLAGS"
  617. fi
  618. printf " ${OK} Signing: Enabled - Using key from config file.\n"
  619. elif [[ ${signing} == "password" ]]; then
  620. if [ -z "${security_password}" ]; then
  621. die "You need to set the password for signing with --my-security-password option" 6
  622. fi
  623. printf " ${OK} Signing: Enabled - Simplified signing using password.\n"
  624. CPPFLAGS="-DMY_SIGNING_SIMPLE_PASSWD=\\\"${security_password}\\\" $CPPFLAGS"
  625. else
  626. die "Invalid signing type." 7
  627. fi
  628. if [[ ${encryption} == true ]]; then
  629. # Encryption enabled on some transport
  630. if [ -z "${security_password}" ]; then
  631. printf " ${OK} Encryption: Enabled - Using key from config file.\n"
  632. else
  633. printf " ${OK} Encryption: Enabled - Simplified encryption using password.\n"
  634. CPPFLAGS="-DMY_ENCRYPTION_SIMPLE_PASSWD=\\\"${security_password}\\\" $CPPFLAGS"
  635. fi
  636. else
  637. printf " ${OK} Encryption: Disabled.\n"
  638. fi
  639. printf " ${OK} CPPFLAGS: $CPPFLAGS\n"
  640. LDFLAGS="-pthread $LDFLAGS"
  641. CPPFLAGS="$CPUFLAGS $CPPFLAGS"
  642. printf "${SECTION} Detecting init system.\n"
  643. if [ "${NO_INIT}" ]; then
  644. printf " ${OK} No init system chosen.\n"
  645. elif [ -x /usr/bin/systemctl ] || [ -x /bin/systemctl ]; then
  646. INIT_SYSTEM=systemd
  647. printf " ${OK} Init system detected: systemd.\n"
  648. elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
  649. INIT_SYSTEM=sysvinit
  650. printf " ${OK} Init system detected: sysvinit.\n"
  651. else
  652. printf " ${FAILED} Unknown init system.\n"
  653. fi
  654. printf "${SECTION} Saving configuration.\n"
  655. echo -n "" > Makefile.inc
  656. for param in ${params}; do
  657. if [[ ${!param} ]]; then
  658. echo "${param}=${!param}" >> Makefile.inc
  659. fi
  660. done
  661. printf " ${OK} Saved.\n"
  662. if [ -z "${NO_CLEAN}" ]; then
  663. printf "${SECTION} Cleaning previous builds.\n"
  664. make clean >/dev/null
  665. fi
  666. printf " ${OK} Finished.\n"