@@ -1625,7 +1625,7 @@ void SFE_UBLOX_GNSS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_
1625
1625
else if (checkAutomatic (incomingUBX->cls , incomingUBX->id ))
1626
1626
{
1627
1627
// This isn't the message we are looking for...
1628
- // Let's say so and leave incomingUBX->classAndIDmatch _unchanged_
1628
+ // Let's say so...
1629
1629
if (_printDebug == true )
1630
1630
{
1631
1631
_debugSerial->print (F (" processUBX: incoming \" automatic\" message: Class: 0x" ));
@@ -1654,20 +1654,6 @@ void SFE_UBLOX_GNSS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_
1654
1654
{
1655
1655
incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_NOT_VALID;
1656
1656
1657
- // Let's check if the class and ID match the requestedClass and requestedID.
1658
- // This is potentially risky as we are saying that we saw the requested Class and ID
1659
- // but that the packet checksum failed. Potentially it could be the class or ID bytes
1660
- // that caused the checksum error!
1661
- if ((incomingUBX->cls == requestedClass) && (incomingUBX->id == requestedID))
1662
- {
1663
- incomingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_VALID; // If we have a match, set the classAndIDmatch flag to not valid
1664
- }
1665
- // If this is an ACK then let's check if the class and ID match the requestedClass and requestedID
1666
- else if ((incomingUBX->cls == UBX_CLASS_ACK) && (incomingUBX->payload [0 ] == requestedClass) && (incomingUBX->payload [1 ] == requestedID))
1667
- {
1668
- incomingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_VALID; // If we have a match, set the classAndIDmatch flag to not valid
1669
- }
1670
-
1671
1657
if ((_printDebug == true ) || (_printLimitedDebug == true )) // This is important. Print this if doing limited debugging
1672
1658
{
1673
1659
// Drive an external pin to allow for easier logic analyzation
@@ -2987,10 +2973,6 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
2987
2973
packetAck.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
2988
2974
packetBuf.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
2989
2975
packetAuto.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
2990
- outgoingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // This will go VALID (or NOT_VALID) when we receive a packet that matches the requested class and ID
2991
- packetAck.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
2992
- packetBuf.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
2993
- packetAuto.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
2994
2976
2995
2977
unsigned long startTime = millis ();
2996
2978
while (millis () - startTime < maxTime)
@@ -3022,12 +3004,6 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3022
3004
}
3023
3005
return (SFE_UBLOX_STATUS_DATA_RECEIVED); // We received valid data and a correct ACK!
3024
3006
}
3025
-
3026
- // We can be confident that the data packet (if we are going to get one) will always arrive
3027
- // before the matching ACK. So if we sent a config packet which only produces an ACK
3028
- // then outgoingUBX->classAndIDmatch will be NOT_DEFINED and the packetAck.classAndIDmatch will VALID.
3029
- // We should not check outgoingUBX->valid, outgoingUBX->cls or outgoingUBX->id
3030
- // as these may have been changed by an automatic packet.
3031
3007
else if (!packetCfg.isClassAndIdMatch (requestedClass, requestedID) && packetAck.isClassAndIdMatch (requestedClass, requestedID))
3032
3008
{
3033
3009
if (_printDebug == true )
@@ -3039,27 +3015,9 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3039
3015
return (SFE_UBLOX_STATUS_DATA_SENT); // We got an ACK but no data...
3040
3016
}
3041
3017
3042
- // If both the outgoingUBX->classAndIDmatch and packetAck.classAndIDmatch are VALID
3043
- // but the outgoingUBX->cls or ID no longer match then we can be confident that we had
3044
- // valid data but it has been or is currently being overwritten by an automatic packet (e.g. PVT).
3045
- // If (e.g.) a PVT packet is _being_ received: outgoingUBX->valid will be NOT_DEFINED
3046
- // If (e.g.) a PVT packet _has been_ received: outgoingUBX->valid will be VALID (or just possibly NOT_VALID)
3047
- // So we cannot use outgoingUBX->valid as part of this check.
3048
- // Note: the addition of packetBuf should make this check redundant!
3049
- else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID) && (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID) && ((outgoingUBX->cls != requestedClass) || (outgoingUBX->id != requestedID)))
3050
- {
3051
- if (_printDebug == true )
3052
- {
3053
- _debugSerial->print (F (" waitForACKResponse: data being OVERWRITTEN after " ));
3054
- _debugSerial->print (millis () - startTime);
3055
- _debugSerial->println (F (" msec" ));
3056
- }
3057
- return (SFE_UBLOX_STATUS_DATA_OVERWRITTEN); // Data was valid but has been or is being overwritten
3058
- }
3059
-
3060
- // If packetAck.classAndIDmatch is VALID but both outgoingUBX->valid and outgoingUBX->classAndIDmatch
3018
+ // If packetAck is for requested class/ID but both outgoingUBX->valid and packetCfg isClassAndIDmatch
3061
3019
// are NOT_VALID then we can be confident we have had a checksum failure on the data packet
3062
- else if ((packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID) && (outgoingUBX-> classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID ) && (outgoingUBX-> valid == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID))
3020
+ else if ((packetAck.isAckForClassAndId (requestedClass, requestedID ) && (packetCfg. valid == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID) ))
3063
3021
{
3064
3022
if (_printDebug == true )
3065
3023
{
@@ -3069,14 +3027,6 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3069
3027
}
3070
3028
return (SFE_UBLOX_STATUS_CRC_FAIL); // Checksum fail
3071
3029
}
3072
-
3073
- // If our packet was not-acknowledged (NACK) we do not receive a data packet - we only get the NACK.
3074
- // So you would expect outgoingUBX->valid and outgoingUBX->classAndIDmatch to still be NOT_DEFINED
3075
- // But if a full PVT packet arrives afterwards outgoingUBX->valid could be VALID (or just possibly NOT_VALID)
3076
- // but outgoingUBX->cls and outgoingUBX->id would not match...
3077
- // So I think this is telling us we need a special state for packetAck.classAndIDmatch to tell us
3078
- // the packet was definitely NACK'd otherwise we are possibly just guessing...
3079
- // Note: the addition of packetBuf changes the logic of this, but we'll leave the code as is for now.
3080
3030
else if (packetAck.isNackForClassAndId (requestedClass, requestedID))
3081
3031
{
3082
3032
if (_printDebug == true )
@@ -3088,10 +3038,10 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3088
3038
return (SFE_UBLOX_STATUS_COMMAND_NACK); // We received a NACK!
3089
3039
}
3090
3040
3091
- // If the outgoingUBX->classAndIDmatch is VALID but the packetAck.classAndIDmatch is NOT_VALID
3041
+ // If the packetCfg.isClassAndIdMatch but the packetAck is not for this class/ID
3092
3042
// then the ack probably had a checksum error. We will take a gamble and return DATA_RECEIVED.
3093
3043
// If we were playing safe, we should return FAIL instead
3094
- else if ((outgoingUBX-> classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID) && (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID) && (outgoingUBX-> valid == SFE_UBLOX_PACKET_VALIDITY_VALID) && (outgoingUBX-> cls == requestedClass ) && (outgoingUBX-> id == requestedID ))
3044
+ else if ((packetCfg. isClassAndIdMatch (requestedClass, requestedID) && (packetAck.isClassAndIdMatch (requestedClass, requestedID) == false ) && (packetCfg. valid == SFE_UBLOX_PACKET_VALIDITY_VALID) ))
3095
3045
{
3096
3046
if (_printDebug == true )
3097
3047
{
@@ -3102,9 +3052,9 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3102
3052
return (SFE_UBLOX_STATUS_DATA_RECEIVED); // We received valid data and an invalid ACK!
3103
3053
}
3104
3054
3105
- // If the outgoingUBX->classAndIDmatch is NOT_VALID and the packetAck.classAndIDmatch is NOT_VALID
3055
+ // If classes of ack and data do not match
3106
3056
// then we return a FAIL. This must be a double checksum failure?
3107
- else if ((outgoingUBX-> classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID ) && (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID ))
3057
+ else if ((packetCfg. isClassAndIdMatch (requestedClass, requestedID) == false ) && (packetAck.isClassAndIdMatch (requestedClass, requestedID) == false ))
3108
3058
{
3109
3059
if (_printDebug == true )
3110
3060
{
@@ -3115,9 +3065,9 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3115
3065
return (SFE_UBLOX_STATUS_FAIL); // We received invalid data and an invalid ACK!
3116
3066
}
3117
3067
3118
- // If the outgoingUBX->classAndIDmatch is VALID and the packetAck.classAndIDmatch is NOT_DEFINED
3068
+ // If the config packet is VALID and packetAck does not match the requested class/ID
3119
3069
// then the ACK has not yet been received and we should keep waiting for it
3120
- else if ((outgoingUBX-> classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID ) && (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED ))
3070
+ else if ((packetCfg. isClassAndIdMatch (requestedClass, requestedID) == true ) && (packetAck.isClassAndIdMatch (requestedClass, requestedID) == false ))
3121
3071
{
3122
3072
// if (_printDebug == true)
3123
3073
// {
@@ -3133,7 +3083,7 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForACKResponse(ubxPacket *outgoingUBX, ui
3133
3083
} // while (millis() - startTime < maxTime)
3134
3084
3135
3085
// We have timed out...
3136
- // If the outgoingUBX->classAndIDmatch is VALID then we can take a gamble and return DATA_RECEIVED
3086
+ // If the packetCfg matches the requested class/ID then we can take a gamble and return DATA_RECEIVED
3137
3087
// even though we did not get an ACK
3138
3088
if ((packetCfg.isClassAndIdMatch (requestedClass, requestedID) && !packetAck.isClassAndIdMatch (requestedClass, requestedID)) && (packetCfg.valid == SFE_UBLOX_PACKET_VALIDITY_VALID))
3139
3089
{
@@ -3168,20 +3118,16 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForNoACKResponse(ubxPacket *outgoingUBX,
3168
3118
packetAck.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
3169
3119
packetBuf.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
3170
3120
packetAuto.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
3171
- outgoingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // This will go VALID (or NOT_VALID) when we receive a packet that matches the requested class and ID
3172
- packetAck.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
3173
- packetBuf.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
3174
- packetAuto.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
3175
-
3121
+
3176
3122
unsigned long startTime = millis ();
3177
3123
while (millis () - startTime < maxTime)
3178
3124
{
3179
3125
if (checkUbloxInternal (&packetBuf, requestedClass, requestedID) == true ) // See if new data is available. Process bytes as they come in.
3180
3126
{
3181
3127
3182
- // If outgoingUBX->classAndIDmatch is VALID
3128
+ // If packetBuf matches
3183
3129
// and outgoingUBX->valid is _still_ VALID and the class and ID _still_ match
3184
- // then we can be confident that the data in outgoingUBX is valid
3130
+ // then we can be confident that the data in packetBuf is valid
3185
3131
if (packetBuf.isClassAndIdMatch (requestedClass, requestedID) && packetBuf.valid == SFE_UBLOX_PACKET_VALIDITY_VALID)
3186
3132
{
3187
3133
if (_printDebug == true )
@@ -3192,53 +3138,7 @@ sfe_ublox_status_e SFE_UBLOX_GNSS::waitForNoACKResponse(ubxPacket *outgoingUBX,
3192
3138
}
3193
3139
return (SFE_UBLOX_STATUS_DATA_RECEIVED); // We received valid data!
3194
3140
}
3195
-
3196
- // If the outgoingUBX->classAndIDmatch is VALID
3197
- // but the outgoingUBX->cls or ID no longer match then we can be confident that we had
3198
- // valid data but it has been or is currently being overwritten by another packet (e.g. PVT).
3199
- // If (e.g.) a PVT packet is _being_ received: outgoingUBX->valid will be NOT_DEFINED
3200
- // If (e.g.) a PVT packet _has been_ received: outgoingUBX->valid will be VALID (or just possibly NOT_VALID)
3201
- // So we cannot use outgoingUBX->valid as part of this check.
3202
- // Note: the addition of packetBuf should make this check redundant!
3203
- else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID) && ((outgoingUBX->cls != requestedClass) || (outgoingUBX->id != requestedID)))
3204
- {
3205
- if (_printDebug == true )
3206
- {
3207
- _debugSerial->print (F (" waitForNoACKResponse: data being OVERWRITTEN after " ));
3208
- _debugSerial->print (millis () - startTime);
3209
- _debugSerial->println (F (" msec" ));
3210
- }
3211
- return (SFE_UBLOX_STATUS_DATA_OVERWRITTEN); // Data was valid but has been or is being overwritten
3212
- }
3213
-
3214
- // If outgoingUBX->classAndIDmatch is NOT_DEFINED
3215
- // and outgoingUBX->valid is VALID then this must be (e.g.) a PVT packet
3216
- else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED) && (outgoingUBX->valid == SFE_UBLOX_PACKET_VALIDITY_VALID))
3217
- {
3218
- // if (_printDebug == true)
3219
- // {
3220
- // _debugSerial->print(F("waitForNoACKResponse: valid but UNWANTED data after "));
3221
- // _debugSerial->print(millis() - startTime);
3222
- // _debugSerial->print(F(" msec. Class: "));
3223
- // _debugSerial->print(outgoingUBX->cls);
3224
- // _debugSerial->print(F(" ID: "));
3225
- // _debugSerial->print(outgoingUBX->id);
3226
- // }
3227
- }
3228
-
3229
- // If the outgoingUBX->classAndIDmatch is NOT_VALID then we return CRC failure
3230
- /* else if (outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
3231
- {
3232
- if (_printDebug == true)
3233
- {
3234
- _debugSerial->print(F("waitForNoACKResponse: CLS/ID match but failed CRC after "));
3235
- _debugSerial->print(millis() - startTime);
3236
- _debugSerial->println(F(" msec"));
3237
- }
3238
- return (SFE_UBLOX_STATUS_CRC_FAIL); //We received invalid data
3239
- }*/
3240
3141
}
3241
-
3242
3142
delayMicroseconds (500 );
3243
3143
}
3244
3144
0 commit comments