-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestsource.c
More file actions
39 lines (34 loc) · 852 Bytes
/
testsource.c
File metadata and controls
39 lines (34 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
int main()
{
int fd;
fd = open("softscope.fifo", O_WRONLY);
if(fd < 0) {
perror("Open softscope.fifo");
return -1;
}
float data[4];
int t;
while(1) {
data[0] = ((float) sin((float)t / 10.) * 10000.);
data[1] = ((float) sin((float)t / 8.) * 5000.);
data[2] = ((float) sin((float)t / 15.) * 14000.);
data[3] = ((float) sin((float)t / 25.) * 8000.);
if(write(fd, &data, sizeof(data)) != sizeof(data)) {
perror("Write to file");
break;
}
t++;
usleep(10000); // 10 ms
}
if(close(fd) < 0) {
perror("Close softscope.fifo");
return -1;
}
return 0;
}