#include <RealworldConnector.h>
Inheritance diagram for RealworldConnector:
Public Member Functions | |
Module_Class_Members (RealworldConnector, cSimpleModule, 0) | |
virtual int | numInitStages () const |
virtual void | initialize (int stage) |
Initialization of the module. | |
virtual void | handleMessage (cMessage *msg) |
The "main loop". | |
Protected Member Functions | |
virtual void | transmitToNetwork (cMessage *msg) |
Send a message to the (realworld) network. | |
virtual void | updateDisplayString () |
virtual char * | encapsulate (cMessage *msg, unsigned int *length)=0 |
Converts an IP datagram to a data block for sending it to the (realworld) network. | |
virtual cMessage * | decapsulate (char *buf, uint32_t length)=0 |
Parses data received from the (realworld) network and converts it into a cMessage. | |
virtual bool | isApp () |
If the Connector connects to an application, this method has to be overwritten to return "true". | |
Protected Attributes | |
int | gateIndexNetwOut |
unsigned int | mtu |
long | numSent |
long | numSendError |
long | numRcvdOK |
long | numRcvError |
cMessage * | packetNotification |
RealtimeScheduler::PacketBuffer | packetBuffer |
RealtimeScheduler * | scheduler |
PacketParser * | parser |
virtual cMessage* RealworldConnector::decapsulate | ( | char * | buf, | |
uint32_t | length | |||
) | [protected, pure virtual] |
Parses data received from the (realworld) network and converts it into a cMessage.
buf | A pointer to the data to be parsed | |
length | The lenght of the buffer in bytes |
Implemented in RealworldApp, and TunOutDevice.
virtual char* RealworldConnector::encapsulate | ( | cMessage * | msg, | |
unsigned int * | length | |||
) | [protected, pure virtual] |
Converts an IP datagram to a data block for sending it to the (realworld) network.
msg | A pointer to the message to be converted | |
length | A pointer to an int that will hold the length of the converted data |
Implemented in RealworldApp, and TunOutDevice.
void RealworldConnector::handleMessage | ( | cMessage * | msg | ) | [virtual] |
The "main loop".
Every message that is received or send is handled by this method
00048 { 00049 // Packet from the real world... 00050 if (msg==packetNotification) { 00051 EV << "RealworldConnector: Message from outside. Queue length = " << packetBuffer.size() << ".\n"; 00052 while( packetBuffer.size() > 0 ) { 00053 // get packet from buffer and parse it 00054 00055 RealtimeScheduler::PacketBufferEntry packet = *(packetBuffer.begin()); 00056 packetBuffer.pop_front(); 00057 char* buf = packet.data; 00058 uint32_t len = packet.length; 00059 cMessage *parsedPacket = decapsulate(buf, len); 00060 if (parsedPacket) { 00061 numRcvdOK++; 00062 send(parsedPacket, gateIndexNetwOut); 00063 } else { 00064 numRcvError++; 00065 } 00066 00067 } 00068 } else // arrived on gate "netwIn" 00069 { 00070 // Packet from inside, send to real word 00071 EV << "Received " << msg << " for transmission\n"; 00072 00073 transmitToNetwork(msg); 00074 } 00075 00076 if (ev.isGUI()) 00077 updateDisplayString(); 00078 00079 }
void RealworldConnector::initialize | ( | int | stage | ) | [virtual] |
Initialization of the module.
Registers the device at the scheduler and searches for the appropriate payload-parser Will be called automatically at startup
Reimplemented in RealworldDevice.
00008 { 00009 if (stage==3) { 00010 // update display string when addresses have been autoconfigured etc. 00011 updateDisplayString(); 00012 return; 00013 } 00014 00015 // all initialization is done in the first stage 00016 if (stage!=0) 00017 return; 00018 00019 packetNotification = new cMessage("packetNotification"); 00020 mtu = par("mtu"); 00021 00022 scheduler = check_and_cast<RealtimeScheduler *>(simulation.scheduler()); 00023 scheduler->setInterfaceModule(this, packetNotification, &packetBuffer, mtu, isApp()); 00024 00025 // parser = check_and_cast<PacketParser*>(parentModule()->submodule("packetParser")); 00026 if (!isApp() ) { 00027 parser = check_and_cast<PacketParser*>(parentModule()->submodule("packetParser")); 00028 } else { 00029 parser = check_and_cast<PacketParser*>(parentModule()->submodule("applicationParser")); 00030 } 00031 00032 numSent = numRcvdOK = numRcvError = numSendError = 0; 00033 WATCH(numSent); 00034 WATCH(numRcvdOK); 00035 WATCH(numRcvError); 00036 WATCH(numSendError); 00037 00038 if (!isApp() ) { 00039 gateIndexNetwOut = gate("netwOut")->id(); 00040 } else { 00041 gateIndexNetwOut = gate("to_lowerTier")->id(); 00042 } 00043 00044 }
virtual bool RealworldConnector::isApp | ( | ) | [inline, protected, virtual] |
If the Connector connects to an application, this method has to be overwritten to return "true".
Reimplemented in RealworldApp.
RealworldConnector::Module_Class_Members | ( | RealworldConnector | , | |
cSimpleModule | , | |||
0 | ||||
) |
virtual int RealworldConnector::numInitStages | ( | void | ) | const [inline, virtual] |
void RealworldConnector::transmitToNetwork | ( | cMessage * | msg | ) | [protected, virtual] |
Send a message to the (realworld) network.
msg | A pointer to the message to be send |
00082 { 00083 unsigned int length; 00084 char* buf = encapsulate(msg, &length); 00085 if( buf ) { 00086 numSent++; 00087 scheduler->sendBytes( buf, length, isApp() ); 00088 } else { 00089 numSendError++; 00090 } 00091 delete buf; 00092 }
void RealworldConnector::updateDisplayString | ( | ) | [protected, virtual] |
00095 { 00096 char buf[80]; 00097 if (ev.disabled()) { 00098 // speed up things 00099 displayString().setTagArg("t",0,""); 00100 } 00101 sprintf(buf, "rcv:%ld snt:%ld", numRcvdOK, numSent); 00102 00103 if (numRcvError>0) 00104 sprintf(buf+strlen(buf), "\nerrin:%ld errout:%ld", numRcvError, numSendError); 00105 00106 displayString().setTagArg("t",0,buf); 00107 }
int RealworldConnector::gateIndexNetwOut [protected] |
unsigned int RealworldConnector::mtu [protected] |
long RealworldConnector::numRcvdOK [protected] |
long RealworldConnector::numRcvError [protected] |
long RealworldConnector::numSendError [protected] |
long RealworldConnector::numSent [protected] |
cMessage* RealworldConnector::packetNotification [protected] |
PacketParser* RealworldConnector::parser [protected] |
RealtimeScheduler* RealworldConnector::scheduler [protected] |