|
RTC Toolkit
0.1.0-alpha
|
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <signal.h>#include <sys/time.h>#include <time.h>#include "mudpi.h"#include "math.h"#include <vector>#include <sstream>#include <fcntl.h>#include <sys/mman.h>#include <sys/shm.h>#include <sys/stat.h>Macros | |
| #define | IFNAMSIZ 16 |
| #define | LINESIZE 1024*500 |
Functions | |
| void | error (const char *msg) |
| void | sig_int (int sig) |
| int | bind_src (int sockfd, char const *ifName) |
| int | parse_args (int argc, char **argv, char *&hostname, int &portno, int &topicId, int &nframes, long &delayUs, char *&data_file, int &bufSize, bool &waitTrigger, bool &rollingRamp, int &sampleSize, int &limit) |
| void | fillSample (int samplePayloadFloats, int sampleId) |
| void | readSamples (char *filename, int samplePayloadFloats) |
| void | create_shm () |
| void | remove_shm () |
| void | signal_shm (int value) |
| void | wait_shm (int value) |
| int | main (int argc, char **argv) |
Variables | |
| int | time_to_die =0 |
| std::vector< std::vector< float > > | samplesVector |
| int | shm_fd |
| int * | shm_ptr |
| #define IFNAMSIZ 16 |
| #define LINESIZE 1024*500 |
| int bind_src | ( | int | sockfd, |
| char const * | ifName | ||
| ) |
| void create_shm | ( | ) |
we want the shm to be writeable by all so disable the umask
open or create
| void error | ( | const char * | msg | ) |
| void fillSample | ( | int | samplePayloadFloats, |
| int | sampleId | ||
| ) |
If we just ramp forever with increasing sample Id we will run out of numerical precision so when we get to 1000 increments start again
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Announce the amount of data we are sending
Either read sample values from a file or generate a ramp if no file is given
Access mudpi { int32_t topicId; uint16_t componentId; uint16_t applicationTag; uint16_t reserved; uint16_t version; uint32_t sampleId; timestamp_t timestamp; uint16_t frameId; uint16_t numFrames; uint16_t payloadSize; uint16_t reserved2; }mudpiHeader;
Fill in some fixed values for MUDPI constant fields
Create the shm seg where we coordinate instances
terminate on signal
If waiting for a trigger process, them wait, otherwise signal
If the rollingRamp flag is set then update the ramp for this sampleId if not coming from a file
Fill in some of the more interesting MUDPI fields
fill in this frame of data from the relevant part of the sample
move to the next sample and wrap around if needed
| int parse_args | ( | int | argc, |
| char ** | argv, | ||
| char *& | hostname, | ||
| int & | portno, | ||
| int & | topicId, | ||
| int & | nframes, | ||
| long & | delayUs, | ||
| char *& | data_file, | ||
| int & | bufSize, | ||
| bool & | waitTrigger, | ||
| bool & | rollingRamp, | ||
| int & | sampleSize, | ||
| int & | limit | ||
| ) |
If the sample size is set, we need to work out how many frames of buffsize we need to transport the sample
For some reason the way I would have done this in the past does not seem to work with the implementation of round on eltrtctk40 which "rounds away from 0" so that round 2.5 is 3 not 2 so the first check catches the case where sampleSize is a multiple of payloadsize
If the sample size is not set, then it's just nframes * payload
| void readSamples | ( | char * | filename, |
| int | samplePayloadFloats | ||
| ) |
Read one line at a time with a big LINESIZE
Space separated floats up to the maximum allowed
Add to the vector of samples
| void remove_shm | ( | ) |
| void sig_int | ( | int | sig | ) |
| void signal_shm | ( | int | value | ) |
Just write the value into the shm after checking the segment is good
| void wait_shm | ( | int | value | ) |
Wait for a value(sampleId) to be present in the shm or bail out if we get a signal
| std::vector<std::vector<float> > samplesVector |
| int shm_fd |
| int* shm_ptr |
| int time_to_die =0 |