void vLoggingPrintf( const char * pcFormat,
... )
{
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
char cOutputString[ dlMAX_PRINT_STRING_LENGTH ];
char * pcSource, * pcTarget, * pcBegin;
size_t xLength, xLength2, rc;
static BaseType_t xMessageNumber = 0;
static BaseType_t xAfterLineBreak = pdTRUE;
va_list args;
uint32_t ulIPAddress;
const char * pcTaskName;
const char * pcNoTask = "None";
int iOriginalPriority;
// HANDLE xCurrentTask;
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) || ( xUDPLoggingUsed != pdFALSE ) )
{
/* There are a variable number of parameters. */
va_start( args, pcFormat );
/* Additional info to place at the start of the log. */
if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )
{
pcTaskName = pcTaskGetName( NULL );
}
else
{
pcTaskName = pcNoTask;
}
if( ( xAfterLineBreak == pdTRUE ) && ( strcmp( pcFormat, "\r\n" ) != 0 ) )
{
xLength = snprintf( cPrintString, dlMAX_PRINT_STRING_LENGTH, "%lu %lu [%s] ",
xMessageNumber++,
( unsigned long ) xTaskGetTickCount(),
pcTaskName );
xAfterLineBreak = pdFALSE;
}
else
{
xLength = 0;
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
xAfterLineBreak = pdTRUE;
}
xLength2 = vsnprintf( cPrintString + xLength, dlMAX_PRINT_STRING_LENGTH - xLength, pcFormat, args );
if( xLength2 < 0 )
{
/* Clean up. */
xLength2 = dlMAX_PRINT_STRING_LENGTH - 1 - xLength;
cPrintString[ dlMAX_PRINT_STRING_LENGTH - 1 ] = '\0';
}
xLength += xLength2;
va_end( args );
/* For ease of viewing, copy the string into another buffer, converting
* IP addresses to dot notation on the way. */
pcSource = cPrintString;
pcTarget = cOutputString;
while( ( *pcSource ) != '\0' )
{
*pcTarget = *pcSource;
pcTarget++;
pcSource++;
/* Look forward for an IP address denoted by 'ip'. */
if( ( isxdigit( pcSource[ 0 ] ) != pdFALSE ) && ( pcSource[ 1 ] == 'i' ) && ( pcSource[ 2 ] == 'p' ) )
{
*pcTarget = *pcSource;
pcTarget++;
*pcTarget = '\0';
pcBegin = pcTarget - 8;
while( ( pcTarget > pcBegin ) && ( isxdigit( pcTarget[ -1 ] ) != pdFALSE ) )
{
pcTarget--;
}
sscanf( pcTarget, "%8X", &ulIPAddress );
rc = sprintf( pcTarget, "%lu.%lu.%lu.%lu",
( unsigned long ) ( ulIPAddress >> 24UL ),
( unsigned long ) ( ( ulIPAddress >> 16UL ) & 0xffUL ),
( unsigned long ) ( ( ulIPAddress >> 8UL ) & 0xffUL ),
( unsigned long ) ( ulIPAddress & 0xffUL ) );
pcTarget += rc;
pcSource += 3; /* skip "<n>ip" */
}
}
TaskFunction_t xFunctionToPend;
TickType_t xTicksToWait;
const struct freertos_sockaddr *pxDestinationAddress;
socklen_t xDestinationAddressLength;
/* How far through the buffer was written? */
xLength = ( BaseType_t ) ( pcTarget - cOutputString );
/* If the message is to be logged to a UDP port then it can be sent directly
* because it only uses FreeRTOS function (not Win32 functions). */
if( xUDPLoggingUsed != pdFALSE )
{
if( ( xPrintSocket == FREERTOS_INVALID_SOCKET() ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
{
/* Create and bind the socket to which print messages are sent. The
* xTimerPendFunctionCall() function is used even though this is
* not an interrupt because this function is called from the IP task
* and the IP task cannot itself wait for a socket to bind. The
* parameters to prvCreatePrintSocket() are not required so set to
* NULL or 0. */
xTimerPendFunctionCall( xFunctionToPend, NULL, 0, xTicksToWait );
}
if( xPrintSocket() != FREERTOS_INVALID_SOCKET() )
{
FreeRTOS_sendto( xPrintSocket, cOutputString, xLength, 0, &pxDestinationAddress, sizeof( xDestinationAddressLength ) );
/* Just because the UDP data logger I'm using is dumb. */
FreeRTOS_sendto( xPrintSocket, "\r", sizeof( char ), 0, &pxDestinationAddress, sizeof( xDestinationAddressLength ) );
}
}
/* If logging is also to go to either stdout or a disk file then it cannot
* be output here - so instead write the message to the stream buffer and wake
* the Win32 thread which will read it from the stream buffer and perform the
* actual output. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
configASSERT( xLogStreamBuffer );
/* How much space is in the buffer? */
xLength2 = uxStreamBufferGetSpace( xLogStreamBuffer );
/* There must be enough space to write both the string and the length of
* the string. */
if( xLength2 >= ( xLength + sizeof( xLength ) ) )
{
/* First write in the length of the data, then write in the data
* itself. Raising the thread priority is used as a critical section
* as there are potentially multiple writers. The stream buffer is
* only thread safe when there is a single writer (likewise for
* reading from the buffer). */
// xCurrentTask = GetCurrentThread();
// iOriginalPriority = GetThreadPriority( xCurrentTask );
// SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) &( xLength ), sizeof( xLength ) );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) cOutputString, xLength );
SetThreadPriority( GetCurrentThread(), iOriginalPriority );
}
/* xDirectPrint is initialized to pdTRUE, and while it remains true the
* logging output function is called directly. When the system is running
* the output function cannot be called directly because it would get
* called from both FreeRTOS tasks and Win32 threads - so instead wake the
* Win32 thread responsible for the actual output. */
BaseType_t xDirectPrint;
BaseType_t pvLoggingThreadEvent;
if( xDirectPrint != pdFALSE )
{
/* While starting up, the thread which calls prvWin32LoggingThread()
* is not running yet and xDirectPrint will be pdTRUE. */
prvLoggingFlushBuffer();
}
else if( pvLoggingThreadEvent != NULL )
{
/* While running, wake up prvWin32LoggingThread() to send the
* logging data. */
SetEvent( pvLoggingThreadEvent );
}
}
}
}
this is the errors i face
../FreeRTOS_http/src/logging.c:210:19: error: 'xPrintSocket' undeclared (first use in this function)
210 | if( ( xPrintSocket == FREERTOS_INVALID_SOCKET() ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
| ^~~~~~~~~~~~
../FreeRTOS_http/src/logging.c:210:19: note: each undeclared identifier is reported only once for each function it appears in
../FreeRTOS_http/src/logging.c:210:35: warning: implicit declaration of function 'FREERTOS_INVALID_SOCKET' [-Wimplicit-function-declaration]
210 | if( ( xPrintSocket == FREERTOS_INVALID_SOCKET() ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
| ^~~~~~~~~~~~~~~~~~~~~~~
../FreeRTOS_http/src/logging.c:218:17: warning: implicit declaration of function 'xTimerPendFunctionCall'; did you mean 'INCLUDE_xTimerPendFunctionCall'? [-Wimplicit-function-declaration]
218 | xTimerPendFunctionCall( xFunctionToPend, NULL, 0, xTicksToWait );
| ^~~~~~~~~~~~~~~~~~~~~~
| INCLUDE_xTimerPendFunctionCall
../FreeRTOS_http/src/logging.c:221:17: warning: implicit declaration of function 'xPrintSocket' [-Wimplicit-function-declaration]
221 | if( xPrintSocket() != FREERTOS_INVALID_SOCKET() )
| ^~~~~~~~~~~~
../FreeRTOS_http/src/logging.c:223:17: warning: implicit declaration of function 'FreeRTOS_sendto'; did you mean 'FreeRTOS_IPInit'? [-Wimplicit-function-declaration]
223 | FreeRTOS_sendto( xPrintSocket, cOutputString, xLength, 0, &pxDestinationAddress, sizeof( xDestinationAddressLength ) );
| ^~~~~~~~~~~~~~~
| FreeRTOS_IPInit
../FreeRTOS_http/src/logging.c:239:24: warning: implicit declaration of function 'uxStreamBufferGetSpace' [-Wimplicit-function-declaration]
239 | xLength2 = uxStreamBufferGetSpace( xLogStreamBuffer );
|
^~~~~~~~~~~~~~~~~~~~~~
please brief me where can I declare the ‘xPrintSocket’ and how to declare it and brief me about the other erros
Thankyou