diff --git a/src/wasm/activity-service/activity/fit/activity.go b/src/wasm/activity-service/activity/fit/activity.go index e833976..bede8db 100644 --- a/src/wasm/activity-service/activity/fit/activity.go +++ b/src/wasm/activity-service/activity/fit/activity.go @@ -15,20 +15,20 @@ func createActivityMesg(timestamp time.Time, timezone int, sessionCount uint16) mesg := factory.CreateMesgOnly(mesgnum.Activity) activityTypeField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityType) - activityTypeField.Value = uint8(typedef.ActivityAutoMultiSport) + activityTypeField.Value = proto.Uint8(uint8(typedef.ActivityAutoMultiSport)) mesg.Fields = append(mesg.Fields, activityTypeField) timestampField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityTimestamp) - timestampField.Value = datetime.ToUint32(timestamp) + timestampField.Value = proto.Uint32(datetime.ToUint32(timestamp)) mesg.Fields = append(mesg.Fields, timestampField) localTimestamp := datetime.ToLocalTime(timestampField.Value, timezone) localTimestampField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityLocalTimestamp) - localTimestampField.Value = datetime.ToUint32(localTimestamp) + localTimestampField.Value = proto.Uint32(datetime.ToUint32(localTimestamp)) mesg.Fields = append(mesg.Fields, localTimestampField) sessionCountField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityNumSessions) - sessionCountField.Value = sessionCount + sessionCountField.Value = proto.Uint16(sessionCount) return mesg } diff --git a/src/wasm/activity-service/activity/fit/creator.go b/src/wasm/activity-service/activity/fit/creator.go index ee9e316..bc5db5a 100644 --- a/src/wasm/activity-service/activity/fit/creator.go +++ b/src/wasm/activity-service/activity/fit/creator.go @@ -21,16 +21,10 @@ func NewCreator(mesg proto.Message) activity.Creator { switch field.Num { case fieldnum.FileIdManufacturer: - manufacturer, ok := field.Value.(uint16) - if !ok { - continue - } + manufacturer := field.Value.Uint16() m.Manufacturer = &manufacturer case fieldnum.FileIdProduct: - product, ok := field.Value.(uint16) - if !ok { - continue - } + product := field.Value.Uint16() m.Product = &product case fieldnum.FileIdTimeCreated: m.TimeCreated = datetime.ToTime(field.Value) @@ -44,19 +38,19 @@ func convertCreatorToMesg(cre *activity.Creator) proto.Message { mesg := factory.CreateMesgOnly(mesgnum.FileId) fileTypeField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdType) - fileTypeField.Value = uint8(typedef.FileActivity) + fileTypeField.Value = proto.Uint8(uint8(typedef.FileActivity)) mesg.Fields = append(mesg.Fields, fileTypeField) manufacturerField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdManufacturer) - manufacturerField.Value = uint16(*cre.Manufacturer) + manufacturerField.Value = proto.Uint16(*cre.Manufacturer) mesg.Fields = append(mesg.Fields, manufacturerField) productField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdProduct) - productField.Value = uint16(*cre.Product) + productField.Value = proto.Uint16(*cre.Product) mesg.Fields = append(mesg.Fields, productField) timeCreatedField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdTimeCreated) - timeCreatedField.Value = datetime.ToUint32(cre.TimeCreated) + timeCreatedField.Value = proto.Uint32(datetime.ToUint32(cre.TimeCreated)) mesg.Fields = append(mesg.Fields, timeCreatedField) return mesg diff --git a/src/wasm/activity-service/activity/fit/lap.go b/src/wasm/activity-service/activity/fit/lap.go index 921db7c..5e8059a 100644 --- a/src/wasm/activity-service/activity/fit/lap.go +++ b/src/wasm/activity-service/activity/fit/lap.go @@ -25,88 +25,88 @@ func NewLap(mesg proto.Message) *activity.Lap { case fieldnum.LapStartTime: lap.StartTime = datetime.ToTime(field.Value) case fieldnum.LapTotalMovingTime: - totalMovingTime, ok := field.Value.(uint32) - if !ok || totalMovingTime == basetype.Uint32Invalid { + totalMovingTime := field.Value.Uint32() + if totalMovingTime == basetype.Uint32Invalid { continue } lap.TotalMovingTime = float64(totalMovingTime) / 1000 case fieldnum.LapTotalElapsedTime: - totalElapsedTime, ok := field.Value.(uint32) - if !ok || totalElapsedTime == basetype.Uint32Invalid { + totalElapsedTime := field.Value.Uint32() + if totalElapsedTime == basetype.Uint32Invalid { continue } lap.TotalElapsedTime = float64(totalElapsedTime) / 1000 case fieldnum.LapTotalDistance: - totalDistance, ok := field.Value.(uint32) - if !ok || totalDistance == basetype.Uint32Invalid { + totalDistance := field.Value.Uint32() + if totalDistance == basetype.Uint32Invalid { continue } lap.TotalDistance = float64(totalDistance) / 100 case fieldnum.LapTotalAscent: - totalAscent, ok := field.Value.(uint16) - if !ok || totalAscent == basetype.Uint16Invalid { + totalAscent := field.Value.Uint16() + if totalAscent == basetype.Uint16Invalid { continue } lap.TotalAscent = totalAscent case fieldnum.LapTotalDescent: - totalDescent, ok := field.Value.(uint16) - if !ok || totalDescent == basetype.Uint16Invalid { + totalDescent := field.Value.Uint16() + if totalDescent == basetype.Uint16Invalid { continue } lap.TotalDescent = totalDescent case fieldnum.LapTotalCalories: - totalCalories, ok := field.Value.(uint16) - if !ok || totalCalories == basetype.Uint16Invalid { + totalCalories := field.Value.Uint16() + if totalCalories == basetype.Uint16Invalid { continue } lap.TotalCalories = totalCalories case fieldnum.LapAvgSpeed: - avgSpeed, ok := field.Value.(uint16) - if !ok || avgSpeed == basetype.Uint16Invalid { + avgSpeed := field.Value.Uint16() + if avgSpeed == basetype.Uint16Invalid { continue } fAvgSpeed := float64(avgSpeed) / 1000 lap.AvgSpeed = &fAvgSpeed case fieldnum.LapMaxSpeed: - maxSpeed, ok := field.Value.(uint16) - if !ok || maxSpeed == basetype.Uint16Invalid { + maxSpeed := field.Value.Uint16() + if maxSpeed == basetype.Uint16Invalid { continue } fMaxSpeed := float64(maxSpeed) / 1000 lap.MaxSpeed = &fMaxSpeed case fieldnum.LapAvgCadence: - avgCadence, ok := field.Value.(uint8) - if !ok || avgCadence == basetype.Uint8Invalid { + avgCadence := field.Value.Uint8() + if avgCadence == basetype.Uint8Invalid { continue } lap.AvgCadence = &avgCadence case fieldnum.LapMaxCadence: - maxCadence, ok := field.Value.(uint8) - if !ok || maxCadence == basetype.Uint8Invalid { + maxCadence := field.Value.Uint8() + if maxCadence == basetype.Uint8Invalid { continue } lap.MaxCadence = &maxCadence case fieldnum.LapAvgHeartRate: - avgHeartRate, ok := field.Value.(uint8) - if !ok || avgHeartRate == basetype.Uint8Invalid { + avgHeartRate := field.Value.Uint8() + if avgHeartRate == basetype.Uint8Invalid { continue } lap.AvgHeartRate = &avgHeartRate case fieldnum.LapMaxHeartRate: - maxHeartRate, ok := field.Value.(uint8) - if !ok || maxHeartRate == basetype.Uint8Invalid { + maxHeartRate := field.Value.Uint8() + if maxHeartRate == basetype.Uint8Invalid { continue } lap.MaxHeartRate = &maxHeartRate case fieldnum.LapAvgPower: - avgPower, ok := field.Value.(uint16) - if !ok || avgPower == basetype.Uint16Invalid { + avgPower := field.Value.Uint16() + if avgPower == basetype.Uint16Invalid { continue } lap.AvgPower = &avgPower case fieldnum.LapMaxPower: - maxPower, ok := field.Value.(uint16) - if !ok || maxPower == basetype.Uint16Invalid { + maxPower := field.Value.Uint16() + if maxPower == basetype.Uint16Invalid { continue } lap.MaxPower = &maxPower @@ -121,12 +121,12 @@ func convertLapToMesg(lap *activity.Lap) proto.Message { if !lap.Timestamp.IsZero() { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTimestamp) - field.Value = datetime.ToUint32(lap.Timestamp) + field.Value = proto.Uint32(datetime.ToUint32(lap.Timestamp)) mesg.Fields = append(mesg.Fields, field) } if !lap.StartTime.IsZero() { field := factory.CreateField(mesgnum.Lap, fieldnum.LapStartTime) - field.Value = datetime.ToUint32(lap.StartTime) + field.Value = proto.Uint32(datetime.ToUint32(lap.StartTime)) mesg.Fields = append(mesg.Fields, field) } if lap.Sport != "" { @@ -135,17 +135,17 @@ func convertLapToMesg(lap *activity.Lap) proto.Message { sport = typedef.SportGeneric } field := factory.CreateField(mesgnum.Lap, fieldnum.LapSport) - field.Value = uint8(sport) + field.Value = proto.Uint8(uint8(sport)) mesg.Fields = append(mesg.Fields, field) } if lap.TotalMovingTime != 0 { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalMovingTime) - field.Value = scaleoffset.DiscardAny(lap.TotalMovingTime, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(lap.TotalMovingTime, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if lap.TotalElapsedTime != 0 { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalElapsedTime) - field.Value = scaleoffset.DiscardAny(lap.TotalElapsedTime, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(lap.TotalElapsedTime, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) totalTimerTimeField := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalTimerTime) @@ -154,91 +154,91 @@ func convertLapToMesg(lap *activity.Lap) proto.Message { } if lap.TotalDistance != 0 { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalDistance) - field.Value = scaleoffset.DiscardAny(lap.TotalDistance, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(lap.TotalDistance, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if lap.TotalAscent != 0 { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalAscent) - field.Value = lap.TotalAscent + field.Value = proto.Uint16(lap.TotalAscent) mesg.Fields = append(mesg.Fields, field) } if lap.TotalDescent != 0 { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalDescent) - field.Value = lap.TotalDescent + field.Value = proto.Uint16(lap.TotalDescent) mesg.Fields = append(mesg.Fields, field) } if lap.TotalCalories != 0 { field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalCalories) - field.Value = lap.TotalCalories + field.Value = proto.Uint16(lap.TotalCalories) mesg.Fields = append(mesg.Fields, field) } if lap.AvgSpeed != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgSpeed) - field.Value = scaleoffset.DiscardAny(*lap.AvgSpeed, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*lap.AvgSpeed, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if lap.MaxSpeed != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxSpeed) - field.Value = scaleoffset.DiscardAny(*lap.MaxSpeed, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*lap.MaxSpeed, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if lap.AvgHeartRate != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgHeartRate) - field.Value = *lap.AvgHeartRate + field.Value = proto.Uint8(*lap.AvgHeartRate) mesg.Fields = append(mesg.Fields, field) } if lap.MaxHeartRate != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxHeartRate) - field.Value = *lap.MaxHeartRate + field.Value = proto.Uint8(*lap.MaxHeartRate) mesg.Fields = append(mesg.Fields, field) } if lap.AvgCadence != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgCadence) - field.Value = *lap.AvgCadence + field.Value = proto.Uint8(*lap.AvgCadence) mesg.Fields = append(mesg.Fields, field) } if lap.MaxCadence != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxCadence) - field.Value = *lap.MaxCadence + field.Value = proto.Uint8(*lap.MaxCadence) mesg.Fields = append(mesg.Fields, field) } if lap.AvgPower != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgPower) - field.Value = *lap.AvgPower + field.Value = proto.Uint16(*lap.AvgPower) mesg.Fields = append(mesg.Fields, field) } if lap.MaxPower != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxPower) - field.Value = *lap.MaxPower + field.Value = proto.Uint16(*lap.MaxPower) mesg.Fields = append(mesg.Fields, field) } if lap.AvgTemperature != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgTemperature) - field.Value = *lap.AvgTemperature + field.Value = proto.Int8(*lap.AvgTemperature) mesg.Fields = append(mesg.Fields, field) } if lap.MaxTemperature != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxTemperature) - field.Value = *lap.MaxTemperature + field.Value = proto.Int8(*lap.MaxTemperature) mesg.Fields = append(mesg.Fields, field) } if lap.AvgAltitude != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgAltitude) - field.Value = scaleoffset.DiscardAny(*lap.AvgAltitude, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*lap.AvgAltitude, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if lap.MaxAltitude != nil { field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxAltitude) - field.Value = scaleoffset.DiscardAny(*lap.MaxAltitude, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*lap.MaxAltitude, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } eventField := factory.CreateField(mesgnum.Lap, fieldnum.LapEvent) - eventField.Value = uint8(typedef.EventLap) + eventField.Value = proto.Uint8(uint8(typedef.EventLap)) mesg.Fields = append(mesg.Fields, eventField) eventTypeField := factory.CreateField(mesgnum.Lap, fieldnum.LapEventType) - eventTypeField.Value = uint8(typedef.EventTypeStop) + eventTypeField.Value = proto.Uint8(uint8(typedef.EventTypeStop)) mesg.Fields = append(mesg.Fields, eventTypeField) return mesg diff --git a/src/wasm/activity-service/activity/fit/record.go b/src/wasm/activity-service/activity/fit/record.go index 150e056..1cb2318 100644 --- a/src/wasm/activity-service/activity/fit/record.go +++ b/src/wasm/activity-service/activity/fit/record.go @@ -23,20 +23,20 @@ func NewRecord(mesg proto.Message) *activity.Record { case fieldnum.RecordTimestamp: rec.Timestamp = datetime.ToTime(field.Value) case fieldnum.RecordPositionLat: - lat, ok := field.Value.(int32) - if !ok || lat == basetype.Sint32Invalid { + lat := field.Value.Int32() + if lat == basetype.Sint32Invalid { continue } rec.PositionLat = kit.Ptr(semicircles.ToDegrees(lat)) case fieldnum.RecordPositionLong: - long, ok := field.Value.(int32) - if !ok || long == basetype.Sint32Invalid { + long := field.Value.Int32() + if long == basetype.Sint32Invalid { continue } rec.PositionLong = kit.Ptr(semicircles.ToDegrees(long)) case fieldnum.RecordAltitude: - altitude, ok := field.Value.(uint16) - if !ok || altitude == basetype.Uint16Invalid { + altitude := field.Value.Uint16() + if altitude == basetype.Uint16Invalid { continue } faltitude := (float64(altitude) / 5) - 500 @@ -45,39 +45,39 @@ func NewRecord(mesg proto.Message) *activity.Record { } rec.Altitude = &faltitude case fieldnum.RecordHeartRate: - heartRate, ok := field.Value.(uint8) - if !ok || heartRate == basetype.Uint8Invalid { + heartRate := field.Value.Uint8() + if heartRate == basetype.Uint8Invalid { continue } rec.HeartRate = &heartRate case fieldnum.RecordCadence: - cadence, ok := field.Value.(uint8) - if !ok || cadence == basetype.Uint8Invalid { + cadence := field.Value.Uint8() + if cadence == basetype.Uint8Invalid { continue } rec.Cadence = &cadence case fieldnum.RecordDistance: - distance, ok := field.Value.(uint32) - if !ok || distance == basetype.Uint32Invalid { + distance := field.Value.Uint32() + if distance == basetype.Uint32Invalid { continue } rec.Distance = kit.Ptr(float64(distance) / 100) case fieldnum.RecordSpeed: - speed, ok := field.Value.(uint16) - if !ok || speed == basetype.Uint16Invalid { + speed := field.Value.Uint16() + if speed == basetype.Uint16Invalid { continue } rec.Speed = kit.Ptr(float64(speed) / 1000) case fieldnum.RecordPower: - power, ok := field.Value.(uint16) - if !ok || power == basetype.Uint16Invalid { + power := field.Value.Uint16() + if power == basetype.Uint16Invalid { continue } rec.Power = &power case fieldnum.RecordTemperature: - temperature, ok := field.Value.(int8) - if !ok || temperature == basetype.Sint8Invalid { + temperature := field.Value.Int8() + if temperature == basetype.Sint8Invalid { continue } rec.Temperature = &temperature @@ -92,52 +92,52 @@ func convertRecordToMesg(rec *activity.Record) proto.Message { if !rec.Timestamp.IsZero() { field := factory.CreateField(mesgnum.Record, fieldnum.RecordTimestamp) - field.Value = datetime.ToUint32(rec.Timestamp) + field.Value = proto.Uint32(datetime.ToUint32(rec.Timestamp)) mesg.Fields = append(mesg.Fields, field) } if rec.PositionLat != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordPositionLat) - field.Value = semicircles.ToSemicircles(*rec.PositionLat) + field.Value = proto.Int32(semicircles.ToSemicircles(*rec.PositionLat)) mesg.Fields = append(mesg.Fields, field) } if rec.PositionLong != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordPositionLong) - field.Value = semicircles.ToSemicircles(*rec.PositionLong) + field.Value = proto.Int32(semicircles.ToSemicircles(*rec.PositionLong)) mesg.Fields = append(mesg.Fields, field) } if rec.Distance != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordDistance) - field.Value = scaleoffset.DiscardAny(*rec.Distance, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*rec.Distance, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if rec.Altitude != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordAltitude) - field.Value = scaleoffset.DiscardAny(*rec.Altitude, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*rec.Altitude, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if rec.HeartRate != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordHeartRate) - field.Value = *rec.HeartRate + field.Value = proto.Uint8(*rec.HeartRate) mesg.Fields = append(mesg.Fields, field) } if rec.Cadence != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordCadence) - field.Value = *rec.Cadence + field.Value = proto.Uint8(*rec.Cadence) mesg.Fields = append(mesg.Fields, field) } if rec.Speed != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordSpeed) - field.Value = scaleoffset.DiscardAny(*rec.Speed, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*rec.Speed, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if rec.Power != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordPower) - field.Value = *rec.Power + field.Value = proto.Uint16(*rec.Power) mesg.Fields = append(mesg.Fields, field) } if rec.Temperature != nil { field := factory.CreateField(mesgnum.Record, fieldnum.RecordTemperature) - field.Value = *rec.Temperature + field.Value = proto.Int8(*rec.Temperature) mesg.Fields = append(mesg.Fields, field) } diff --git a/src/wasm/activity-service/activity/fit/service.go b/src/wasm/activity-service/activity/fit/service.go index 662faef..6aeb3b0 100644 --- a/src/wasm/activity-service/activity/fit/service.go +++ b/src/wasm/activity-service/activity/fit/service.go @@ -344,7 +344,7 @@ func (b *bytesBufferAt) WriteAt(p []byte, off int64) (n int, err error) { return } -func (s *service) convertActivityToFit(act *activity.Activity) *proto.Fit { +func (s *service) convertActivityToFit(act *activity.Activity) *proto.FIT { var lapCount, recordCount int sessionCount := len(act.Sessions) @@ -353,7 +353,7 @@ func (s *service) convertActivityToFit(act *activity.Activity) *proto.Fit { recordCount += len(act.Sessions[i].Records) } - fit := new(proto.Fit) + fit := new(proto.FIT) fit.Messages = make([]proto.Message, 0, sessionCount+lapCount+recordCount+2) // +2 for FileId and Activity messages filedIdMesg := convertCreatorToMesg(&act.Creator) // Must be first the message diff --git a/src/wasm/activity-service/activity/fit/session.go b/src/wasm/activity-service/activity/fit/session.go index cd85e8d..1dd9381 100644 --- a/src/wasm/activity-service/activity/fit/session.go +++ b/src/wasm/activity-service/activity/fit/session.go @@ -27,75 +27,75 @@ func NewSession(mesg proto.Message) *activity.Session { case fieldnum.SessionStartTime: ses.StartTime = datetime.ToTime(field.Value) case fieldnum.SessionSport: - sport, ok := field.Value.(uint8) - if !ok || sport == basetype.EnumInvalid { + sport := field.Value.Uint8() + if sport == basetype.EnumInvalid { continue } ses.Sport = kit.FormatTitle(typedef.Sport(sport).String()) case fieldnum.SessionTotalMovingTime: - totalMovingTime, ok := field.Value.(uint32) - if !ok || totalMovingTime == basetype.Uint32Invalid { + totalMovingTime := field.Value.Uint32() + if totalMovingTime == basetype.Uint32Invalid { continue } ses.TotalMovingTime = float64(totalMovingTime) / 1000 case fieldnum.SessionTotalElapsedTime: - totalElapsedTime, ok := field.Value.(uint32) - if !ok || totalElapsedTime == basetype.Uint32Invalid { + totalElapsedTime := field.Value.Uint32() + if totalElapsedTime == basetype.Uint32Invalid { continue } ses.TotalElapsedTime = float64(totalElapsedTime) / 1000 ses.EndTime = ses.StartTime.Add(time.Duration(ses.TotalElapsedTime) * time.Second) case fieldnum.SessionTotalDistance: - totalDistance, ok := field.Value.(uint32) - if !ok || totalDistance == basetype.Uint32Invalid { + totalDistance := field.Value.Uint32() + if totalDistance == basetype.Uint32Invalid { continue } ses.TotalDistance = float64(totalDistance) / 100 case fieldnum.SessionTotalAscent: - totalAscent, ok := field.Value.(uint16) - if !ok || totalAscent == basetype.Uint16Invalid { + totalAscent := field.Value.Uint16() + if totalAscent == basetype.Uint16Invalid { continue } ses.TotalAscent = totalAscent case fieldnum.SessionTotalDescent: - totalDescent, ok := field.Value.(uint16) - if !ok || totalDescent == basetype.Uint16Invalid { + totalDescent := field.Value.Uint16() + if totalDescent == basetype.Uint16Invalid { continue } ses.TotalDescent = totalDescent case fieldnum.SessionTotalCalories: - totalCalories, ok := field.Value.(uint16) - if !ok || totalCalories == basetype.Uint16Invalid { + totalCalories := field.Value.Uint16() + if totalCalories == basetype.Uint16Invalid { continue } ses.TotalCalories = totalCalories case fieldnum.SessionAvgSpeed: - avgSpeed, ok := field.Value.(uint16) - if !ok || avgSpeed == basetype.Uint16Invalid { + avgSpeed := field.Value.Uint16() + if avgSpeed == basetype.Uint16Invalid { continue } ses.AvgSpeed = kit.Ptr(float64(avgSpeed) / 1000) case fieldnum.SessionMaxSpeed: - maxSpeed, ok := field.Value.(uint16) - if !ok || maxSpeed == basetype.Uint16Invalid { + maxSpeed := field.Value.Uint16() + if maxSpeed == basetype.Uint16Invalid { continue } ses.MaxSpeed = kit.Ptr(float64(maxSpeed) / 1000) case fieldnum.SessionAvgHeartRate: - avgHeartRate, ok := field.Value.(uint8) - if !ok || avgHeartRate == basetype.Uint8Invalid { + avgHeartRate := field.Value.Uint8() + if avgHeartRate == basetype.Uint8Invalid { continue } ses.AvgHeartRate = &avgHeartRate case fieldnum.SessionMaxHeartRate: - maxHeartRate, ok := field.Value.(uint8) - if !ok || maxHeartRate == basetype.Uint8Invalid { + maxHeartRate := field.Value.Uint8() + if maxHeartRate == basetype.Uint8Invalid { continue } ses.MaxHeartRate = &maxHeartRate case fieldnum.SessionAvgCadence: - avgCadence, ok := field.Value.(uint8) - if !ok { + avgCadence := field.Value.Uint8() + if avgCadence != basetype.Uint8Invalid { continue } if avgCadence == basetype.Uint8Invalid { @@ -103,38 +103,38 @@ func NewSession(mesg proto.Message) *activity.Session { } ses.AvgCadence = &avgCadence case fieldnum.SessionMaxCadence: - maxCadence, ok := field.Value.(uint8) - if !ok || maxCadence == basetype.Uint8Invalid { + maxCadence := field.Value.Uint8() + if maxCadence == basetype.Uint8Invalid { continue } ses.MaxCadence = &maxCadence case fieldnum.SessionAvgPower: - avgPower, ok := field.Value.(uint16) - if !ok || avgPower == basetype.Uint16Invalid { + avgPower := field.Value.Uint16() + if avgPower == basetype.Uint16Invalid { continue } ses.AvgPower = &avgPower case fieldnum.SessionMaxPower: - maxPower, ok := field.Value.(uint16) - if !ok || maxPower == basetype.Uint16Invalid { + maxPower := field.Value.Uint16() + if maxPower == basetype.Uint16Invalid { continue } ses.MaxPower = &maxPower case fieldnum.SessionAvgTemperature: - avgTemperature, ok := field.Value.(int8) - if !ok || avgTemperature == basetype.Sint8Invalid { + avgTemperature := field.Value.Int8() + if avgTemperature == basetype.Sint8Invalid { continue } ses.AvgTemperature = &avgTemperature case fieldnum.SessionMaxTemperature: - maxTemperature, ok := field.Value.(int8) - if !ok || maxTemperature == basetype.Sint8Invalid { + maxTemperature := field.Value.Int8() + if maxTemperature == basetype.Sint8Invalid { continue } ses.MaxTemperature = &maxTemperature case fieldnum.SessionAvgAltitude: - avgAltitude, ok := field.Value.(uint16) - if !ok || avgAltitude == basetype.Uint16Invalid { + avgAltitude := field.Value.Uint16() + if avgAltitude == basetype.Uint16Invalid { continue } fAvgAltitude := (float64(avgAltitude) / 5) - 500 @@ -143,8 +143,8 @@ func NewSession(mesg proto.Message) *activity.Session { } ses.AvgAltitude = &fAvgAltitude case fieldnum.SessionMaxAltitude: - maxAltitude, ok := field.Value.(uint16) - if !ok || maxAltitude == basetype.Uint16Invalid { + maxAltitude := field.Value.Uint16() + if maxAltitude == basetype.Uint16Invalid { continue } fMaxAltitude := (float64(maxAltitude) / 5) - 500 @@ -167,12 +167,12 @@ func convertSessionToMesg(ses *activity.Session) proto.Message { if !ses.Timestamp.IsZero() { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTimestamp) - field.Value = datetime.ToUint32(ses.Timestamp) + field.Value = proto.Uint32(datetime.ToUint32(ses.Timestamp)) mesg.Fields = append(mesg.Fields, field) } if !ses.StartTime.IsZero() { field := factory.CreateField(mesgnum.Session, fieldnum.SessionStartTime) - field.Value = datetime.ToUint32(ses.StartTime) + field.Value = proto.Uint32(datetime.ToUint32(ses.StartTime)) mesg.Fields = append(mesg.Fields, field) } if ses.Sport != "" { @@ -181,17 +181,17 @@ func convertSessionToMesg(ses *activity.Session) proto.Message { sport = typedef.SportGeneric } field := factory.CreateField(mesgnum.Session, fieldnum.SessionSport) - field.Value = uint8(sport) + field.Value = proto.Uint8(uint8(sport)) mesg.Fields = append(mesg.Fields, field) } if ses.TotalMovingTime != 0 { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTotalMovingTime) - field.Value = scaleoffset.DiscardAny(ses.TotalMovingTime, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(ses.TotalMovingTime, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if ses.TotalElapsedTime != 0 { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTotalElapsedTime) - field.Value = scaleoffset.DiscardAny(ses.TotalElapsedTime, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(ses.TotalElapsedTime, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) totalTimerTimeField := factory.CreateField(mesgnum.Lap, fieldnum.SessionTotalElapsedTime) @@ -200,91 +200,91 @@ func convertSessionToMesg(ses *activity.Session) proto.Message { } if ses.TotalDistance != 0 { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTotalDistance) - field.Value = scaleoffset.DiscardAny(ses.TotalDistance, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(ses.TotalDistance, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if ses.TotalAscent != 0 { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTotalAscent) - field.Value = ses.TotalAscent + field.Value = proto.Uint16(ses.TotalAscent) mesg.Fields = append(mesg.Fields, field) } if ses.TotalDescent != 0 { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTotalDescent) - field.Value = ses.TotalDescent + field.Value = proto.Uint16(ses.TotalDescent) mesg.Fields = append(mesg.Fields, field) } if ses.TotalCalories != 0 { field := factory.CreateField(mesgnum.Session, fieldnum.SessionTotalCalories) - field.Value = ses.TotalCalories + field.Value = proto.Uint16(ses.TotalCalories) mesg.Fields = append(mesg.Fields, field) } if ses.AvgSpeed != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionAvgSpeed) - field.Value = scaleoffset.DiscardAny(*ses.AvgSpeed, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*ses.AvgSpeed, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if ses.MaxSpeed != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionMaxSpeed) - field.Value = scaleoffset.DiscardAny(*ses.MaxSpeed, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*ses.MaxSpeed, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if ses.AvgHeartRate != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionAvgHeartRate) - field.Value = *ses.AvgHeartRate + field.Value = proto.Uint8(*ses.AvgHeartRate) mesg.Fields = append(mesg.Fields, field) } if ses.MaxHeartRate != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionMaxHeartRate) - field.Value = *ses.MaxHeartRate + field.Value = proto.Uint8(*ses.MaxHeartRate) mesg.Fields = append(mesg.Fields, field) } if ses.AvgCadence != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionAvgCadence) - field.Value = *ses.AvgCadence + field.Value = proto.Uint8(*ses.AvgCadence) mesg.Fields = append(mesg.Fields, field) } if ses.MaxCadence != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionMaxCadence) - field.Value = *ses.MaxCadence + field.Value = proto.Uint8(*ses.MaxCadence) mesg.Fields = append(mesg.Fields, field) } if ses.AvgPower != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionAvgPower) - field.Value = *ses.AvgPower + field.Value = proto.Uint16(*ses.AvgPower) mesg.Fields = append(mesg.Fields, field) } if ses.MaxPower != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionMaxPower) - field.Value = *ses.MaxPower + field.Value = proto.Uint16(*ses.MaxPower) mesg.Fields = append(mesg.Fields, field) } if ses.AvgTemperature != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionAvgTemperature) - field.Value = *ses.AvgTemperature + field.Value = proto.Int8(*ses.AvgTemperature) mesg.Fields = append(mesg.Fields, field) } if ses.MaxTemperature != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionMaxTemperature) - field.Value = *ses.MaxTemperature + field.Value = proto.Int8(*ses.MaxTemperature) mesg.Fields = append(mesg.Fields, field) } if ses.AvgAltitude != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionAvgAltitude) - field.Value = scaleoffset.DiscardAny(*ses.AvgAltitude, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*ses.AvgAltitude, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } if ses.MaxAltitude != nil { field := factory.CreateField(mesgnum.Session, fieldnum.SessionMaxAltitude) - field.Value = scaleoffset.DiscardAny(*ses.MaxAltitude, field.Type.BaseType(), field.Scale, field.Offset) + field.Value = scaleoffset.DiscardValue(*ses.MaxAltitude, field.Type.BaseType(), field.Scale, field.Offset) mesg.Fields = append(mesg.Fields, field) } eventField := factory.CreateField(mesgnum.Session, fieldnum.SessionEvent) - eventField.Value = uint8(typedef.EventSession) + eventField.Value = proto.Uint8(uint8(typedef.EventSession)) mesg.Fields = append(mesg.Fields, eventField) eventTypeField := factory.CreateField(mesgnum.Session, fieldnum.SessionEventType) - eventTypeField.Value = uint8(typedef.EventTypeStop) + eventTypeField.Value = proto.Uint8(uint8(typedef.EventTypeStop)) mesg.Fields = append(mesg.Fields, eventTypeField) return mesg diff --git a/src/wasm/activity-service/activity/fit/timezone.go b/src/wasm/activity-service/activity/fit/timezone.go index 558a47b..c6fb45c 100644 --- a/src/wasm/activity-service/activity/fit/timezone.go +++ b/src/wasm/activity-service/activity/fit/timezone.go @@ -16,17 +16,9 @@ func CreateTimezone(mesg proto.Message) int { for i := range mesg.Fields { switch mesg.Fields[i].Num { case fieldnum.ActivityTimestamp: - t, ok := mesg.Fields[i].Value.(uint32) - if !ok { - continue - } - timestamp = t + timestamp = mesg.Fields[i].Value.Uint32() case fieldnum.ActivityLocalTimestamp: - t, ok := mesg.Fields[i].Value.(uint32) - if !ok { - continue - } - localDateTime = t + localDateTime = mesg.Fields[i].Value.Uint32() } } diff --git a/src/wasm/activity-service/go.mod b/src/wasm/activity-service/go.mod index fc5ef9d..71ae6e0 100644 --- a/src/wasm/activity-service/go.mod +++ b/src/wasm/activity-service/go.mod @@ -3,8 +3,8 @@ module github.com/muktihari/openactivity-fit go 1.20 require ( - github.com/muktihari/fit v0.11.1 - golang.org/x/text v0.13.0 + github.com/muktihari/fit v0.12.0 + golang.org/x/text v0.14.0 ) require golang.org/x/exp v0.0.0-20230905200255-921286631fa9 diff --git a/src/wasm/activity-service/go.sum b/src/wasm/activity-service/go.sum index 4d297de..803dbb1 100644 --- a/src/wasm/activity-service/go.sum +++ b/src/wasm/activity-service/go.sum @@ -1,9 +1,7 @@ -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/muktihari/fit v0.11.0 h1:7c2yB4H6V+gPu9qoRTkwtVksAbcZMhOWlOuKOX9D6ok= -github.com/muktihari/fit v0.11.0/go.mod h1:Y0S4wUVf9Kpv8IMwP31FGid7WtifT36mg+WMa8a4LqM= -github.com/muktihari/fit v0.11.1 h1:1CZ9Nm0fTnRtuc8TnEpztg6QU2eoYvphrfUcIaIuLoM= -github.com/muktihari/fit v0.11.1/go.mod h1:Y0S4wUVf9Kpv8IMwP31FGid7WtifT36mg+WMa8a4LqM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/muktihari/fit v0.12.0 h1:AuYaanpDuInk28eKXeVUE7zboCYPf8HHVu/GoHLBI84= +github.com/muktihari/fit v0.12.0/go.mod h1:a2O6nq7cANdTvVgH56v67tpOFT0tszHhgWTSOcopf1c= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=