package main import ( "cicv-data-closedloop/pjisuv_ticker" "fmt" "math" "sync" "time" ) var () // 定时任务触发器固定的 func Topic() string { return pjisuv_ticker.TickerTopic } // ******* 禁止存在下划线_ // 触发器标记 func Label() string { return "CCFhos" } func Rule(shareVars *sync.Map) { defer func() { if r := recover(); r != nil { fmt.Println("Recovered from panic:", r) } }() // 1 使用goroutine go func(shareVars *sync.Map) { // 2 定义触发器的间隔时间 ticker := time.NewTicker(time.Duration(3) * time.Second) defer ticker.Stop() // 3 运行一个无限循环 for { select { // 定时器触发时执行的代码 case <-ticker.C: FinalCallback(shareVars) } } }(shareVars) } func isRetrograde(ObjectList [][]float32) bool { for i := 0; i < len(ObjectList[0]); i++ { xi := ObjectList[0][i] yi := math.Abs(float64(ObjectList[1][i])) diff_hi := ObjectList[7][i] Type := ObjectList[6][0] if xi >= 20 && yi <= 1.2 && diff_hi > 150 && Type != 1.0 { for j := 0; j < len(ObjectList[0])-i-1; j++ { xj := ObjectList[0][j] yj := math.Abs(float64(ObjectList[1][j])) diff_hj := ObjectList[7][j] if xj <= 8 && yj <= 1.2 && diff_hj > 150 { return true } } } } return false } func FinalCallback(shareVars *sync.Map) { OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag") ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception") ObjDic := ObjDicOfTpperception.(map[uint32][][]float32) AbsSpeed, ok2 := shareVars.Load("AbsSpeed") if ok && ok1 && ok2 && OutsideWorkshopFlag.(bool) == true && AbsSpeed.(float64) > 1 { for _, objValue := range ObjDic { if len(ObjDic[0]) <= 10 || !isRetrograde(objValue) { continue } event_lable := "CCFhos" fmt.Println(event_lable) pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()} } } }