updateGoGPSUpBodyEntryNewProtocol function
CLCmdGoGpsUpStreamData?
updateGoGPSUpBodyEntryNewProtocol(
- CLCmdGogpsHeaderV2 header,
- CLCmdGogpsBodyPeakNew bodyItem
Implementation
CLCmdGoGpsUpStreamData? updateGoGPSUpBodyEntryNewProtocol(CLCmdGogpsHeaderV2 header, CLCmdGogpsBodyPeakNew bodyItem){
if(GoGpsParam.mbNewSession){
GoGpsParam.mbNewSession = false;
// every track initializes these parameters only once
GoGpsParam.mfGOGPSPreDis = 0;
GoGpsParam.mlGOGPSTrailStartTime = bodyItem.timestamp;
GoGpsParam.mlGOGPSTrailEndTime = 0;
GoGpsParam.mnGogpsLastSecIndex = 0;
}
GoGpsParam.mnGogpsReceivedBodyCntInBlk++;
if (bodyItem.secIndex == GoGpsParam.mlLastSecIndex) {
return null;
}
GoGpsParam.mlLastSecIndex = bodyItem.secIndex;
if(bodyItem.secIndex != 0xffff){
double dGogpsNewLat = bodyItem.lat.toDouble();
double dGogpsNewLng = bodyItem.lon.toDouble();
bool isPositionLegal = isLatLonLegal(GoGpsParam.mdGogpsLastLat / 1000000, GoGpsParam.mdGogpsLastLng / 1000000)
&& isLatLonLegal((dGogpsNewLat) / 1000000, (dGogpsNewLng) / 1000000);
// slog("updateGoGPSUpBodyEntry isPositionLegal $isPositionLegal ");
double dDistance = isPositionLegal? Geolocator.distanceBetween(
GoGpsParam.mdGogpsLastLat / 1000000,
GoGpsParam.mdGogpsLastLng / 1000000,
(dGogpsNewLat) / 1000000,
(dGogpsNewLng) / 1000000) : 0;
// slog("updateGoGPSUpBodyEntry: dis=$dDistance");
double currentDist = GoGpsParam.mfGOGPSPreDis + dDistance;
GoGpsParam.mdGogpsLastLat = dGogpsNewLat;
GoGpsParam.mdGogpsLastLng = dGogpsNewLng;
double dSpeed = 0;
// TODO: zs comment here
// if ble broken after at least one block is finished,
// second index may be wrong.
int nGogpsNewSecIndex = bodyItem.secIndex;
if (nGogpsNewSecIndex - GoGpsParam.mnGogpsLastSecIndex > 0) {
dSpeed = dDistance / (nGogpsNewSecIndex - GoGpsParam.mnGogpsLastSecIndex);
}
GoGpsParam.mnGogpsLastSecIndex = nGogpsNewSecIndex;
final pgu = CLCmdGoGpsUpStreamData.fromNewProtocol(
bodyItem,
GoGpsParam.mGogpsUpHeader!.workoutType,
dSpeed,
currentDist.toInt(),
dDistance,
GoGpsParam.mdGogpsLastLat / 1000000,
GoGpsParam.mdGogpsLastLng / 1000000 ,
header.calories,
);
GoGpsParam.mfGOGPSPreDis = currentDist;
GoGpsParam.mfGOGPSTrailRunDis = currentDist;
if (GoGpsParam.mlGOGPSTrailEndTime < pgu.timestamp + pgu.secondindex) {
GoGpsParam.mlGOGPSTrailEndTime = pgu.timestamp + pgu.secondindex;
}
return pgu;
}
else{
slog("gogpsUpBody.gpsdata[i].secIndex == 0xffff");
return null;
}
}