zhangzengfei
2024-10-20 1f096af76bf2398348c12fe3d3144cdd7c762985
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
65
66
67
68
69
70
71
72
73
74
75
76
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()
    }
}