posix_app.c
来自「fsmlabs的real time linux的内核」· C语言 代码 · 共 35 行
C
35 行
#include <fcntl.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#define NANOSECONDS_PER_TICK (double)((double)1000.00/(double)366.00) int main(int argc, char ** argv){ int fd; int count=0 ; struct { int count; unsigned int d;}D; double f; if( (fd = open("/dev/rtf0",O_RDONLY) ) < 0 ){ perror("Can't open fifo"); exit(0); } while( (read(fd,&D,sizeof(D)) == sizeof(D))){ f = (double)D.d; f = ((f) * NANOSECONDS_PER_TICK)/1000; printf("Delay was %f microseconds\n",f); if(count && (count+1 != D.count)) printf("Dropped a packet at %d ",count); count = D.count; } close(fd); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?