pig2vcd.c
Go to the documentation of this file.
1 /*
2 This is free and unencumbered software released into the public domain.
3 
4 Anyone is free to copy, modify, publish, use, compile, sell, or
5 distribute this software, either in source code form or as a compiled
6 binary, for any purpose, commercial or non-commercial, and by any
7 means.
8 
9 In jurisdictions that recognize copyright laws, the author or authors
10 of this software dedicate any and all copyright interest in the
11 software to the public domain. We make this dedication for the benefit
12 of the public at large and to the detriment of our heirs and
13 successors. We intend this dedication to be an overt act of
14 relinquishment in perpetuity of all present and future rights to this
15 software under copyright law.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 
25 For more information, please refer to <http://unlicense.org/>
26 */
27 
28 /*
29 This version is for pigpio version 3+
30 */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdint.h>
35 #include <unistd.h>
36 #include <time.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/time.h>
40 #include <fcntl.h>
41 
42 #include "pigpio.h"
43 
44 /*
45 This software converts pigpio notification reports
46 into a VCD format understood by GTKWave.
47 */
48 
49 #define RS (sizeof(gpioReport_t))
50 
51 static char * timeStamp()
52 {
53  static char buf[32];
54 
55  struct timeval now;
56  struct tm tmp;
57 
58  gettimeofday(&now, NULL);
59 
60  localtime_r(&now.tv_sec, &tmp);
61  strftime(buf, sizeof(buf), "%F %T", &tmp);
62 
63  return buf;
64 }
65 
66 int symbol(int bit)
67 {
68  if (bit < 26) return ('A' + bit);
69  else return ('a' + bit - 26);
70 }
71 
72 int main(int argc, char * argv[])
73 {
74  int b, r, v;
75  uint32_t t0;
76  uint32_t lastLevel, changed;
77 
79 
80  r=read(STDIN_FILENO, &report, RS);
81 
82  if (r != RS) exit(-1);
83 
84  printf("$date %s $end\n", timeStamp());
85  printf("$version pig2vcd V1 $end\n");
86  printf("$timescale 1 us $end\n");
87  printf("$scope module top $end\n");
88 
89  for (b=0; b<32; b++)
90  printf("$var wire 1 %c %d $end\n", symbol(b), b);
91 
92  printf("$upscope $end\n");
93  printf("$enddefinitions $end\n");
94 
95  t0 = report.tick;
96  lastLevel =0;
97 
98  while ((r=read(STDIN_FILENO, &report, RS)) == RS)
99  {
100  if (report.level != lastLevel)
101  {
102  printf("#%u\n", report.tick - t0);
103 
104  changed = report.level ^ lastLevel;
105 
106  lastLevel = report.level;
107 
108  for (b=0; b<32; b++)
109  {
110  if (changed & (1<<b))
111  {
112  if (report.level & (1<<b)) v='1'; else v='0';
113 
114  printf("%c%c\n", v, symbol(b));
115  }
116  }
117  }
118  }
119  return 0;
120 }
121 
uint32_t tick
Definition: pigpio.h:418
int main(int argc, char *argv[])
Definition: pig2vcd.c:72
#define RS
Definition: pig2vcd.c:49
int r
Definition: DHT22.py:259
void t0()
Definition: x_pigpio.c:46
static char * timeStamp()
Definition: pig2vcd.c:51
int symbol(int bit)
Definition: pig2vcd.c:66
uint32_t level
Definition: pigpio.h:419
void report(int err, char *fmt,...)
Definition: pigs.c:64


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57