zhangzengfei
2024-10-20 c8a641dd784c071f83a0d90c35f617607fd0811b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()
    }
}