Last active
January 17, 2023 14:47
-
-
Save agagniere/fe8a4580d29b33415eab77985c2657c1 to your computer and use it in GitHub Desktop.
Mock ptp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
#include <linux/ptp_clock.h> | |
struct external_timestamp | |
{ | |
int64_t timestamp; // ns | |
int index; | |
}; | |
#define EVAL(expr) #expr, expr | |
#define READ 0 | |
#define WRITE 1 | |
int main() | |
{ | |
int fd[2]; | |
printf("%-50s: %zu\n", EVAL(sizeof(struct external_timestamp))); | |
printf("%-50s: %zu\n", EVAL(sizeof(struct ptp_extts_event))); | |
printf("\n"); | |
pipe(fd); | |
if (!fork()) | |
{ | |
struct external_timestamp A = { .timestamp = 'n' + ('s' << 24), .index = 'I'}; | |
struct ptp_extts_event B = { | |
.t = {.sec = 's', .nsec = 'n'}, | |
.index = 'I', .flags = 'F'}; | |
close(fd[READ]); | |
write(fd[WRITE], &A, sizeof(A)); | |
write(fd[WRITE], &B, sizeof(B)); | |
exit(0); | |
} | |
else | |
{ | |
close(fd[WRITE]); | |
uint8_t buffer[1024]; | |
ssize_t count = read(fd[READ], buffer, sizeof(buffer)); | |
print_memory(buffer, count); | |
} | |
return 0; | |
} |
Author
agagniere
commented
Jan 17, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment