diff --git a/mote/v2/openwrt/package/flukso/Makefile b/mote/v2/openwrt/package/flukso/Makefile index 2183455..0e9bebe 100644 --- a/mote/v2/openwrt/package/flukso/Makefile +++ b/mote/v2/openwrt/package/flukso/Makefile @@ -49,6 +49,7 @@ define Package/flukso/install $(INSTALL_BIN) $(PKG_BUILD_DIR)/spid.lua $(1)/usr/sbin/ $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/fsync.lua $(1)/usr/bin/fsync + $(INSTALL_BIN) $(PKG_BUILD_DIR)/fdude.lua $(1)/usr/bin/fdude $(INSTALL_BIN) $(PKG_BUILD_DIR)/restful.lua $(1)/usr/bin/restful endef diff --git a/mote/v2/openwrt/package/flukso/luasrc/fdude.lua b/mote/v2/openwrt/package/flukso/luasrc/fdude.lua new file mode 100755 index 0000000..f2beaf9 --- /dev/null +++ b/mote/v2/openwrt/package/flukso/luasrc/fdude.lua @@ -0,0 +1,53 @@ +#!/usr/bin/env lua + +--[[ + + fdude.lua - wraps avrdude in an spidev resource lock + + Copyright (C) 2011 Bart Van Der Meerssche + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +]]-- + + +local nixio = require 'nixio' + +local SPI_DEV = '/dev/spidev0.0' +local SPI_DAEMON_PID_FILE = '/var/run/spid/pid' +local O_RDWR_NONBLOCK = nixio.open_flags('rdwr', 'nonblock') + +local spidev = nixio.open(SPI_DEV, O_RDWR_NONBLOCK) +local exit = 0 + +if spidev:lock('tlock') then + nixio.execp('avrdude', ...) +else + print(string.format('Detected a lock on %s', SPI_DEV)) + + local pid = nixio.open(SPI_DAEMON_PID_FILE, O_RDWR_NONBLOCK) + + if pid then + print(string.format('spid process is still running with pid %d', pid:read(-1))) + exit = 1 + else + print('spid is not running.') + print('Could be a second avrdude still in progress.') + exit = 2 + end + + print('Aborting...') +end + +os.exit(exit) diff --git a/mote/v2/openwrt/package/flukso/luasrc/spid.lua b/mote/v2/openwrt/package/flukso/luasrc/spid.lua index 9678910..36ec200 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/spid.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/spid.lua @@ -82,7 +82,7 @@ local fds = { uart, ctrl, delta } local spidev = nixio.open(SPI_DEV, O_RDWR_NONBLOCK) nixio.spi.setspeed(spidev, SPI_MAX_CLK_SPEED_HZ, SPI_MIN_BYTE_DELAY_US) -spidev:lock('lock') +spidev:lock('lock') -- blocks until it can place a write lock on the spidev device while true do local msg