Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

Daemon Class Reference

Truck daemon. More...

#include <truckd.h>

List of all members.

Public Member Functions

 Daemon (int noGPS, int noHW)
 Daemon's Constructor.
 ~Daemon (void)
 Destructor, kill controller (if it is running), and shut off motors.
int run (void)
 'Main loop' of truck daemon.
void quit (void)
 Sends signal run() to clean up and return.

Protected Member Functions

int processController (void)
 controller will send messages for client
int processGPS (void)
 Reads and processes new GPS data.
int processControlServer (void)
 Will accept connections from controlServer to make a new controller connnection.
int runController (void)
 Handles the 'run' message from the client, by starting a controller program.
void childKill (void)
 Write me!
int killController (void)
 Kills a running contoller, first by asking it to then by forcing it.
int processClient (void)
 client may send commands to deamon or controller
int connectClient (void)
 Creates TCPmsg connection to server.

Static Protected Member Functions

static int max (int a, int b)
 Function to find Max between two integers.

Protected Attributes

TCPmsgclient
UNIXmsgServer controlServer
UNIXmsgcontroller
int isLocal
int controllerPID
GPSgps
int _quit
hwInterfacehw
int verbose
fd_set readSet
timeval selectTO


Detailed Description

Truck daemon.

The truck daemon is meant to be run when the truck is first started. All messaging between client and the controller program goes through the truck daemon first. The truck deamon will intercept specific messages like 'run' and 'kill' and handles them locally. The daemon can start and stop controllers. This should make having multiple people write controllers much easier, since each controller is a completely seperate program. Seperating the functions the truck daemon performs from the controller's functions makes writing a controller much simpler. Having the daemon as a seperate program make the system safer. If a controller goes bad, the daemon can allows kill its program and the stop the truck. Also, A bad controller can't crash the daemon because they do not share memory spaces

Author:
<Derek (mostly)>

Definition at line 42 of file truckd.h.


Constructor & Destructor Documentation

Daemon::Daemon int  noGPS,
int  noHW
 

Daemon's Constructor.

The constructor intiates TCP connections and (re)-starts the GPS device Which can take on the order of 10-50seconds. If GPS is unneeded it can be ignored. Also, currently the daemon only really needs to use the HW interface of the truck to make certain the motors of the truck are actually turned off when the controller exits, so the hw interface in not strictly needed.

Parameters:
@return <-1 on error, 0 if sucessful>
Author:
<author name>="">

Definition at line 496 of file truckd.cpp.

References connectClient(), gps, hw, GPS::init(), isLocal, hwInterface::reset(), and verbose.

Daemon::~Daemon void   ) 
 

Destructor, kill controller (if it is running), and shut off motors.

Author:
Derek King

Definition at line 552 of file truckd.cpp.

References hw, killController(), hwInterface::setSCPower(), hwInterface::wait(), and hwInterface::writeControl().


Member Function Documentation

void Daemon::childKill void   )  [protected]
 

Write me!

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 210 of file truckd.cpp.

References controller, controllerPID, and status.

Referenced by killController().

int Daemon::connectClient void   )  [protected]
 

Creates TCPmsg connection to server.

The truck and the server could be moving around, so this function needs to Try different wireless networks to find the server. To do this it runs a python script (trucknet.py) that will connect to different mananged and ad-hoc wireless networks and probe for the server on those networks. When it finds a server it will write the server address to /var/trucknet and return. This function is responsible for starting the python script, waiting for it to find a server, and then using the server's IP address to make a connection to it.

Returns:
<-1 on error, 0 if sucessful>
Author:
<author name>="">

Definition at line 418 of file truckd.cpp.

References buflen, client, HOST_IP_TESTING, __PORT::PORT, status, TRUCK_PORT, and __URL::URL.

Referenced by Daemon(), and run().

int Daemon::killController void   )  [protected]
 

Kills a running contoller, first by asking it to then by forcing it.

Because controllers can be started either by this program or using a command prompt, there is a few different things we may or may not have. When a controller is started by this program, we automatically know the controller's PID, but we might not have a connection to the controller. If the controller is started seperately, this program won't know anything about the controller until it creates a connection. When the controller creates a connection it's supposed to send its PID. So we may have a connection but no PID.

To summerize here is the list of possibilities :

1. Controller was started elsewhere; we have a connection, but no PID. 2. Controller was started elsewhere; we have both a connection and PID. 3. Controller was started here; we have a PID, but no connection. 4. Controller was started here; we have both a connection and PID.

If we have a connection to controller we can first send it a message asking it to quit and wait a while for it to do so. If the controller was started here we can easily check to see if it has exited by using wait(). If controller has not exited (or we can't tell) we can send the controller a kill signal.

To summerize here is how we stop the controller, in each case.

1. Send kill message to controller. DONE 2. Send kill message, wait for a bit, send kill signal. DONE 3. Check to see if controller has exited (maybe it did already), If not, send kill signal and wait for exit code. DONE 4 Send kill message and wait for a bit. GOTO step 3.

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 289 of file truckd.cpp.

References childKill(), controller, controllerPID, endmsg, isLocal, and startmsg().

Referenced by processClient(), runController(), and ~Daemon().

int Daemon::max int  a,
int  b
[inline, static, protected]
 

Function to find Max between two integers.

Returns:
max of two integer inputs
Author:
Derek King

Definition at line 90 of file truckd.h.

Referenced by run().

int Daemon::processClient void   )  [protected]
 

