/*************************************************************** * * boapdll.c * * The "best of all possible data link layers" cnet example * from section 4 of "Getting Started With cnet," * Jeff Ondich, 2000. * ***************************************************************/ #include #include "boapdll.h" void reboot_node( CnetEvent event, CnetTimer timer, CnetData data ) { CHECK( CNET_set_handler( EV_APPLICATIONREADY, on_app_ready, 0 ) ); CHECK( CNET_set_handler( EV_PHYSICALREADY, on_phys_ready, 0 ) ); CHECK( CNET_enable_application( ALLNODES ) ); } void on_app_ready( CnetEvent event, CnetTimer timer, CnetData data ) { CnetAddr destAddr; Frame frame; int frameLength; int messageLength; /* Get the message from the application layer. */ messageLength = MAX_MESSAGE_SIZE; CHECK( CNET_read_application( &destAddr, frame.info, &messageLength ) ); /* Send the frame to the physical layer. */ frameLength = FRAME_HEADER_SIZE + messageLength; CHECK( CNET_write_physical_reliable( 1, (char *)(&frame), &frameLength ) ); } void on_phys_ready( CnetEvent event, CnetTimer timer, CnetData data ) { Frame frame; int link; int frameLength; int messageLength; /* Get the frame from the physical layer. */ frameLength = sizeof( Frame ); CHECK( CNET_read_physical( &link, (char *)(&frame), &frameLength ) ); /* Send the message to the application layer. */ messageLength = frameLength - FRAME_HEADER_SIZE; CHECK( CNET_write_application( frame.info, &messageLength ) ); }