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() (string, int) {
|
runState := cache.data.Back().Value
|
if runState == nil {
|
return "", 0
|
}
|
|
return runState.(elevatorRunData).Floor, runState.(elevatorRunData).RunState
|
}
|
|
func listenQueue() {
|
for {
|
data := queue.dequeue()
|
cache.store(data)
|
|
// 清理过期数据
|
cache.cleanExpired()
|
}
|
}
|