tweak logging around message parsing where crash seems to be

This commit is contained in:
Eric House 2024-12-03 21:06:36 -08:00
parent 2a5fb95dac
commit a60451d84c
2 changed files with 21 additions and 8 deletions

View file

@ -536,17 +536,22 @@ dvc_makeMQTTNoSuchGames( XW_DUtilCtxt* dutil, XWEnv xwe,
} }
static XP_Bool static XP_Bool
isDevMsg( const MQTTDevID* myID, const XP_UCHAR* topic, XP_U32* gameID ) isDevMsg( const MQTTDevID* myID, const XP_UCHAR* topic, XP_U32* gameIDP )
{ {
XP_UCHAR buf[64]; XP_UCHAR buf[64];
formatMQTTDevTopic( myID, buf, VSIZE(buf) ); formatMQTTDevTopic( myID, buf, VSIZE(buf) );
size_t topicLen = XP_STRLEN(buf); size_t topicLen = XP_STRLEN(buf);
XP_ASSERT( topicLen < VSIZE(buf)-1 );
/* Does topic match xw4/device/<devid> at least */
XP_Bool success = 0 == strncmp( buf, topic, topicLen ); XP_Bool success = 0 == strncmp( buf, topic, topicLen );
if ( success ) { if ( success ) {
/* Now get the gameID if it's there */
const XP_UCHAR* gameIDPart = topic + topicLen; const XP_UCHAR* gameIDPart = topic + topicLen;
sscanf( gameIDPart, "/%X", gameID ); int count =
sscanf( gameIDPart, "/%X", gameIDP );
XP_ASSERT( 1 == count || 0 == *gameIDP ); /* firing */
} }
// XP_LOGFF( "(%s) => %s (gameID=%X)", topic, boolToStr(success), *gameID ); XP_LOGFF( "(%s) => %s (gameID=%X)", topic, boolToStr(success), *gameIDP );
return success; return success;
} }
@ -659,11 +664,10 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
MQTTDevID myID; MQTTDevID myID;
dvc_getMQTTDevID( dutil, xwe, &myID ); dvc_getMQTTDevID( dutil, xwe, &myID );
XP_LOGFF( "got myID" ); // XP_LOGFF( "got myID" ); /* gets here */
XP_U32 gameID = 0; XP_U32 gameID = 0;
if ( isDevMsg( &myID, topic, &gameID ) ) { if ( isDevMsg( &myID, topic, &gameID ) ) {
XP_LOGFF( "is msg; gameID: %X", gameID );
XWStreamCtxt* stream = mkStream( dutil ); XWStreamCtxt* stream = mkStream( dutil );
stream_putBytes( stream, buf, len ); stream_putBytes( stream, buf, len );
@ -722,7 +726,6 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
} }
stream_destroy( stream ); stream_destroy( stream );
} else if ( isCtrlMsg( &myID, topic ) ) { } else if ( isCtrlMsg( &myID, topic ) ) {
XP_LOGFF( "is ctrl msg" );
dutil_onCtrlReceived( dutil, xwe, buf, len ); dutil_onCtrlReceived( dutil, xwe, buf, len );
} else { } else {
XP_LOGFF( "OTHER" ); XP_LOGFF( "OTHER" );

View file

@ -666,14 +666,24 @@ smsToBin( XP_U8* out, XP_U16* outlenp, const XP_UCHAR* sms, XP_U16 smslen )
XP_UCHAR* XP_UCHAR*
formatMQTTDevID( const MQTTDevID* devid, XP_UCHAR* buf, XP_U16 bufLen ) formatMQTTDevID( const MQTTDevID* devid, XP_UCHAR* buf, XP_U16 bufLen )
{ {
XP_SNPRINTF( buf, bufLen, MQTTDevID_FMT, *devid ); XP_ASSERT( bufLen >= 17 );
#ifdef DEBUG
int len =
#endif
XP_SNPRINTF( buf, bufLen, MQTTDevID_FMT, *devid );
XP_ASSERT( len < bufLen );
// LOG_RETURNF( "%s", buf );
return buf; return buf;
} }
XP_UCHAR* XP_UCHAR*
formatMQTTDevTopic( const MQTTDevID* devid, XP_UCHAR* buf, XP_U16 bufLen ) formatMQTTDevTopic( const MQTTDevID* devid, XP_UCHAR* buf, XP_U16 bufLen )
{ {
XP_SNPRINTF( buf, bufLen, MQTTTopic_FMT, *devid ); #ifdef DEBUG
int len =
#endif
XP_SNPRINTF( buf, bufLen, MQTTTopic_FMT, *devid );
XP_ASSERT( len < bufLen );
// LOG_RETURNF( "%s", buf ); // LOG_RETURNF( "%s", buf );
return buf; return buf;
} }