-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwrite_if_context_simple.c
66 lines (56 loc) · 1.92 KB
/
write_if_context_simple.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Generate VRT IF context packet and write to file. Note that this will not generate a big endian-format, i.e. standard
* conforming, packet on a little endian platform.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <vrt/vrt_init.h>
#include <vrt/vrt_string.h>
#include <vrt/vrt_types.h>
#include <vrt/vrt_util.h>
#include <vrt/vrt_write.h>
/* Size of buffer in 32-bit words */
#define SIZE 515
int main() {
/* Packet data buffer */
uint32_t b[SIZE];
/* Initialize to reasonable values */
struct vrt_packet p;
vrt_init_packet(&p);
/* Configure. Note that context packets cannot have a trailer word. */
p.header.packet_type = VRT_PT_IF_CONTEXT;
p.fields.stream_id = 0xDEADBEEF;
p.if_context.has.bandwidth = true;
p.if_context.has.sample_rate = true;
p.if_context.has.temperature = true;
p.if_context.bandwidth = 2.4e9;
p.if_context.sample_rate = 2e6;
p.if_context.temperature = 24.0F;
/* Write to buffer */
int32_t rv = vrt_write_packet(&p, b, SIZE, true);
if (rv < 0) {
fprintf(stderr, "Failed to write packet: %s\n", vrt_string_error(rv));
return EXIT_FAILURE;
}
int32_t pkt_sz = rv;
/* Write generated packet to file */
const char* file_path = "context.vrt";
FILE* fp = fopen(file_path, "wb");
if (fp == NULL) {
fprintf(stderr, "Failed to open file '%s'\n", file_path);
return EXIT_FAILURE;
}
if (fwrite(b, sizeof(uint32_t) * pkt_sz, 1, fp) != 1) {
fprintf(stderr, "Failed to write to file '%s'\n", file_path);
fclose(fp);
return EXIT_FAILURE;
}
fclose(fp);
/* Warn if not standards compliant */
if (vrt_is_platform_little_endian()) {
fprintf(stderr, "Warning: Written packet is little endian. It is NOT compliant with the VRT standard.\n");
}
return EXIT_SUCCESS;
}