static void Write_message( telnet_client_t *client, vlm_message_t *message, char *string_message, int i_mode ) { char *psz_message; client->p_buffer_read = client->buffer_read; (client->p_buffer_read)[0] = 0; // if (cl->p_buffer_read)[0] = '\n' if( client->buffer_write ) free( client->buffer_write ); /* generate the psz_message string */ if( message ) { /* ok, look for vlm_message_t */ psz_message = MessageToString( message, 0 ); } else { /* it is a basic string_message */ psz_message = strdup( string_message ); } client->buffer_write = client->p_buffer_write = psz_message; client->i_buffer_write = strlen( psz_message ); client->i_mode = i_mode; }
/* We need the level of the message to put a beautiful indentation. * first level is 0 */ static char *MessageToString( vlm_message_t *message, int i_level ) { #define STRING_CR "\r\n" #define STRING_TAIL "> " char *psz_message; int i, i_message = sizeof( STRING_TAIL ); if( !message || !message->psz_name ) { return strdup( STRING_CR STRING_TAIL ); } else if( !i_level && !message->i_child && !message->psz_value ) { /* A command is successful. Don't write anything */ return strdup( /*STRING_CR*/ STRING_TAIL ); } i_message += strlen( message->psz_name ) + i_level * sizeof( " " ) + 1; psz_message = malloc( i_message ); *psz_message = 0; for( i = 0; i < i_level; i++ ) strcat( psz_message, " " ); strcat( psz_message, message->psz_name ); if( message->psz_value ) { i_message += sizeof( " : " ) + strlen( message->psz_value ) + sizeof( STRING_CR ); psz_message = realloc( psz_message, i_message ); strcat( psz_message, " : " ); strcat( psz_message, message->psz_value ); strcat( psz_message, STRING_CR ); } else { i_message += sizeof( STRING_CR ); psz_message = realloc( psz_message, i_message ); strcat( psz_message, STRING_CR ); } for( i = 0; i < message->i_child; i++ ) { char *child_message = MessageToString( message->child[i], i_level + 1 ); i_message += strlen( child_message ); psz_message = realloc( psz_message, i_message ); strcat( psz_message, child_message ); free( child_message ); } if( i_level == 0 ) strcat( psz_message, STRING_TAIL ); return psz_message; }
int main() { /// First step is to move over to the FRC w/ PLL clock from the default FRC clock. // Set the clock to 79.84MHz. PLLFBD = 63; // M = 65 CLKDIVbits.PLLPOST = 0; // N1 = 2 CLKDIVbits.PLLPRE = 1; // N2 = 3 // Initiate Clock Switch to FRM oscillator with PLL. __builtin_write_OSCCONH(0x01); __builtin_write_OSCCONL(OSCCON | 0x01); // Wait for Clock switch to occur. while (OSCCONbits.COSC != 1); // And finally wait for the PLL to lock. while (OSCCONbits.LOCK != 1); // Initialize the UART Init(); CanMessage rxMsg; char outStr[30]; while (1) { // If we're active, listen for CAN messages and spit them out when they're found. if (opMode == ACTIVE && Ecan1Receive(&rxMsg, NULL)) { // Turn on the yellow LED whenever a CAN message is received _LATA4 = 1; int bytesToSend; if ((bytesToSend = MessageToString(outStr, sizeof(outStr), &rxMsg))) { // We send 1 less than the output, because that last part is just // a NUL character. Uart1WriteData(outStr, bytesToSend - 1); } _LATA4 = 0; } // Regardless of run state, listen for incoming commands uint8_t u1RxData; if (Uart1ReadByte(&u1RxData)) { int commandResponse = ProcessIncomingCommandStream(u1RxData); // Output a CR if the command was successfully executed if (commandResponse > 0) { Uart1WriteByte('\r'); } // Otherwise output a BEL if there was an error. else if (commandResponse < 0) { Uart1WriteByte('\b'); } // The 0 value returned doesn't warrant an output as it's a command sequence in progress. } } }
void MessageManager::Unsubscribe( IMessageSubscriber* pSubscriber, Message m ) { Unsubscribe( pSubscriber, MessageToString(m) ); }
void MessageManager::Broadcast( Message m ) const { Broadcast( MessageToString(m) ); }