-
Notifications
You must be signed in to change notification settings - Fork 2
/
bandwidth_log.go
48 lines (40 loc) · 919 Bytes
/
bandwidth_log.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
package homehub
import (
"strconv"
"strings"
)
// BandwidthLog defines a Home Hub device bandwidth log history
type BandwidthLog struct {
Entries []BandwidthLogEntry
}
// BandwidthLogEntry defines a Home Hub bandwidth log entry
type BandwidthLogEntry struct {
MACAddress string
Date string
DownloadMegabytes int
UploadMegabytes int
}
func parseBandwidthLogEntry(logEntry string) *BandwidthLogEntry {
entry := strings.Split(logEntry, ",")
if len(entry) >= 5 {
var messageParts []string
for i := 0; i < len(entry); i++ {
messageParts = append(messageParts, entry[i])
}
downloaded, downloadedErr := strconv.Atoi(entry[3])
if downloadedErr != nil {
downloaded = 0
}
uploaded, uploadedErr := strconv.Atoi(entry[4])
if uploadedErr != nil {
uploaded = 0
}
return &BandwidthLogEntry{
entry[1],
entry[2],
downloaded,
uploaded,
}
}
return nil
}