client may send commands to deamon or controller

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 343 of file truckd.cpp.

References client, controller, controllerPID, msg::dispatch(), endmsg, killController(), msg::moreArgs(), TCPmsg::recv(), runController(), startmsg(), msg::type(), and verbose.

Referenced by run().

int Daemon::processController void   )  [protected]
 

controller will send messages for client

Receive messages from the controller through a UNIXmsg System and pass them to the Client using a TCPmsg System

Returns:
returns 0 on success and non-zero error from controller->recvNoWait() otherwise
Author:
Derek King

Definition at line 32 of file truckd.cpp.

References client, controller, controllerPID, msg::dispatch(), endmsg, msg::error(), msg::moreArgs(), UNIXmsg::recvNoWait(), startmsg(), msg::type(), and verbose.

Referenced by run().

int Daemon::processControlServer void   )  [protected]
 

Will accept connections from controlServer to make a new controller connnection.

When a controller is started it needs to make a 'connection' to the daemon. This connection allows messages to be passed from the client to the deamon and vica-versa. If a controller is already connected to the daemon the new connection is closed.

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 124 of file truckd.cpp.

References UNIXmsgServer::Accept(), controller, controlServer, isLocal, sock, and SOCKET.

Referenced by run().

int Daemon::processGPS void   )  [protected]
 

Reads and processes new GPS data.

Sends data to the controller (if it is running).

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 90 of file truckd.cpp.

References controller, endmsg, gps, GPS::hasPositions(), GPS::Read(), startmsg(), GPS::xPos(), and GPS::yPos().

Referenced by run().

void Daemon::quit void   )  [inline]
 

Sends signal run() to clean up and return.

This function will return immediately. But, since run() may be doing other things it could take a while for it to complete.

Returns:
max of two integer inputs
Author:
Derek King

Definition at line 107 of file truckd.h.

References _quit.

Referenced by sighandler().

int Daemon::run void   ) 
 

'Main loop' of truck daemon.

This function runs in a loop checking for new data or events. When something occurs it figures out what it is calls the appropriate function to handle it. This function doesn't return unless there is an error or quit() is called. Its a good to catch the Ctrl-C signal and call quit() so the deamon can perform some clean-up before exiting

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 581 of file truckd.cpp.

References _quit, client, connectClient(), controller, controlServer, TCPmsg::getFD(), GPS::getFD(), UNIXmsg::getFD(), gps, max(), processClient(), processController(), processControlServer(), processGPS(), and readSet.

Referenced by main().

int Daemon::runController void   )  [protected]
 

Handles the 'run' message from the client, by starting a controller program.

TODO : fix this so it doesn't just run '/usr/local/bin/controller'. Also, allow people to send command line options to controller.

Will run a new controller using the arguments provided by the client. If a controller is already running it will stop it before starting the new contoller.

Returns:
returns 0 on success and negative on error
Author:
Derek King

Definition at line 164 of file truckd.cpp.

References controllerPID, isLocal, and killController().

Referenced by processClient().


Member Data Documentation

int Daemon::_quit [protected]
 

Definition at line 50 of file truckd.h.

Referenced by quit(), and run().

TCPmsg* Daemon::client [protected]
 

Definition at line 44 of file truckd.h.

Referenced by connectClient(), processClient(), processController(), and run().

UNIXmsg* Daemon::controller [protected]
 

Definition at line 46 of file truckd.h.

Referenced by childKill(), killController(), processClient(), processController(), processControlServer(), processGPS(), and run().

int Daemon::controllerPID [protected]
 

Definition at line 48 of file truckd.h.

Referenced by childKill(), killController(), processClient(), processController(), and runController().

UNIXmsgServer Daemon::controlServer [protected]
 

Definition at line 45 of file truckd.h.

Referenced by processControlServer(), and run().

GPS* Daemon::gps [protected]
 

Definition at line 49 of file truckd.h.

Referenced by Daemon(), processGPS(), and run().

hwInterface* Daemon::hw [protected]
 

Definition at line 55 of file truckd.h.

Referenced by Daemon(), and ~Daemon().

int Daemon::isLocal [protected]
 

Definition at line 47 of file truckd.h.

Referenced by Daemon(), killController(), processControlServer(), and runController().

fd_set Daemon::readSet [protected]
 

Definition at line 59 of file truckd.h.

Referenced by run().

struct timeval Daemon::selectTO [protected]
 

Definition at line 60 of file truckd.h.

int Daemon::verbose [protected]
 

Definition at line 58 of file truckd.h.

Referenced by Daemon(), processClient(), and processController().


The documentation for this class was generated from the following files:
Generated on Fri Sep 1 14:26:00 2006 for Raptor by  doxygen 1.4.4