views:

146

answers:

2

Hi all,

I am writing a linux testbed for wireless sensor networks. The core objective is to test data transfer between any two nodes. The network runs using tree topology. One node in the network is the "Driver". This node is connected using serial port to a linux PC. What I am trying to write is the software on this linux PC that will drive data transfer in the network.

The "Driver" node, taking commands from the software running on linux PC, will send out data request message to a Sender node. The Sender node will parse the data request message and commence data transfer to the "Driver". Multiple such Senders can exist. All data transfers is from the Senders to the "Driver" node. The "Driver" node passes all the data it receives to the linux application. The linux application keeps track of how many packets have been received from the different Senders.

Following are the requirements.

  1. Any node in the network can be the driver (destination) and any node can be the Sender.
  2. There can be multiple Senders at any give time, sending data to the "Driver" node.
  3. The data received from serial port and sent by serial port by the linux application are logged to a file.
  4. The linux application should be able to read data request messages from a file and send them out at specified times.
  5. A GUI for this linux application. All the code with be in C, so the GUI choice will have to place nice with C.

One final twist: the data from Sender to "Driver" is fragmented data. On the Sender side fragmentation is handled in the device itself. On the "Driver" side fragmentation will be handled in the linux application. So the linux application will have to keep track of the fragmentation window and send fragment ack for each of the data transfer going on with the multiple senders, and keep track of the number of packets received so far from each Sender.

So in the linux application, is the way to go having multiple threads - one thread for each Sender? Will multiple threads play nice with one serial port for sending and receiving simultaneously?

Advise on any requirement will be appreciated. The basic idea is to test data transfer, especially data gathering(several nodes sending data to one node) . If a different approach than outlined above is suggested I am more than welcome to hear them too.

Thanks a bunch

James

A: 

This is less of a question and more of an incomplete spec for a full software package. However, I'll do my best to help you out here.

Regarding single vs multithreaded: You certainly can write this in a single thread. In this approach you would probably just keep the fragment state in a data structure, and use poll() to read from all of the sensors and serial port. If you went for the multithreaded approach, you probably want to wrap your serial port access (and any other shared resources) in a mutex using pthreads.

Yeah, so I don't see any other questions you're asking here. What exactly are you looking for in addition?

bmdhacks
thanks. I think multi-threading is unncessary. Would it be a good idea to keep the whole software as one process or have the serial read write as one process that communicates with the serial port for read write and maintains a buffer/queue for the same and a different process to handle fragmentation and data received.Also I have a data structure for storing fragment state. I guess for multiple Senders, I can go with an array of that data structure.
I am thinking of a slightly different requirement. I want to run all the nodes on a single PC. The software should drive the entire network. The network will have multiple Drivers and Senders. A node cannot be Driver and Sender at same time though. A Sender will only talk to one Driver at a time. I am thinking of having one process that reads data from all serial ports. I think I can go with select() for non blocking I/O and read/write from/to several serial ports. Now how do I run each driver? Is it better to have each driver as a process or a thread? Anyother diferent architecture in mind?
+1  A: 

So in the linux application, is the way to go having multiple threads - one thread for each Sender?
Will multiple threads play nice with one serial port for sending and receiving simultaneously?

You want only one reader/sender reading/writing on the serial port. When your application blocks on output, you'll want nonblocking I/O on the port so you can respond to received chars and handle UI requests. Also, on reading, you'll want to assemble a full set of data into a complete packet. This may take multiple reads until you get a full 'packet'.

If your GUI choice is X, you can add an event handler for reading and writing the serial port with XtAppAddInput().

codeDr
thanks. For non blocking I/O, to handle reading and writing select() would be a good choice?
I am thinking of a slightly different requirement. I want to run all the nodes on a single PC. The software should drive the entire network. The network will have multiple Drivers and Senders. A node cannot be Driver and Sender at same time though. A Sender will only talk to one Driver at a time. I am thinking of having one process that reads data from all serial ports. I think I can go with select() for non blocking I/O and read/write from/to several serial ports. Now how do I run each driver? Is it better to have each driver as a process or a thread?Anyother diferent architecture in mind?
For any process managing more than one file descriptor you want to useselect() or poll() to find out which file descriptor is ready for processing. I'm not sure what system looks like, but it might be simpler to manage drivers as processes which you start/stop as necessary.
codeDr