I am trying to use the CB34EX as a remote CANBUS monitor. I have looked at the CAN Serial example and have successfully ran it on the hardware. I am trying to adapt it to work with Ajax requests by putting the CAN Serial code in the Ajax callback function. Here's the code inside the Ajax Callback. As you can see, all it does is print the FIFO content whenever there's an Ajax request. I will later change it to send the CAN message as a JSON object.
Code: Select all
void AjaxCallback(int sock, const char* url)
{
CanRxMessage can_msg( &fifo, 1 ); //Wait up to 1 tick
if ( can_msg.IsValid() )
{
BYTE buffer[8],tension[2];
BYTE len;
DWORD id;
len = can_msg.GetData( buffer, 8 );
id = can_msg.GetId();
iprintf( "Received a CAN message of %d bytes from ", len );
if ( IsNBIdExt( id ) )
{
iprintf( "Extended ID=%ld or 0x%07X\r\n",
NbToExtId( id ),
NbToExtId( id ) );
}
else
{
iprintf( "ID=%d or 0x%03X\r\n", NbToNormId( id ), NbToNormId( id ) );
}
iprintf( "Data = [" );
for ( int i = 0; i < len; i++ )
{
if ( ( buffer[i] < ' ' ) || ( buffer[i] > 128 ) )
{
iprintf( "{%d}", buffer[i] );
}
else
{
iprintf( "%d", buffer[i] );
}
}
iprintf( "]\r\n" );
}
}
Please advise.
Regards,
Kid