-
Notifications
You must be signed in to change notification settings - Fork 4
/
rawfile.cc
64 lines (51 loc) · 1.62 KB
/
rawfile.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* ArduLogic - Low Speed Logic Analyzer using the Arduino Hardware
*
* Copyright (C) 2011 Clifford Wolf <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "ardulogic.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void writerawfile(const char *file)
{
FILE *f = fopen(file, "w");
if (f == NULL) {
fprintf(stderr, "Can't open RAW file `%s' for writing: %s\n", file, strerror(errno));
exit(1);
}
printf("Writing RAW output file `%s'.\n", file);
for (size_t i = 0; i < samples.size(); i++) {
fprintf(f, "%04x\n", samples[i]);
}
fclose(f);
}
void readrawfile(const char *file)
{
FILE *f = fopen(file, "r");
if (f == NULL) {
fprintf(stderr, "Can't open RAW file `%s' for reading: %s\n", file, strerror(errno));
exit(1);
}
printf("Reading RAW file `%s'.\n", file);
unsigned int sample;
while (fscanf(f, "%04x\n", &sample) == 1)
samples.push_back(sample);
fclose(f);
}