#!/bin/sh /etc/rc.common
START=96

boot() {
	stop
	start
}

start() {
	cp "`uci get dnp3.outstation.config_file`" /etc/MODBUS_DNP3_Configuration_MH.csv &> /dev/null
	if  [[ ! `ls /etc/MODBUS_DNP3_Configuration_MH.csv` ]] || [[ "`ls -l /etc/MODBUS_DNP3_Configuration_MH.csv  | awk '{print$5}'`" == 0 ]]; then exit ; fi;
	if [ `uci get dnp3.outstation.dnp3_oenable` == 1 ]; then
		/usr/bin/dnp3outstation &> /dev/null &
		if [ `uci get dnp3.outstation.modbus_enable` == 1 ]; then
			/usr/bin/modbusmaster-lite &> /dev/null &
		fi
	fi
}

stop() {
	rm -rf /etc/MODBUS_DNP3_Configuration_MH.csv &> /dev/null
        killall dnp3outstation
	killall modbusmaster-lite
	return 0
}

reload() {
	stop
	start
}


