Continued to work on the MQTT demo project.

A few review comments added into the MQTT implementation.
This commit is contained in:
Richard Barry
2019-07-24 00:27:14 +00:00
parent 53842d4cac
commit fe4511b35e
21 changed files with 244 additions and 166 deletions

View File

@ -0,0 +1,4 @@
+ platform
Contains FreeRTOS specific implementations of abstractions used within the IoT
libraries.

View File

@ -219,7 +219,7 @@ static void _networkReceiveTask( void * pArgument )
IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
void * pCredentialInfo,
void ** pConnection )
void ** pConnection ) //_RB_ Why all void* and why a void**?
{
IOT_FUNCTION_ENTRY( IotNetworkError_t, IOT_NETWORK_SUCCESS );
Socket_t tcpSocket = FREERTOS_INVALID_SOCKET;
@ -228,7 +228,8 @@ IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
const TickType_t receiveTimeout = pdMS_TO_TICKS( IOT_NETWORK_SOCKET_POLL_MS );
_networkConnection_t * pNewNetworkConnection = NULL;
/* TLS is not supported yet and therefore pCredentialInfo must be NULL. */
/* TLS is not enabled in this version and therefore pCredentialInfo
must be NULL. */
configASSERT( pCredentialInfo == NULL );
/* Cast function parameters to correct types. */
@ -279,7 +280,7 @@ IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
IotLogError( "Failed to resolve %s.", pServerInfo->pHostName );
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );
}
//_RB_ Connects without setting a read block time.
socketStatus = FreeRTOS_connect( tcpSocket,
&serverAddress,
sizeof( serverAddress ) );

View File

@ -0,0 +1,3 @@
+ standard
Contains the implementation of IoT libraries that implement standard protocols
and interfaces, such a MQTT.

View File

@ -665,8 +665,8 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
static StaticTask_t workerTaskTCBs[ IOT_TASKPOOL_NUMBER_OF_WORKERS ];
static StackType_t workerTaskStacks[ IOT_TASKPOOL_NUMBER_OF_WORKERS ][ IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ) ];
/* Static structure to hold te software timer. */
static StaticTimer_t staticTimer;
/* Static structure to hold te software timer. */
static StaticTimer_t staticTimer;
uint32_t threadsCreated = 0; /* Although initialised before use removing the initialiser here results in compiler warnings. */
char taskName[ 10 ];
@ -682,11 +682,11 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
/* Create the timer for a new connection. */
pTaskPool->timer = xTimerCreateStatic( NULL, /* Text name for the timer, only used for debugging. */
portMAX_DELAY, /* Timer period in ticks. */
pdFALSE, /* pdFALSE means its a one-shot timer. */
( void * ) pTaskPool, /* Parameter passed into callback. */
_timerCallback, /* Callback that executes when the timer expires. */
&staticTimer ); /* Static storage for the timer's data structure. */
portMAX_DELAY, /* Timer period in ticks. */
pdFALSE, /* pdFALSE means its a one-shot timer. */
( void * ) pTaskPool, /* Parameter passed into callback. */
_timerCallback, /* Callback that executes when the timer expires. */
&staticTimer ); /* Static storage for the timer's data structure. */
/* The task pool will initialize the minimum number of threads requested by the user upon start.
Note this tailored version of the task pool does not autoscale, but fixes the number of tasks
@ -699,17 +699,17 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
xTaskCreateStatic( _taskPoolWorker, /* Function that implements the task. */
taskName, /* Text name for the task, used for debugging only. */
IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */
IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */
pTaskPool, /* Parameter passed into the task. */
pInfo->priority, /* Priority at which the task starts running. */
&( workerTaskStacks[ threadsCreated ][ 0 ] ), /* Pointer to static storage for the task's stack. */
&( workerTaskTCBs[ threadsCreated ] ) ); /* Pointer to static storage for te task's TCB. */
&( workerTaskTCBs[ threadsCreated ] ) ); /* Pointer to static storage for te task's TCB. */
/* Upon successful thread creation, increase the number of active threads. */
/* Upon successful thread creation, increase the number of active threads. */
pTaskPool->activeThreads++;
++threadsCreated;
}
pTaskPool->running = true;
pTaskPool->running = true;
TASKPOOL_FUNCTION_CLEANUP();

View File

@ -0,0 +1,7 @@
+ mqtt
Contains the implementation of the MQTT library.
+ common
Contains the implementation of utility functions used by other IoT libraries.
Further libraries will be rolled out soon.

View File

@ -853,7 +853,7 @@ IotMqttError_t IotMqtt_Init( void )
#endif /* if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES == 1 */
/* Log initialization status. */
if( status != IOT_MQTT_SUCCESS )
if( status != IOT_MQTT_SUCCESS ) //_RB_ This will generate compiler warnings if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES != 0
{
IotLogError( "Failed to initialize MQTT library serializer. " );
}
@ -896,7 +896,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
_mqttConnection_t * pNewMqttConnection = NULL;
/* Default CONNECT serializer function. */
IotMqttError_t ( * serializeConnect )( const IotMqttConnectInfo_t *,
IotMqttError_t ( * serializeConnect )( const IotMqttConnectInfo_t *, //_RB_ Needs to be a typedef to make it easier to rease and more maintainable should the prototype change.
uint8_t **,
size_t * ) = _IotMqtt_SerializeConnect;
@ -911,7 +911,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
}
/* Validate network interface and connect info. */
if( _IotMqtt_ValidateConnect( pConnectInfo ) == false )
if( _IotMqtt_ValidateConnect( pConnectInfo ) == false ) //_RB_ A lot of code in here that could be replaced by asserts().
{
IOT_SET_AND_GOTO_CLEANUP( IOT_MQTT_BAD_PARAMETER );
}
@ -1002,7 +1002,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
IotLogInfo( "Establishing new MQTT connection." );
/* Initialize a new MQTT connection object. */
/* Initialize a new MQTT connection object. *///_RB_ Initialise, as per the comment, or create, as per the function name? I don't think this does create a connection as that happens below.
pNewMqttConnection = _createMqttConnection( pConnectInfo->awsIotMqttMode,
pNetworkInfo,
pConnectInfo->keepAliveSeconds );
@ -1127,7 +1127,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
IotMqtt_Assert( pOperation->u.operation.packetSize > 0 );
/* Add the CONNECT operation to the send queue for network transmission. */
status = _IotMqtt_ScheduleOperation( pOperation,
status = _IotMqtt_ScheduleOperation( pOperation, // Why schedule a job if going to wait for comletion?
_IotMqtt_ProcessSend,
0 );

View File

@ -0,0 +1,8 @@
Base directory for the FreeRTOS IoT Libraries.
+ abstractions
Contains FreeRTOS specific implementations of abstractions used within the IoT
libraries.
+ c_sdk
Contains the implementations of the IoT libraries - more will be rolled out soon.