Download Pelican User Guide

Transcript
8
Getting Started (Tutorial)
• Header + 8: A four-byte integer containing the number of samples in the packet (256).
• Header + 12: A four-byte integer containing the size of a single sample, in bytes (4).
• Header + 16: An eight-byte integer containing a monotonically-increasing packet sequence number.
The remainder of the header data is reserved. Each sample represents 10 microseconds of data, so each UDP
packet will arrive roughly every 2.56 milliseconds.
3.2.3.1
Emulating Input Stream Data
This data stream can be emulated using the classes provided in the data emulation framework. The EmulatorDriver
class takes care of the common, low-level details. It creates a separate thread in which to run the data emulator, and
is responsible for writing the data packets to the output device. On construction, the EmulatorDriver takes ownership
of a pointer to an AbstractEmulator derived class, which is called repeatedly by the driver to generate the required
data packets.
The primary function of the data emulator is to provide a pointer to a block of memory to use when sending data
packets. Since we are using a UDP stream, we can use the AbstractUdpEmulator as a base class for our SignalEmulator. Here is the C++ header file containing the class declaration:
#ifndef SIGNALEMULATOR_H
#define SIGNALEMULATOR_H
#include "emulator/AbstractUdpEmulator.h"
#include <QtCore/QByteArray>
namespace pelican {
class ConfigNode;
/*
* This emulator outputs simple packets of real-valued, floating-point,
* time-series data using a UDP socket. A sine wave is put into the time
* stream.
* It should be constructed with a configuration node that contains
* the number of samples in the packet, the interval between packets in
* microseconds, and the connection settings.
*
* The default values are:
*
* <SignalEmulator>
<packet samples="256" interval="2560" />
*
<signal period="20" />
*
<connection host="127.0.0.1" port="2001" />
*
* </SignalEmulator>
*/
class SignalEmulator : public AbstractUdpEmulator
{
public:
// Constructs a new UDP packet emulator.
SignalEmulator(const ConfigNode& configNode);
// Destroys the UDP packet emulator.
~SignalEmulator() {}
// Creates a UDP packet.
void getPacketData(char*& ptr, unsigned long& size);
// Returns the interval between packets in microseconds.
unsigned long interval() {return _interval;}
private:
unsigned long _counter; // Packet counter.
unsigned long long _totalSamples; // The total number of samples sent.
unsigned long _samples; // The number of samples in the packet.
unsigned long _interval; // The interval between packets in microsec.
unsigned long _period; // The number of samples in one period.
float _omega; // The angular frequency of the signal (from _period).
QByteArray _packet; // The data packet.
};
} // namespace pelican
#endif // SIGNALEMULATOR_H
Generated on Tue Jan 22 2013 11:07:31 for Pelican User Guide by Doxygen