-
Notifications
You must be signed in to change notification settings - Fork 0
/
dto.go
152 lines (124 loc) · 3.26 KB
/
dto.go
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Define Data type in this file
package serial
import (
"fmt"
"time"
)
// All response data from sensor has to follow(implement) this interface.
type SensorData interface {
print()
}
// Define new data type as itself to implement interface
type TemperatureData float64
type HumidityData float64
type PressureData float64
type LightData int8
type BroadbandData float64
type TimeSeriesData struct {
Time time.Time
Data map[byte]SensorData
}
// Define type for multiple threads to use channel to access map data type
type MapWriteData struct {
Key byte
Value SensorData
}
type TiltData struct {
XAxis int64
YAxis int64
ZAxis int64
}
// It could be VibrationX, VibrationY, and also VibratoinY
type VibrationData struct {
Axis byte
Peak [6]int64
Amp [6]float64
}
type SoundData struct {
Peak [6]int64
Amp [6]float64
}
func (temperatureData TemperatureData) print() {
fmt.Printf("Temperature: %+v(℃)\n", temperatureData)
}
func (humidity HumidityData) print() {
fmt.Printf("Humidity: %+v(%%)\n", humidity)
}
func (pressure PressureData) print() {
fmt.Printf("Pressure: %+v(hPa)\n", pressure)
}
func (tiltData *TiltData) print() {
if tiltData == nil {
fmt.Printf("tiltData is nil\n")
return
}
fmt.Println("Tilt data below")
fmt.Printf("XAxis: %+v\n", tiltData.XAxis)
fmt.Printf("YAxis: %+v\n", tiltData.YAxis)
fmt.Printf("ZAxis: %+v\n", tiltData.ZAxis)
}
func (vibrationData *VibrationData) print() {
if vibrationData == nil {
fmt.Printf("vibrationData is nil\n")
return
}
var axis string
if vibrationData.Axis == VibrationXASCIICmd {
axis = "X"
} else if vibrationData.Axis == VibrationYASCIICmd {
axis = "Y"
} else {
axis = "Z"
}
fmt.Printf("Vibration%+v data below\n", axis)
fmt.Printf("Fund%+v: %+v(Hz)\t", axis, vibrationData.Peak[0])
fmt.Printf("Amp%+v: %+v\n", axis, vibrationData.Amp[0])
for i := 1; i < 6; i++ {
fmt.Printf("Peak%+v%d: %+v(Hz)\t", axis, i+1, vibrationData.Peak[i])
fmt.Printf("Amp%+v: %+v\n", axis, vibrationData.Amp[i])
}
}
func (lightData LightData) print() {
fmt.Printf("Light: %+v\n", lightData)
}
func (soundData *SoundData) print() {
if soundData == nil {
fmt.Printf("soundData is nil\n")
return
}
fmt.Println("Sound data below")
fmt.Printf("Fund: %+v(Hz)\t", soundData.Peak[0])
fmt.Printf("Amp: %+v\n", soundData.Amp[0])
for i := 1; i < 6; i++ {
fmt.Printf("Peak%d: %+v(Hz)\t", i+1, soundData.Peak[i])
fmt.Printf("Amp: %+v\n", soundData.Amp[i])
}
}
func (broadbanddata BroadbandData) print() {
fmt.Printf("Broadband: %+v\n", broadbanddata)
}
// do not use anymore since https://github.com/w00cheol/serial/commit/15d0f2690c37e121818a7f6ab7a93cb38d895186
// type AllData struct {
// Temperature TemperatureData
// Humidity HumidityData
// Pressure PressureData
// Tilt *TiltData
// VibrationX *VibrationData
// VibrationY *VibrationData
// VibrationZ *VibrationData
// Light LightData
// Sound *SoundData
// Broadband BroadbandData
// }
// func (allData *AllData) print() {
// allData.Temperature.print()
// allData.Humidity.print()
// allData.Pressure.print()
// allData.Tilt.print()
// allData.VibrationX.print()
// allData.VibrationY.print()
// allData.VibrationZ.print()
// allData.Light.print()
// allData.Sound.print()
// allData.Broadband.print()
// }