#include #include "utopia.h" void reboot_node( CnetEvent ev, CnetTimer ts, CnetData data ) { CHECK( CNET_enable_application( ALLNODES ) ); CHECK( CNET_set_handler( EV_APPLICATIONREADY, OnApplicationReady, 0 ) ); CHECK( CNET_set_handler( EV_PHYSICALREADY, OnPhysicalReady, 0 ) ); } void OnApplicationReady( CnetEvent ev, CnetTimer ts, CnetData data ) { CnetAddr destAddr; Frame frame; int frameLength; int packetLength; /* Get the packet from the Application/Network layer. */ packetLength = MAX_MESSAGE_SIZE; CHECK( CNET_read_application( &destAddr, frame.info, &packetLength ) ); /* Send the frame to the Physical layer. */ frameLength = FRAME_HEADER_SIZE + packetLength; CHECK( CNET_write_physical_reliable( 1, (char *)(&frame), &frameLength ) ); } void OnPhysicalReady( CnetEvent ev, CnetTimer ts, CnetData data ) { Frame frame; int link; int frameLength; int packetLength; /* Get the frame from the Physical layer. */ frameLength = sizeof( Frame ); CHECK( CNET_read_physical( &link, (char *)(&frame), &frameLength ) ); /* Send the packet to the Application/Network layer. */ packetLength = frameLength - FRAME_HEADER_SIZE; CHECK( CNET_write_application( frame.info, &packetLength ) ); }