package timer import ( "github.com/robfig/cron" "smart_tunnel_edge/service" "smart_tunnel_edge/util/config" "time" ) var commandQueue = make(chan []byte, 5) func TimeTasks() { c := cron.New() _ = c.AddFunc("0 */5 * * * ?", func() { //0/5 * * * * ? if config.Instance().Policy.Id == 3 { //如果当前策略是定时改变光照亮度 endTime := config.Instance().Policy.EndTime startTime := config.Instance().Policy.StartTime currentTime := time.Now().Format("15:04") if currentTime == startTime { //开灯,将两条路亮度调高 go service.OperationLampSwitchJudge(1, service.HighLightLevel, 2, 1) go service.OperationLampSwitchJudge(2, service.HighLightLevel, 2, 1) } else if currentTime == endTime { //关灯,将两条路亮度调低 go service.OperationLampSwitchJudge(1, service.LowLightLevel, 2, 0) go service.OperationLampSwitchJudge(2, service.LowLightLevel, 2, 0) } } }) c.Start() }