Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <stdint.h>
00035 #include <unistd.h>
00036 #include <time.h>
00037 #include <sys/types.h>
00038 #include <sys/stat.h>
00039 #include <sys/time.h>
00040 #include <fcntl.h>
00041
00042 #include "pigpio.h"
00043
00044
00045
00046
00047
00048
00049 #define RS (sizeof(gpioReport_t))
00050
00051 static char * timeStamp()
00052 {
00053 static char buf[32];
00054
00055 struct timeval now;
00056 struct tm tmp;
00057
00058 gettimeofday(&now, NULL);
00059
00060 localtime_r(&now.tv_sec, &tmp);
00061 strftime(buf, sizeof(buf), "%F %T", &tmp);
00062
00063 return buf;
00064 }
00065
00066 int symbol(int bit)
00067 {
00068 if (bit < 26) return ('A' + bit);
00069 else return ('a' + bit - 26);
00070 }
00071
00072 int main(int argc, char * argv[])
00073 {
00074 int b, r, v;
00075 uint32_t t0;
00076 uint32_t lastLevel, changed;
00077
00078 gpioReport_t report;
00079
00080 r=read(STDIN_FILENO, &report, RS);
00081
00082 if (r != RS) exit(-1);
00083
00084 printf("$date %s $end\n", timeStamp());
00085 printf("$version pig2vcd V1 $end\n");
00086 printf("$timescale 1 us $end\n");
00087 printf("$scope module top $end\n");
00088
00089 for (b=0; b<32; b++)
00090 printf("$var wire 1 %c %d $end\n", symbol(b), b);
00091
00092 printf("$upscope $end\n");
00093 printf("$enddefinitions $end\n");
00094
00095 t0 = report.tick;
00096 lastLevel =0;
00097
00098 while ((r=read(STDIN_FILENO, &report, RS)) == RS)
00099 {
00100 if (report.level != lastLevel)
00101 {
00102 printf("#%u\n", report.tick - t0);
00103
00104 changed = report.level ^ lastLevel;
00105
00106 lastLevel = report.level;
00107
00108 for (b=0; b<32; b++)
00109 {
00110 if (changed & (1<<b))
00111 {
00112 if (report.level & (1<<b)) v='1'; else v='0';
00113
00114 printf("%c%c\n", v, symbol(b));
00115 }
00116 }
00117 }
00118 }
00119 return 0;
00120 }
00121