package nvcs import ( "context" "gat1400Exchange/config" "time" ) const ( RunStop = iota RunUp RunDown ) // 数据结构 type ElevatorRunData struct { Device string Timestamp int64 Floor string RunState int } var queue = newChQueue(100) var cache = newCache(5 * time.Minute) func StartNVCSServer(ctx context.Context) { go listenQueue() if config.RFIDConf.ReadFloor { go readRFID(ctx) } if config.NVCSConf.Model == "A1" { go a1UDPServer() } if config.NVCSConf.Model == "A2" { go a2WebServer() } if config.NVCSConf.Model == "A3" { go a3WebServer() } } func CurrentRunState() (runState ElevatorRunData) { node := cache.data.Back() if node == nil { return } return node.Value.(ElevatorRunData) } func FindPositionByTime(timestamp int64) ElevatorRunData { return cache.getPositionByTime(timestamp) } func FindMovePosition(timestamp int64, floor string) ElevatorRunData { return cache.getMovePosition(timestamp, floor) } func listenQueue() { for { data := queue.get() //t := time.Now() cache.store(data) //logger.Debug("process queue data %+v, use time %v", data, time.Since(t)) // 清理过期数据 cache.cleanExpired() } }