Skip to content

Commit 1384b01

Browse files
authored
Modernize code, apply newer Go conventions (#5)
1 parent 9bc050e commit 1384b01

File tree

15 files changed

+90
-83
lines changed

15 files changed

+90
-83
lines changed

bin/gopro2gpx/gopro2gpx.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func main() {
3030
}
3131
defer telemFile.Close()
3232

33-
t := &telemetry.TELEM{}
34-
t_prev := &telemetry.TELEM{}
33+
t := &telemetry.Telem{}
34+
t_prev := &telemetry.Telem{}
3535

3636
track := new(gpx.GPXTrack)
3737
segment := new(gpx.GPXTrackSegment)
@@ -54,9 +54,9 @@ func main() {
5454

5555
// process until t.Time
5656
t_prev.FillTimes(t.Time.Time)
57-
telems := t_prev.ShitJson()
57+
telems := t_prev.Json()
5858

59-
for i, _ := range telems {
59+
for i := range telems {
6060
segment.AppendPoint(
6161
&gpx.GPXPoint{
6262
Point: gpx.Point{
@@ -70,7 +70,7 @@ func main() {
7070
}
7171

7272
*t_prev = *t
73-
t = &telemetry.TELEM{}
73+
t = &telemetry.Telem{}
7474
}
7575

7676
track.AppendSegment(segment)
@@ -91,5 +91,14 @@ func main() {
9191
}(gpxFile)
9292

9393
xml, err := gpxData.ToXml(gpx.ToXmlParams{Version: "1.1", Indent: true})
94-
gpxFile.Write(xml)
94+
if err != nil {
95+
fmt.Printf("Cannot write to gpx file %s: %s", *outName, err)
96+
os.Exit(1)
97+
}
98+
99+
_, err = gpxFile.Write(xml)
100+
if err != nil {
101+
fmt.Printf("Cannot write to gpx file %s: %s", *outName, err)
102+
os.Exit(1)
103+
}
95104
}

bin/gopro2json/gopro2json.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
type data struct {
14-
Data []telemetry.TELEM_OUT `json:"data"`
14+
Data []telemetry.TelemOut `json:"data"`
1515
}
1616

1717
func main() {
@@ -33,8 +33,8 @@ func main() {
3333

3434
var d data
3535

36-
t := &telemetry.TELEM{}
37-
t_prev := &telemetry.TELEM{}
36+
t := &telemetry.Telem{}
37+
t_prev := &telemetry.Telem{}
3838

3939
for {
4040
t, err = telemetry.Read(telemFile)
@@ -55,11 +55,11 @@ func main() {
5555
// process until t.Time
5656
t_prev.FillTimes(t.Time.Time)
5757

58-
telems := t_prev.ShitJson()
58+
telems := t_prev.Json()
5959
d.Data = append(d.Data, telems...)
6060

6161
*t_prev = *t
62-
t = &telemetry.TELEM{}
62+
t = &telemetry.Telem{}
6363
}
6464

6565
jsonFile, err := os.Create(*outName)

bin/gpmdinfo/gpmdinfo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
}(telemFile)
3434

3535
// currently processing sentence
36-
t := &telemetry.TELEM{}
36+
t := &telemetry.Telem{}
3737

3838
for {
3939
t, err = telemetry.Read(telemFile)
@@ -53,6 +53,6 @@ func main() {
5353
// or mangle it to your wishes into JSON/CSV/format of choice
5454
fmt.Println(t)
5555

56-
t = &telemetry.TELEM{}
56+
t = &telemetry.Telem{}
5757
}
5858
}

gpmf/gpmf.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (scale *SCAL) Parse(bytes []byte, size int64) error {
150150
s := int(size)
151151

152152
// No left over bytes
153-
if 0 != len(bytes)%s {
153+
if len(bytes)%s != 0 {
154154
return errors.New("SCAL: Invalid packet length")
155155
}
156156

@@ -174,7 +174,7 @@ func (scale *SCAL) Parse(bytes []byte, size int64) error {
174174
// Parse (ACCL) - Parse byte slice into ACCL struct and scale
175175
func (accl *ACCL) Parse(bytes []byte, scale *SCAL) error {
176176
// Check length
177-
if 6 != len(bytes) {
177+
if len(bytes) != 6 {
178178
return errors.New("ACCL: Invalid packet length")
179179
}
180180

@@ -190,7 +190,7 @@ func (accl *ACCL) Parse(bytes []byte, scale *SCAL) error {
190190
// Parse (GYRO) - Parse byte slice into GYRO struct and scale
191191
func (gyro *GYRO) Parse(bytes []byte, scale *SCAL) error {
192192
// Check length
193-
if 6 != len(bytes) {
193+
if len(bytes) != 6 {
194194
return errors.New("GYRO: Invalid packet length")
195195
}
196196

@@ -206,8 +206,8 @@ func (gyro *GYRO) Parse(bytes []byte, scale *SCAL) error {
206206
// Parse (GPS5) - Parse byte slice into GPS5 struct and scale
207207
func (gps5 *GPS5) Parse(bytes []byte, scale *SCAL) error {
208208
// Check length
209-
if 20 != len(bytes) {
210-
return errors.New("GPS5: Inavlid packet length")
209+
if len(bytes) != 20 {
210+
return errors.New("GPS5: Invalid packet length")
211211
}
212212

213213
// Geodetic location
@@ -226,7 +226,7 @@ func (gps5 *GPS5) Parse(bytes []byte, scale *SCAL) error {
226226
// Parse (GPSF) - Parse byte slice into GPSF struct
227227
func (gpsf *GPSF) Parse(bytes []byte) error {
228228
// Check length
229-
if 4 != len(bytes) {
229+
if len(bytes) != 4 {
230230
return errors.New("GPSF: Invalid packet length")
231231
}
232232

@@ -240,7 +240,7 @@ func (gpsf *GPSF) Parse(bytes []byte) error {
240240
// Parse (GPSP) - Parse byte slice into GPSP struct
241241
func (gpsp *GPSP) Parse(bytes []byte) error {
242242
// Check length
243-
if 2 != len(bytes) {
243+
if len(bytes) != 2 {
244244
return errors.New("GPSP: Invalid packet length")
245245
}
246246

@@ -254,7 +254,7 @@ func (gpsp *GPSP) Parse(bytes []byte) error {
254254
// Parse (GPSU) - Parse byte slice int GPSU struct
255255
func (gpsu *GPSU) Parse(bytes []byte) error {
256256
// Check length
257-
if 16 != len(bytes) {
257+
if len(bytes) != 16 {
258258
return errors.New("GPSU: Invalid packet length")
259259
}
260260

@@ -274,7 +274,7 @@ func (gpsu *GPSU) Parse(bytes []byte) error {
274274
// Parse (TMPC) - Parse byte slice int TMPC struct
275275
func (tmpc *TMPC) Parse(bytes []byte) error {
276276
// Check length
277-
if 4 != len(bytes) {
277+
if len(bytes) != 4 {
278278
return errors.New("TMPC: Invalid packet length")
279279
}
280280

@@ -291,8 +291,8 @@ func (tmpc *TMPC) Parse(bytes []byte) error {
291291
// Parse (TSMP) - Parse byte slice int TSMP struct
292292
func (tsmp *TSMP) Parse(bytes []byte) error {
293293
// Check length
294-
if 4 != len(bytes) {
295-
return errors.New("Invalid length TSMP packet")
294+
if len(bytes) != 4 {
295+
return errors.New("invalid length TSMP packet")
296296
}
297297

298298
// Total number of sample

telemetry/accl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type ACCL struct {
1313
}
1414

1515
func (accl *ACCL) Parse(bytes []byte, scale *SCAL) error {
16-
if 6 != len(bytes) {
17-
return errors.New("Invalid length ACCL packet")
16+
if len(bytes) != 6 {
17+
return errors.New("invalid length ACCL packet")
1818
}
1919

2020
accl.X = float64(int16(binary.BigEndian.Uint16(bytes[0:2]))) / float64(scale.Values[0])

telemetry/gps5.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ type GPS5 struct {
1616
}
1717

1818
func (gps *GPS5) Parse(bytes []byte, scale *SCAL) error {
19-
if 20 != len(bytes) {
20-
return errors.New("Invalid length GPS5 packet")
19+
if len(bytes) != 20 {
20+
return errors.New("invalid length GPS5 packet")
2121
}
2222

2323
gps.Latitude = float64(int32(binary.BigEndian.Uint32(bytes[0:4]))) / float64(scale.Values[0])

telemetry/gpsf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type GPSF struct {
1111
}
1212

1313
func (gpsf *GPSF) Parse(bytes []byte) error {
14-
if 4 != len(bytes) {
15-
return errors.New("Invalid length GPSF packet")
14+
if len(bytes) != 4 {
15+
return errors.New("invalid length GPSF packet")
1616
}
1717

1818
gpsf.F = binary.BigEndian.Uint32(bytes[0:4])

telemetry/gpsp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type GPSP struct {
1111
}
1212

1313
func (gpsp *GPSP) Parse(bytes []byte) error {
14-
if 2 != len(bytes) {
15-
return errors.New("Invalid length GPSP packet")
14+
if len(bytes) != 2 {
15+
return errors.New("invalid length GPSP packet")
1616
}
1717

1818
gpsp.Accuracy = binary.BigEndian.Uint16(bytes[0:2])

telemetry/gpsu.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type GPSU struct {
1111
}
1212

1313
func (gpsu *GPSU) Parse(bytes []byte) error {
14-
if 16 != len(bytes) {
15-
return errors.New("Invalid length GPSU packet")
14+
if len(bytes) != 16 {
15+
return errors.New("invalid length GPSU packet")
1616
}
1717

1818
t, err := time.Parse("060102150405", string(bytes))

telemetry/gyro.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type GYRO struct {
1313
}
1414

1515
func (gyro *GYRO) Parse(bytes []byte, scale *SCAL) error {
16-
if 6 != len(bytes) {
17-
return errors.New("Invalid length GYRO packet")
16+
if len(bytes) != 6 {
17+
return errors.New("invalid length GYRO packet")
1818
}
1919

2020
gyro.X = float64(int16(binary.BigEndian.Uint16(bytes[0:2]))) / float64(scale.Values[0])

0 commit comments

Comments
 (0)