Skip to content

Commit 7931260

Browse files
committed
修复bug
1 parent ef56b85 commit 7931260

File tree

8 files changed

+30220
-41
lines changed

8 files changed

+30220
-41
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VUE_APP_GITTAG=v0.10.1
1+
VUE_APP_GITTAG=v0.10.2

internal/serial/serial.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,26 @@ func GrRxPrase() {
208208
select {
209209
case rx := <-chRx: // 收到你的来信
210210
glog.V(4).Infoln("GrRxPrase: got chRx...")
211+
212+
glog.V(4).Infoln("had buff: ", rxBuff)
213+
211214
rxBuff = append(rxBuff, rx...) // 深藏我的心底
212215

213-
glog.V(4).Infoln("read buff: ", rxBuff)
216+
glog.V(4).Infoln("got buff: ", rxBuff)
214217

215218
// 解开长情的信笺
216219
// 残余的信亦不能忘却
217-
vars, rxBuff := variable.Unpack(rxBuff)
220+
var vars []variable.CmdT
221+
vars, rxBuff = variable.Unpack(rxBuff)
218222

219223
// 所有的酸甜苦辣都值得铭记
220224
glog.V(4).Infoln("left buff: ", rxBuff)
221225
glog.V(4).Infof("got vars: %v\n", vars)
222226

227+
if len(vars) > 10 {
228+
glog.Fatalln("Too many vars")
229+
}
230+
223231
// 拼凑出变量的清单
224232
chart, add, del := variable.Filt(vars)
225233
if len(chart) != 0 {

internal/serial/testport.go

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var vartypeMap = map[uint32]string{
3333

3434
var (
3535
chAddr = make(chan bool, 10) // 修改通知
36-
addresses []uint32 = []uint32{} // 观察的地址
36+
addresses map[uint32]bool = map[uint32]bool{} // 观察的地址
3737
writeData map[uint32][]byte = map[uint32][]byte{} // 直接写入数据
3838
BoardSysTime time.Time = time.Now() // 虚拟电路板的系统时间
3939
)
@@ -107,32 +107,31 @@ func testValue(x float64, addr uint32) []byte {
107107
}
108108

109109
func (tp *testPort) Read(p []byte) (n int, err error) {
110-
// maxNumPack := len(p) / 20
111-
// if len(addresses) > maxNumPack {
112-
// addresses = addresses[:maxNumPack]
113-
// }
114110
for len(addresses) == 0 {
115111
<-chAddr
116112
}
117-
pdu := make([]byte, len(addresses)*20)
118-
119-
for i, addr := range addresses {
120-
s := pdu[20*i : 20*(i+1)]
121-
s[0] = 1 // 单片机代号 board
122-
s[1] = 2 // 响应或错误代号 act (0x02 = 订阅的正常返回)
123-
s[2] = 8 // 数据长度 length
124-
copy(s[3:7], variable.AnyToBytes(addr)) // 单片机地址
113+
data := make([]byte, 0, len(addresses)*40)
114+
115+
i := 0
116+
for addr := range addresses {
117+
var pdu [20]byte
118+
pdu[0] = 1 // 单片机代号 board
119+
pdu[1] = 2 // 响应或错误代号 act (0x02 = 订阅的正常返回)
120+
pdu[2] = 8 // 数据长度 length
121+
copy(pdu[3:7], variable.AnyToBytes(addr)) // 单片机地址
125122
t := time.Since(BoardSysTime)
126123
x := t.Seconds()
127124
u := t.Milliseconds()
128125
y := testValue(x, addr)
129-
copy(s[7:15], y) // 数据
130-
copy(s[15:19], variable.AnyToBytes(uint32(u))) // 时间戳
131-
s[19] = '\n' // 尾部固定为0x0a
126+
copy(pdu[7:15], y) // 数据
127+
copy(pdu[15:19], variable.AnyToBytes(uint32(u))) // 时间戳
128+
pdu[19] = '\n' // 尾部固定为0x0a
129+
i++
130+
sdu := slip.Pack(pdu[:])
131+
data = append(data, sdu...)
132132
}
133133

134-
sdu := slip.Pack(pdu)
135-
return copy(p, sdu), nil
134+
return copy(p, data), nil
136135
}
137136

138137
func (tp *testPort) Write(p []byte) (n int, err error) {
@@ -152,20 +151,14 @@ func (tp *testPort) Write(p []byte) (n int, err error) {
152151
switch act {
153152
case variable.Subscribe:
154153
go time.AfterFunc(500*time.Millisecond, func() {
155-
addresses = append(addresses, address)
154+
addresses[address] = true
156155
chAddr <- true
157156
glog.Infof("Adding address: %08X\n", address)
158157
})
159158

160159
case variable.Unsubscribe:
161160
go time.AfterFunc(500*time.Millisecond, func() {
162-
var newAddresses []uint32
163-
for _, addr := range addresses {
164-
if addr != address {
165-
newAddresses = append(newAddresses, addr)
166-
}
167-
}
168-
addresses = newAddresses
161+
delete(addresses, address)
169162
chAddr <- true
170163
glog.Infof("Deleting address: %08X\n", address)
171164
})

internal/variable/filt.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ func Unpack(data []byte) ([]CmdT, []byte) {
6060
// 加入变量列表
6161
vars = append(vars, v)
6262
}
63-
f := ends[len(ends)-1] // 最后的结束,也是新的开始
64-
return vars, data[f+1:] // 变量的回音,仍有余音
63+
f := ends[len(ends)-1] // 最后的结束,
64+
newbuff := make([]byte, len(data)-f) // 也是新的开始。
65+
if len(newbuff) == 0 {
66+
return vars, newbuff
67+
}
68+
copy(newbuff, data[f:]) // 留存残篇。
69+
return vars, newbuff // 变量的回音,仍有余音
6570
}
6671

6772
// 从茫茫 vars 中,寻找我所挂念的 to[RD] ,记录在列表 chart 中。
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
Log file created at: 2022/05/16 20:46:25
2+
Running on machine: LAPTOP-KLOCKHJ1
3+
Binary: Built with gc go1.18.1 for windows/amd64
4+
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
5+
I0516 20:46:25.318923 8312 jsonfile.go:27] C:\Users\bige\AppData\Roaming/asuwave/option.json Found
6+
I0516 20:46:25.327681 8312 opt_json.go:26] Set SaveVarList to true
7+
I0516 20:46:25.328191 8312 jsonfile.go:19] C:\Users\bige\AppData\Roaming/asuwave/vToRead.json save success.
8+
I0516 20:46:25.328736 8312 jsonfile.go:19] C:\Users\bige\AppData\Roaming/asuwave/vToWrite.json save success.
9+
I0516 20:46:25.328736 8312 opt_json.go:38] Set UpdateByProj to true
10+
I0516 20:46:25.328736 8312 jsonfile.go:27] C:\Users\bige\AppData\Roaming/asuwave/FileWatch.json Found
11+
I0516 20:46:25.329287 8312 watch.go:20] Get: []
12+
I0516 20:46:25.330158 8312 jsonfile.go:19] C:\Users\bige\AppData\Roaming/asuwave/FileWatch.json save success.
13+
I0516 20:46:25.330695 8312 jsonfile.go:19] C:\Users\bige\AppData\Roaming/asuwave/option.json save success.
14+
I0516 20:46:25.330695 8312 server.go:20] Listen on :8000
15+
I0516 20:46:25.331223 8312 serial.go:194] GrTransmit:
16+
I0516 20:46:31.905205 8312 server.go:52] [::1]:59751 POST /serial_cur
17+
I0516 20:46:31.905800 8312 testport.go:44] TestPort open at: 2022-05-16 20:46:25.3189231 +0800 CST m=+0.007091801
18+
I0516 20:46:31.906419 8312 serial.go:169] chOp...
19+
I0516 20:46:31.906933 8312 serial.go:177] GrReceive: default...
20+
I0516 20:46:32.036068 8312 serial.go:263] GrRxPrase: time after 200ms...
21+
I0516 20:46:32.036516 8312 serial.go:266] add: []
22+
I0516 20:46:32.238168 8312 serial.go:263] GrRxPrase: time after 200ms...
23+
I0516 20:46:32.238802 8312 serial.go:266] add: []
24+
I0516 20:46:32.441191 8312 serial.go:263] GrRxPrase: time after 200ms...
25+
I0516 20:46:32.442352 8312 serial.go:266] add: []
26+
I0516 20:46:32.659312 8312 serial.go:263] GrRxPrase: time after 200ms...
27+
I0516 20:46:32.659788 8312 serial.go:266] add: []
28+
I0516 20:46:32.862228 8312 serial.go:263] GrRxPrase: time after 200ms...
29+
I0516 20:46:32.862363 8312 serial.go:266] add: []
30+
I0516 20:46:33.065149 8312 serial.go:263] GrRxPrase: time after 200ms...
31+
I0516 20:46:33.065716 8312 serial.go:266] add: []
32+
I0516 20:46:33.267897 8312 serial.go:263] GrRxPrase: time after 200ms...
33+
I0516 20:46:33.268538 8312 serial.go:266] add: []
34+
I0516 20:46:33.469695 8312 serial.go:263] GrRxPrase: time after 200ms...
35+
I0516 20:46:33.470654 8312 serial.go:266] add: []
36+
I0516 20:46:33.671841 8312 serial.go:263] GrRxPrase: time after 200ms...
37+
I0516 20:46:33.671841 8312 serial.go:266] add: []
38+
I0516 20:46:33.875027 8312 serial.go:263] GrRxPrase: time after 200ms...
39+
I0516 20:46:33.875717 8312 serial.go:266] add: []
40+
I0516 20:46:34.078649 8312 serial.go:263] GrRxPrase: time after 200ms...
41+
I0516 20:46:34.079651 8312 serial.go:266] add: []
42+
I0516 20:46:34.284029 8312 serial.go:263] GrRxPrase: time after 200ms...
43+
I0516 20:46:34.284557 8312 serial.go:266] add: []
44+
I0516 20:46:34.485028 8312 serial.go:263] GrRxPrase: time after 200ms...
45+
I0516 20:46:34.485028 8312 serial.go:266] add: []
46+
I0516 20:46:34.700694 8312 serial.go:263] GrRxPrase: time after 200ms...
47+
I0516 20:46:34.701857 8312 serial.go:266] add: []
48+
I0516 20:46:34.903667 8312 serial.go:263] GrRxPrase: time after 200ms...
49+
I0516 20:46:34.904802 8312 serial.go:266] add: []
50+
I0516 20:46:35.108481 8312 serial.go:263] GrRxPrase: time after 200ms...
51+
I0516 20:46:35.108481 8312 serial.go:266] add: []
52+
I0516 20:46:35.310956 8312 serial.go:263] GrRxPrase: time after 200ms...
53+
I0516 20:46:35.311051 8312 serial.go:266] add: []
54+
I0516 20:46:35.512534 8312 serial.go:263] GrRxPrase: time after 200ms...
55+
I0516 20:46:35.514287 8312 serial.go:266] add: []
56+
I0516 20:46:35.730834 8312 serial.go:263] GrRxPrase: time after 200ms...
57+
I0516 20:46:35.732248 8312 serial.go:266] add: []
58+
I0516 20:46:35.948226 8312 serial.go:263] GrRxPrase: time after 200ms...
59+
I0516 20:46:35.948226 8312 serial.go:266] add: []
60+
I0516 20:46:36.151686 8312 serial.go:263] GrRxPrase: time after 200ms...
61+
I0516 20:46:36.151794 8312 serial.go:266] add: []
62+
I0516 20:46:36.354983 8312 serial.go:263] GrRxPrase: time after 200ms...
63+
I0516 20:46:36.355592 8312 serial.go:266] add: []
64+
I0516 20:46:36.557329 8312 serial.go:263] GrRxPrase: time after 200ms...
65+
I0516 20:46:36.557380 8312 serial.go:266] add: []
66+
I0516 20:46:36.758779 8312 serial.go:263] GrRxPrase: time after 200ms...
67+
I0516 20:46:36.759050 8312 serial.go:266] add: []
68+
I0516 20:46:36.965070 8312 serial.go:263] GrRxPrase: time after 200ms...
69+
I0516 20:46:36.965859 8312 serial.go:266] add: []
70+
I0516 20:46:37.181962 8312 serial.go:263] GrRxPrase: time after 200ms...
71+
I0516 20:46:37.182027 8312 serial.go:266] add: []
72+
I0516 20:46:37.383102 8312 serial.go:263] GrRxPrase: time after 200ms...
73+
I0516 20:46:37.383906 8312 serial.go:266] add: []
74+
I0516 20:46:37.585980 8312 serial.go:263] GrRxPrase: time after 200ms...
75+
I0516 20:46:37.586272 8312 serial.go:266] add: []
76+
I0516 20:46:37.789358 8312 serial.go:263] GrRxPrase: time after 200ms...
77+
I0516 20:46:37.789787 8312 serial.go:266] add: []
78+
I0516 20:46:37.991618 8312 serial.go:263] GrRxPrase: time after 200ms...
79+
I0516 20:46:37.991800 8312 serial.go:266] add: []
80+
I0516 20:46:38.193340 8312 serial.go:263] GrRxPrase: time after 200ms...
81+
I0516 20:46:38.193340 8312 serial.go:266] add: []
82+
I0516 20:46:38.398070 8312 serial.go:263] GrRxPrase: time after 200ms...
83+
I0516 20:46:38.398070 8312 serial.go:266] add: []
84+
I0516 20:46:38.600907 8312 serial.go:263] GrRxPrase: time after 200ms...
85+
I0516 20:46:38.601731 8312 serial.go:266] add: []
86+
I0516 20:46:38.804611 8312 serial.go:263] GrRxPrase: time after 200ms...
87+
I0516 20:46:38.805186 8312 serial.go:266] add: []
88+
I0516 20:46:39.007430 8312 serial.go:263] GrRxPrase: time after 200ms...
89+
I0516 20:46:39.008337 8312 serial.go:266] add: []
90+
I0516 20:46:39.213148 8312 serial.go:263] GrRxPrase: time after 200ms...
91+
I0516 20:46:39.214076 8312 serial.go:266] add: []
92+
I0516 20:46:39.416793 8312 serial.go:263] GrRxPrase: time after 200ms...
93+
I0516 20:46:39.416793 8312 serial.go:266] add: []
94+
I0516 20:46:39.620344 8312 serial.go:263] GrRxPrase: time after 200ms...
95+
I0516 20:46:39.620491 8312 serial.go:266] add: []
96+
I0516 20:46:39.835547 8312 serial.go:263] GrRxPrase: time after 200ms...
97+
I0516 20:46:39.835547 8312 serial.go:266] add: []
98+
I0516 20:46:40.052549 8312 serial.go:263] GrRxPrase: time after 200ms...
99+
I0516 20:46:40.053813 8312 serial.go:266] add: []
100+
I0516 20:46:40.108263 8312 server.go:52] [::1]:59751 POST /variable_read
101+
I0516 20:46:40.109113 8312 jsonfile.go:19] C:\Users\bige\AppData\Roaming/asuwave/vToRead.json save success.
102+
I0516 20:46:40.122661 8312 server.go:52] [::1]:59751 GET /variable_read
103+
I0516 20:46:40.270033 8312 serial.go:263] GrRxPrase: time after 200ms...
104+
I0516 20:46:40.271070 8312 serial.go:266] add: [{1 8 556998961 0 [0 0 0 0 0 0 0 0]}]
105+
I0516 20:46:40.272756 8312 serial.go:159] Send cmd 1 {1 8 556998961 0 [0 0 0 0 0 0 0 0]}
106+
I0516 20:46:40.273839 8312 serial.go:196] GrTransmit: got chTx...
107+
I0516 20:46:40.274991 8312 serial.go:101] serial port write: [1 1 8 49 33 51 33 0 0 0 0 0 0 0 0 10]
108+
I0516 20:46:40.276084 8312 testport.go:141] Got write: board = 1
109+
I0516 20:46:40.276746 8312 testport.go:143] Got write: act = 1
110+
I0516 20:46:40.278658 8312 testport.go:145] Got write: length = 8
111+
I0516 20:46:40.280915 8312 testport.go:147] Got write: address = 556998961
112+
I0516 20:46:40.285145 8312 serial.go:194] GrTransmit:
113+
I0516 20:46:40.488225 8312 serial.go:263] GrRxPrase: time after 200ms...
114+
I0516 20:46:40.489202 8312 serial.go:266] add: [{1 8 556998961 0 [0 0 0 0 0 0 0 0]}]
115+
I0516 20:46:40.490118 8312 serial.go:144] Has sent subscribe cmd recently {1 8 556998961 0 [0 0 0 0 0 0 0 0]}
116+
I0516 20:46:40.706251 8312 serial.go:263] GrRxPrase: time after 200ms...
117+
I0516 20:46:40.706467 8312 serial.go:266] add: [{1 8 556998961 0 [0 0 0 0 0 0 0 0]}]
118+
I0516 20:46:40.708376 8312 serial.go:144] Has sent subscribe cmd recently {1 8 556998961 0 [0 0 0 0 0 0 0 0]}
119+
I0516 20:46:40.785319 8312 testport.go:155] Adding address: 21332131
120+
I0516 20:46:40.785319 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 106 60 0 0 10 192]
121+
I0516 20:46:40.786535 8312 serial.go:184] GrReceive: send chRx...
122+
I0516 20:46:40.786625 8312 serial.go:210] GrRxPrase: got chRx...
123+
I0516 20:46:40.787145 8312 serial.go:212] had buff: []
124+
I0516 20:46:40.787691 8312 serial.go:216] got buff: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 106 60 0 0 10 192]
125+
I0516 20:46:40.787691 8312 filt.go:40] [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 106 60 0 0 10 192]
126+
I0516 20:46:40.788352 8312 filt.go:46] [1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 106 60 0 0 10]
127+
I0516 20:46:40.788865 8312 serial.go:224] left buff: []
128+
I0516 20:46:40.788919 8312 serial.go:225] got vars: [{1 8 556998961 15466 [0 0 0 0 0 0 0 0]}]
129+
I0516 20:46:40.801214 8312 serial.go:177] GrReceive: default...
130+
I0516 20:46:40.801416 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 122 60 0 0 10 192]
131+
I0516 20:46:40.801995 8312 serial.go:184] GrReceive: send chRx...
132+
I0516 20:46:40.817207 8312 serial.go:177] GrReceive: default...
133+
I0516 20:46:40.817767 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 138 60 0 0 10 192]
134+
I0516 20:46:40.818420 8312 serial.go:184] GrReceive: send chRx...
135+
I0516 20:46:40.832520 8312 serial.go:177] GrReceive: default...
136+
I0516 20:46:40.833682 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 154 60 0 0 10 192]
137+
I0516 20:46:40.834274 8312 serial.go:184] GrReceive: send chRx...
138+
I0516 20:46:40.847854 8312 serial.go:177] GrReceive: default...
139+
I0516 20:46:40.848245 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 169 60 0 0 10 192]
140+
I0516 20:46:40.849783 8312 serial.go:184] GrReceive: send chRx...
141+
I0516 20:46:40.875660 8312 serial.go:177] GrReceive: default...
142+
I0516 20:46:40.896117 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 217 60 0 0 10 192]
143+
I0516 20:46:40.903626 8312 serial.go:184] GrReceive: send chRx...
144+
I0516 20:46:40.925364 8312 serial.go:177] GrReceive: default...
145+
I0516 20:46:40.925466 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 246 60 0 0 10 192]
146+
I0516 20:46:40.925466 8312 serial.go:184] GrReceive: send chRx...
147+
I0516 20:46:40.941014 8312 serial.go:177] GrReceive: default...
148+
I0516 20:46:40.942537 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 6 61 0 0 10 192]
149+
I0516 20:46:40.943305 8312 serial.go:184] GrReceive: send chRx...
150+
I0516 20:46:40.956934 8312 serial.go:177] GrReceive: default...
151+
I0516 20:46:40.957615 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 22 61 0 0 10 192]
152+
I0516 20:46:40.957615 8312 serial.go:184] GrReceive: send chRx...
153+
I0516 20:46:40.972801 8312 serial.go:177] GrReceive: default...
154+
I0516 20:46:40.972979 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 38 61 0 0 10 192]
155+
I0516 20:46:40.973490 8312 serial.go:184] GrReceive: send chRx...
156+
I0516 20:46:40.988042 8312 serial.go:177] GrReceive: default...
157+
I0516 20:46:40.988177 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 53 61 0 0 10 192]
158+
I0516 20:46:40.988687 8312 serial.go:184] GrReceive: send chRx...
159+
I0516 20:46:41.003248 8312 serial.go:177] GrReceive: default...
160+
I0516 20:46:41.004526 8312 serial.go:182] GrReceive b: [192 1 2 8 49 33 51 33 0 0 0 0 0 0 0 0 69 61 0 0 10 192]
161+
I0516 20:46:48.627657 8312 server.go:52] [::1]:59751 POST /variable_read
162+
I0516 20:46:48.630326 8312 jsonfile.go:19] C:\Users\bige\AppData\Roaming/asuwave/vToRead.json save success.
163+
I0516 20:46:48.646726 8312 server.go:52] [::1]:59751 GET /variable_read

0 commit comments

Comments
 (0)