dol: initial dol commit
[jump.git] / dol / examples / example5 / src / generator.c
1 #include <stdio.h>
2
3 #include "generator.h"
4
5 /**
6  * Returns a random integer in the range between lower_bound and
7  * upper_bound, where the bounding values are included in the interval.
8  */
9 int getRandomNumber(int lower_bound, int upper_bound)
10 {
11   return (rand() % (upper_bound - lower_bound + 1)) + lower_bound;
12 }
13
14
15 void generator_init(DOLProcess *p)
16 {
17   ; //nothing to be done here
18 }
19
20
21 int generator_fire(DOLProcess *p)
22 {
23   CREATEPORTVAR(output_port);
24
25   srand(0); //initialize random number generator
26
27   //generate input coefficients and write them to output ports
28   for (p->local->index = 0;
29        p->local->index < NUMBER_OF_FFT_POINTS;
30        p->local->index++) {
31     p->local->coeffs[p->local->index].real = (float)getRandomNumber(-9, 9);
32     p->local->coeffs[p->local->index].imag = (float)getRandomNumber(-9, 9);
33
34     CREATEPORT(output_port, PORT_INPUT_COEFFICIENTS, 1,
35             p->local->index, NUMBER_OF_FFT_POINTS);
36     printf("%15s: Write to input_coefficients_%d: %9f + j * %9f\n",
37            "input_generator", p->local->index,
38            p->local->coeffs[p->local->index].real,
39            p->local->coeffs[p->local->index].imag);
40     DOL_write((void*)output_port, &(p->local->coeffs[p->local->index]),
41               sizeof(ComplexNumber), p);
42   }
43
44   DOL_detach(p);
45   return -1;
46 }
47