123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- module(...,package.seeall)
- require "pins"
- local BAT_ADC_ID,DC_ADC_ID = 2,3
- power24Flag = nil
- local function powerInterrupt( msg )
- -- body
- log.info("msg:", msg)
- if msg==cpu.INT_GPIO_NEGEDGE then
- log.info("gpio11 INT NEGEDGE msg")
- sys.publish("24V_POWER_DOWN")
- modbusTT.checkNetWorkHealth("power_24_off")
- else
- log.info("gpio11 INT POSGEDGE msg")
- end
- end
- setGpio11Fnc = pins.setup(pio.P0_11, powerInterrupt )
- function closePDs( )
- -- body
- uart.close(1) --关闭串口1
- -- pins.setup(pio.P0_18, 1) --断电GPS
- pins.setup(pio.P0_13, 1) --断电485
- end
- local function setRestartClock( )
- local restartInterval = nvm.get("restartInterval") or 86400
- -- body
- log.info("alarm test start")
- local t = os.date("*t")
- misc.setClock({year=t.year,month=t.month,day=t.day,hour=t.hour,min=t.min,sec=t.sec})
- sys.wait(2000)
- closePDs()
- local onTimet = os.date("*t",os.time() + restartInterval) --下次要开机的时间为1800秒后
- log.info("alarm restart time", restartInterval)
- rtos.set_alarm(1,onTimet.year,onTimet.month,onTimet.day,onTimet.hour,onTimet.min,onTimet.sec) --设定闹铃
- --如果要测试关机闹钟,打开下面这2行代码
- sys.wait(200000)
- rtos.poweroff()
- end
- local function powerTaskFnc( )
- -- body
- sys.wait(4000)
- power24Flag = setGpio11Fnc()
- log.info("当前24V电平:", power24Flag)
- if power24Flag == 0 then
- -- body
- setRestartClock()
- return
- end
- pins.setup(pio.P0_13, 0) --485上电
- sys.waitUntil("24V_POWER_DOWN")
- power24Flag = setGpio11Fnc()
- log.info("当前24V电平:", power24Flag)
-
- setRestartClock()
- end
- adc.open(BAT_ADC_ID)
- function adcTimer( )
- -- body
- local adcval, voltval = adc.read(BAT_ADC_ID)
- log.info("bat_power.read",adcval,voltval)
- end
- sys.timerLoopStart(adcTimer, 10000)
- sys.taskInit(powerTaskFnc)
- --[[
- 函数名:alarMsg
- 功能 :开机闹钟事件的处理函数
- 参数 :无
- 返回值:无
- ]]
- local function alarMsg()
- print("alarMsg---------------")
- end
- --如果是关机闹钟开机,则需要软件主动重启一次,才能启动GSM协议栈
- if rtos.poweron_reason()==rtos.POWERON_ALARM then
- sys.restart("ALARM")
- end
- --注册闹钟模块
- rtos.init_module(rtos.MOD_ALARM)
- --注册闹钟消息的处理函数(如果是开机闹钟,闹钟事件到来时会调用alarmsg)
- rtos.on(rtos.MSG_ALARM,alarMsg)
|