Skip to content

Commit

Permalink
Only output to /tmp/ when building with -d DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhowe committed Sep 13, 2012
1 parent 0aa19fa commit 543af39
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.c
Expand Up @@ -67,7 +67,9 @@ int doRepeat = false;
int nMissingTeeth = 1;

int fd;
#ifdef DEBUG
FILE *dbgfp;
#endif

void msleep(unsigned long msec)
{
Expand Down Expand Up @@ -145,13 +147,14 @@ int sendPacket(uint8_t* rawPacket, int rawLength)
if (write(fd, encodedPacket, encodedLength) == encodedLength) {
txSuccess = true;
tcdrain(fd);
fwrite(encodePacket, sizeof(uint8_t), encodedLength, dbgfp);
fflush(dbgfp);
} else {
txSuccess = false;
fprintf(stderr, "Write to " DEVICE " failed.\n");
msleep(RPM_PACKET_DELAY*10);
}
#else
fwrite(encodePacket, sizeof(uint8_t), encodedLength, dbgfp);
fflush(dbgfp);
#endif
return txSuccess;
}
Expand Down Expand Up @@ -430,11 +433,13 @@ void parseArg(char *arg)
int main(int argc, char **argv)
{

#ifdef DEBUG
dbgfp = fopen("/tmp/Pempheridae", "w");
if (dbgfp == NULL) {
fprintf(stderr, "Can't open /tmp/Pempheridae file.\n");
return -1;
}
#endif

struct termios oldtermios, termopts;

Expand Down Expand Up @@ -472,7 +477,9 @@ int main(int argc, char **argv)

tcsetattr(fd, TCSANOW, &oldtermios);
close(fd);
#ifdef DEBUG
fclose(dbgfp);
#endif

printf("\n");
return 0;
Expand Down

0 comments on commit 543af39

Please sign in to comment.