Commit 222bf65b5a704cb02bb7ce40e8fc91a7c67327d6

Authored by 김태훈
1 parent 1ff9159b3d
Exists in master and in 2 other branches fhd, fhd-demo

프로토콜 변경 대응 수정

app/modbus-data-viewer/src/service-web/main.go
... ... @@ -14,11 +14,51 @@ import (
14 14 )
15 15  
16 16 type Header int32
17   -type Packet [50]uint16
  17 +type ControlPacket [50]uint16
  18 +type StatePacket [73]uint16
18 19  
19 20 var mutex sync.Mutex
20 21 var templateMap = make(map[string]interface{})
21   -var controlTable, stateTable string
  22 +var controlDesc [50]string
  23 +var stateDesc [73]string
  24 +
  25 +func init() {
  26 + controlDesc[5] = "Oven Mode"
  27 + controlDesc[6] = "Cook On/Off"
  28 + controlDesc[7] = "Wash On/Off"
  29 + controlDesc[8] = "System On/Off"
  30 + controlDesc[9] = "Temp"
  31 + controlDesc[10] = "Humidity"
  32 + controlDesc[11] = "Time"
  33 + controlDesc[12] = "Preheat On/Off"
  34 + controlDesc[15] = "Convection RPM"
  35 + controlDesc[16] = "Cooldown On/Off"
  36 + controlDesc[17] = "Core Temp"
  37 + controlDesc[20] = "Wash Type"
  38 + controlDesc[21] = "Wash Total"
  39 + controlDesc[22] = "Wash Steps"
  40 + controlDesc[23] = "Wash Step Type"
  41 +
  42 + stateDesc[0] = "Firmware Y"
  43 + stateDesc[1] = "Firmware Y"
  44 + stateDesc[2] = "Firmware M"
  45 + stateDesc[3] = "Firmware D"
  46 + stateDesc[4] = "Cook State"
  47 + stateDesc[5] = "Temp Setting"
  48 + stateDesc[6] = "Humidity Setting"
  49 + stateDesc[7] = "Time Setting"
  50 + stateDesc[8] = "Temp Value"
  51 + stateDesc[9] = "Humidity Value"
  52 + stateDesc[10] = "Time Value"
  53 + stateDesc[11] = "Wash State"
  54 + stateDesc[12] = "Wash Type"
  55 + stateDesc[13] = "Wash Steps"
  56 + stateDesc[16] = "Door Open/Close"
  57 + stateDesc[32] = "Core Temp 1"
  58 + stateDesc[33] = "Core Temp 2"
  59 + stateDesc[34] = "Core Temp 3"
  60 + stateDesc[35] = "Core Temp 4"
  61 +}
22 62  
23 63 func main() {
24 64 go ListenUDP()
... ... @@ -64,40 +104,54 @@ func ListenUDP() {
64 104 log.Fatal(err)
65 105 }
66 106  
67   - var packet Packet
68   - err = binary.Read(buf, binary.LittleEndian, &packet)
69   - if err != nil {
70   - log.Fatal(err)
71   - }
72   -
73 107 switch header {
74 108 case 0:
  109 + var packet ControlPacket
  110 + err = binary.Read(buf, binary.LittleEndian, &packet)
  111 + if err != nil {
  112 + log.Fatal(err)
  113 + }
75 114 mapControl(packet)
76 115 case 1:
  116 + var packet StatePacket
  117 + err = binary.Read(buf, binary.LittleEndian, &packet)
  118 + if err != nil {
  119 + log.Fatal(err)
  120 + }
77 121 mapState(packet)
78 122 }
79 123 }
80 124 }
81 125  
82   -func mapControl(packet Packet) {
  126 +func mapControl(packet ControlPacket) {
83 127 mutex.Lock()
84 128 defer mutex.Unlock()
85 129  
86   - controlTable = ""
  130 + var controlTable string
87 131 for i, v := range packet {
88   - controlTable += fmt.Sprintf("<tr><td>%v</td><td>0x%04X</td><td>0x%04X</td><td>%d</td></tr>\n", 40001+i, i, v, v)
  132 + class := "odd"
  133 + if i%2 == 0 {
  134 + class = "even"
  135 + }
  136 +
  137 + controlTable += fmt.Sprintf("<tr class=\"%v\"><td>%v</td><td>0x%04X</td><td>0x%04X</td><td>%d</td><td>%v</td></tr>\n", class, 40001+i, i, v, v, controlDesc[i])
89 138 }
90 139  
91 140 templateMap["Table_Control"] = template.HTML(controlTable)
92 141 }
93 142  
94   -func mapState(packet Packet) {
  143 +func mapState(packet StatePacket) {
95 144 mutex.Lock()
96 145 defer mutex.Unlock()
97 146  
98   - stateTable = ""
  147 + var stateTable string
99 148 for i, v := range packet {
100   - stateTable += fmt.Sprintf("<tr><td>%v</td><td>0x%04X</td><td>0x%04X</td><td>%d</td></tr>\n", 30001+i, i, v, v)
  149 + class := "odd"
  150 + if i%2 == 0 {
  151 + class = "even"
  152 + }
  153 +
  154 + stateTable += fmt.Sprintf("<tr class=\"%v\"><td>%v</td><td>0x%04X</td><td>0x%04X</td><td>%d</td><td>%v</td></tr>\n", class, 30001+i, i, v, v, stateDesc[i])
101 155 }
102 156  
103 157 templateMap["Table_State"] = template.HTML(stateTable)
... ...
app/modbus-data-viewer/src/service-web/templates/main.tmpl
... ... @@ -2,45 +2,38 @@
2 2 <html lang="en">
3 3 <head>
4 4 <style>
5   -th, td { padding: 0.5em }
6   -table.data
  5 +th, td { padding: 0.5em; }
  6 +table
7 7 {
8 8 display: inline-block;
  9 + vertical-align: top;
9 10 text-align: right;
10 11 font-family: monospace;
11 12 font-size: 1.2em;
12 13 border: 1px solid black;
  14 + border-collapse: collapse;
13 15 }
  16 +tr:nth-child(even) { background-color: #EEE; }
14 17 </style>
15 18 </head>
16 19 <body>
17   - <table class="data">
  20 + <table>
18 21 <tr>
19   - <th>Address</th>
20   - <th>Address</th>
21   - <th>Value</th>
22   - <th>Value</th>
23   - </tr>
24   - <tr>
25   - <th>(Dec)</th>
26   - <th>(Hex)</th>
27   - <th>(Hex)</th>
28   - <th>(Dec)</th>
  22 + <th>Address<br />(Dec)</th>
  23 + <th>Address<br />(Hex)</th>
  24 + <th>Value<br />(Hex)</th>
  25 + <th>Value<br />(Dec)</th>
  26 + <th>Description</th>
29 27 </tr>
30 28 {{.Table_Control}}
31 29 </table>
32   - <table class="data">
33   - <tr>
34   - <th>Address</th>
35   - <th>Address</th>
36   - <th>Value</th>
37   - <th>Value</th>
38   - </tr>
  30 + <table>
39 31 <tr>
40   - <th>(Dec)</th>
41   - <th>(Hex)</th>
42   - <th>(Hex)</th>
43   - <th>(Dec)</th>
  32 + <th>Address<br />(Dec)</th>
  33 + <th>Address<br />(Hex)</th>
  34 + <th>Value<br />(Hex)</th>
  35 + <th>Value<br />(Dec)</th>
  36 + <th>Description</th>
44 37 </tr>
45 38 {{.Table_State}}
46 39 </table>
... ...