-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhutianhua
committed
May 4, 2020
1 parent
eb2133e
commit 6a737eb
Showing
49 changed files
with
528 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--必须在这个位置定义PROJECT和VERSION变量 | ||
--PROJECT:ascii string类型,可以随便定义,只要不使用,就行 | ||
--VERSION:ascii string类型,如果使用Luat物联云平台固件升级的功能,必须按照"X.X.X"定义,X表示1位数字;否则可随便定义 | ||
PROJECT = "ALARM" | ||
VERSION = "2.0.0" | ||
|
||
--加载日志功能模块,并且设置日志输出等级 | ||
--如果关闭调用log模块接口输出的日志,等级设置为log.LOG_SILENT即可 | ||
require "log" | ||
LOG_LEVEL = log.LOGLEVEL_TRACE | ||
--[[ | ||
如果使用UART输出日志,打开这行注释的代码"--log.openTrace(true,1,115200)"即可,根据自己的需求修改此接口的参数 | ||
如果要彻底关闭脚本中的输出日志(包括调用log模块接口和Lua标准print接口输出的日志),执行log.openTrace(false,第二个参数跟调用openTrace接口打开日志的第二个参数相同),例如: | ||
1、没有调用过sys.opntrace配置日志输出端口或者最后一次是调用log.openTrace(true,nil,921600)配置日志输出端口,此时要关闭输出日志,直接调用log.openTrace(false)即可 | ||
2、最后一次是调用log.openTrace(true,1,115200)配置日志输出端口,此时要关闭输出日志,直接调用log.openTrace(false,1)即可 | ||
]] | ||
--log.openTrace(true,1,115200) | ||
|
||
require "sys" | ||
|
||
require "net" | ||
--每1分钟查询一次GSM信号强度 | ||
--每1分钟查询一次基站信息 | ||
net.startQueryAll(60000, 60000) | ||
|
||
--加载控制台调试功能模块(此处代码配置的是uart2,波特率115200) | ||
--此功能模块不是必须的,根据项目需求决定是否加载 | ||
--使用时注意:控制台使用的uart不要和其他功能使用的uart冲突 | ||
--使用说明参考demo/console下的《console功能使用说明.docx》 | ||
--require "console" | ||
--console.setup(2, 115200) | ||
|
||
--加载网络指示灯和LTE指示灯功能模块 | ||
--根据自己的项目需求和硬件配置决定:1、是否加载此功能模块;2、配置指示灯引脚 | ||
--合宙官方出售的Air720U开发板上的网络指示灯引脚为pio.P0_1,LTE指示灯引脚为pio.P0_4 | ||
require "netLed" | ||
pmd.ldoset(2,pmd.LDO_VLCD) | ||
netLed.setup(true,pio.P0_1,pio.P0_4) | ||
--网络指示灯功能模块中,默认配置了各种工作状态下指示灯的闪烁规律,参考netLed.lua中ledBlinkTime配置的默认值 | ||
--如果默认值满足不了需求,此处调用netLed.updateBlinkTime去配置闪烁时长 | ||
--LTE指示灯功能模块中,配置的是注册上4G网络,灯就常亮,其余任何状态灯都会熄灭 | ||
|
||
--加载错误日志管理功能模块【强烈建议打开此功能】 | ||
--如下2行代码,只是简单的演示如何使用errDump功能,详情参考errDump的api | ||
require "errDump" | ||
errDump.request("udp://ota.airm2m.com:9072") | ||
|
||
--加载远程升级功能模块【强烈建议打开此功能】 | ||
--如下3行代码,只是简单的演示如何使用update功能,详情参考update的api以及demo/update | ||
--PRODUCT_KEY = "v32xEAKsGTIEQxtqgwCldp5aPlcnPs3K" | ||
--require "update" | ||
--update.request() | ||
|
||
--加载闹钟功能测试模块 | ||
require "testAlarm" | ||
|
||
--启动系统框架 | ||
sys.init(0, 0) | ||
sys.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- 模块功能:闹钟功能测试(支持开机闹钟和关机闹钟,同时只能存在一个闹钟,如果想实现多个闹钟,等当前闹钟触发后,再次调用闹钟设置接口去配置下一个闹钟). | ||
-- @author openLuat | ||
-- @module alarm.testAlarm | ||
-- @license MIT | ||
-- @copyright openLuat | ||
-- @release 2018.03.14 | ||
|
||
require"ntp" | ||
require "sys" | ||
require"misc" | ||
module(...,package.seeall) | ||
|
||
|
||
sys.taskInit(function() | ||
sys.wait(10000) | ||
log.info("alarm test start") | ||
misc.setClock({year=2020,month=5,day=1,hour=12,min=12,sec=12}) | ||
sys.wait(2000) | ||
local onTimet = os.date("*t",os.time() + 60) --下次要开机的时间为60秒后 | ||
log.info("alarm restart time", 60) | ||
rtos.set_alarm(1,onTimet.year,onTimet.month,onTimet.day,onTimet.hour,onTimet.min,onTimet.sec) --设定闹铃 | ||
--如果要测试关机闹钟,打开下面这2行代码 | ||
--sys.wait(2000) | ||
--rtos.poweroff() | ||
end) | ||
|
||
--[[ | ||
函数名: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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--必须在这个位置定义PROJECT和VERSION变量 | ||
--PROJECT:ascii string类型,可以随便定义,只要不使用,就行 | ||
--VERSION:ascii string类型,如果使用Luat物联云平台固件升级的功能,必须按照"X.X.X"定义,X表示1位数字;否则可随便定义 | ||
PROJECT = "RECORD" | ||
VERSION = "2.0.0" | ||
|
||
--加载日志功能模块,并且设置日志输出等级 | ||
--如果关闭调用log模块接口输出的日志,等级设置为log.LOG_SILENT即可 | ||
require "log" | ||
LOG_LEVEL = log.LOGLEVEL_TRACE | ||
--[[ | ||
如果使用UART输出日志,打开这行注释的代码"--log.openTrace(true,1,115200)"即可,根据自己的需求修改此接口的参数 | ||
如果要彻底关闭脚本中的输出日志(包括调用log模块接口和Lua标准print接口输出的日志),执行log.openTrace(false,第二个参数跟调用openTrace接口打开日志的第二个参数相同),例如: | ||
1、没有调用过sys.opntrace配置日志输出端口或者最后一次是调用log.openTrace(true,nil,921600)配置日志输出端口,此时要关闭输出日志,直接调用log.openTrace(false)即可 | ||
2、最后一次是调用log.openTrace(true,1,115200)配置日志输出端口,此时要关闭输出日志,直接调用log.openTrace(false,1)即可 | ||
]] | ||
--log.openTrace(true,1,115200) | ||
|
||
require "sys" | ||
|
||
require "net" | ||
--每1分钟查询一次GSM信号强度 | ||
--每1分钟查询一次基站信息 | ||
net.startQueryAll(60000, 60000) | ||
|
||
--加载控制台调试功能模块(此处代码配置的是uart1,波特率115200) | ||
--此功能模块不是必须的,根据项目需求决定是否加载 | ||
--使用时注意:控制台使用的uart不要和其他功能使用的uart冲突 | ||
--使用说明参考demo/console下的《console功能使用说明.docx》 | ||
--require "console" | ||
--console.setup(1, 115200) | ||
|
||
--加载硬件看门狗功能模块 | ||
--根据自己的硬件配置决定:1、是否加载此功能模块;2、配置Luat模块复位单片机引脚和互相喂狗引脚 | ||
--合宙官方出售的Air201开发板上有硬件看门狗,所以使用官方Air201开发板时,必须加载此功能模块 | ||
--[[ | ||
require "wdt" | ||
wdt.setup(pio.P0_30, pio.P0_31) | ||
]] | ||
|
||
--加载网络指示灯和LTE指示灯功能模块 | ||
--根据自己的项目需求和硬件配置决定:1、是否加载此功能模块;2、配置指示灯引脚 | ||
--合宙官方出售的Air720U开发板上的网络指示灯引脚为pio.P0_1,LTE指示灯引脚为pio.P0_4 | ||
require "netLed" | ||
pmd.ldoset(2,pmd.LDO_VLCD) | ||
netLed.setup(true,pio.P0_1,pio.P0_4) | ||
--网络指示灯功能模块中,默认配置了各种工作状态下指示灯的闪烁规律,参考netLed.lua中ledBlinkTime配置的默认值 | ||
--如果默认值满足不了需求,此处调用netLed.updateBlinkTime去配置闪烁时长 | ||
|
||
--加载错误日志管理功能模块【强烈建议打开此功能】 | ||
--如下2行代码,只是简单的演示如何使用errDump功能,详情参考errDump的api | ||
require "errDump" | ||
errDump.request("udp://ota.airm2m.com:9072") | ||
|
||
--加载远程升级功能模块【强烈建议打开此功能】 | ||
--如下3行代码,只是简单的演示如何使用update功能,详情参考update的api以及demo/update | ||
--PRODUCT_KEY = "v32xEAKsGTIEQxtqgwCldp5aPlcnPs3K" | ||
--require "update" | ||
--update.request() | ||
|
||
--加载录音功能测试模块 | ||
require "testRecord" | ||
|
||
--启动系统框架 | ||
sys.init(0, 0) | ||
sys.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- 模块功能:录音功能测试. | ||
-- @author openLuat | ||
-- @module record.testRecord | ||
-- @license MIT | ||
-- @copyright openLuat | ||
-- @release 2018.03.27 | ||
|
||
module(...,package.seeall) | ||
|
||
require"record" | ||
require"audio" | ||
|
||
--每次读取的录音文件长度 | ||
local RCD_READ_UNIT = 1024 | ||
--rcdoffset:当前读取的录音文件内容起始位置 | ||
--rcdsize:录音文件总长度 | ||
--rcdcnt:当前需要读取多少次录音文件,才能全部读取 | ||
local rcdoffset,rcdsize,rcdcnt | ||
|
||
--[[ | ||
函数名:playcb | ||
功能 :播放录音结束后的回调函数 | ||
参数 :无 | ||
返回值:无 | ||
]] | ||
local function playcb(r) | ||
log.info("testRecord.playcb",r) | ||
--删除录音文件 | ||
record.delete() | ||
record.start(5,rcdcb) | ||
end | ||
|
||
--[[ | ||
函数名:readrcd | ||
功能 :读取录音文件内容 | ||
参数 :无 | ||
返回值:无 | ||
]] | ||
local function readrcd() | ||
local s = record.getData(rcdoffset,RCD_READ_UNIT) | ||
log.info("testRecord.readrcd",rcdoffset,rcdcnt,string.len(s)) | ||
rcdcnt = rcdcnt-1 | ||
--录音文件内容已经全部读取出来 | ||
if rcdcnt<=0 then | ||
sys.timerStop(readrcd) | ||
--播放录音内容 | ||
audio.play(0,"FILE",record.getFilePath(),7,playcb) | ||
--还没有全部读取出来 | ||
else | ||
rcdoffset = rcdoffset+RCD_READ_UNIT | ||
end | ||
end | ||
|
||
--[[ | ||
函数名:rcdcb | ||
功能 :录音结束后的回调函数 | ||
参数 : | ||
result:录音结果,true表示成功,false或者nil表示失败 | ||
size:number类型,录音文件的大小,单位是字节,在result为true时才有意义 | ||
返回值:无 | ||
]] | ||
function rcdcb(result,size) | ||
log.info("testRecord.rcdcb",result,size) | ||
if result then | ||
rcdoffset,rcdsize,rcdcnt = 0,size,(size-1)/RCD_READ_UNIT+1 | ||
sys.timerLoopStart(readrcd,1000) | ||
end | ||
end | ||
|
||
--5秒后,开始录音 | ||
sys.timerStart(record.start,5000,5,rcdcb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.