Skip to content

Commit 486207c

Browse files
committed
fix outf
1 parent 2143999 commit 486207c

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

MIDAS/src/hilsim/stream/main.cpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ size_t struct_sizes[16];
1313
#define DEBUG
1414

1515
FILE* inptr;
16+
FILE* outptr;
1617

1718
// Packet: $ uint32_t:timestamp uint8_t:disc uint8_t*:data uint16_t:crc
1819
typedef struct {
@@ -110,11 +111,20 @@ void send_data(serialib& s, entry_t& dat) {
110111
memcpy(buf + 1, &dat.raw_data_stream, dat.raw_data_stream_size);
111112
memcpy(buf + 1 + dat.raw_data_stream_size, &dat.crc, sizeof(uint16_t));
112113

113-
#ifdef DEBUG
114-
printf("$");
115-
for(int i = 1; i < dat.raw_data_stream_size + 2; i++) {
116-
printf("%x", buf[i]);
114+
if(outptr) {
115+
fputs(".D $", outptr);
116+
for(int i = 1; i < dat.raw_data_stream_size + 2; i++) {
117+
fprintf(outptr, "%x", buf[i]);
118+
}
119+
fputc('\n', outptr);
120+
fflush(outptr);
117121
}
122+
123+
#ifdef DEBUG
124+
// printf("$");
125+
// for(int i = 1; i < dat.raw_data_stream_size + 2; i++) {
126+
// printf("%x", buf[i]);
127+
// }
118128
// printf("\n");
119129
#else
120130
s.writeBytes(buf, dat._data_size + num_overhead_bytes);
@@ -138,14 +148,15 @@ int main(int argc, char** argv) {
138148

139149
entry_t entry;
140150
size_t num_read = 0;
151+
uint32_t _inf_checksum;
141152

142153
auto start_time = std::chrono::high_resolution_clock::now();
143154
auto current_time = std::chrono::high_resolution_clock::now();
144155

145156
while (true) {
146157

147-
char _inbuf[128];
148-
fgets(_inbuf, 128, stdin);
158+
char _inbuf[255];
159+
fgets(_inbuf, 255, stdin);
149160
// std::cout << (uint8_t)cmd << std::endl;
150161

151162
switch(_inbuf[0]) {
@@ -158,6 +169,23 @@ int main(int argc, char** argv) {
158169
char serial_open_err = Serial.openDevice(sbuf, 115200);
159170
if (serial_open_err != 1) return wrap_err(serial_open_err);
160171
printf("SERIAL OK\n", sbuf);
172+
fflush(stdout);
173+
}
174+
break;
175+
case 'o':
176+
// (o)utfile <filepath>: Set data output path
177+
char sbuf[240];
178+
sscanf(_inbuf + 1, " %s", &sbuf);
179+
outptr = fopen(sbuf, "w+");
180+
181+
{
182+
if (outptr == NULL) {
183+
std::cerr << "Error opening file " << sbuf << std::endl;
184+
continue;
185+
}
186+
187+
printf(".OUTF %s\n", sbuf);
188+
161189
fflush(stdout);
162190
}
163191
break;
@@ -189,6 +217,7 @@ int main(int argc, char** argv) {
189217
// memcpy(&checksum, buf, sizeof(uint32_t));
190218

191219
printf(".CHECKSUM %x\n", checksum);
220+
_inf_checksum = checksum;
192221

193222
fflush(stdout);
194223
break;
@@ -232,6 +261,20 @@ int main(int argc, char** argv) {
232261
case 'r':
233262
// r(ealtime) -- streams data to com port in real time
234263
{
264+
printf(".BEGIN\n");
265+
fflush(stdout);
266+
if (!inptr) {
267+
std::cerr << "No file specified" << std::endl;
268+
break;
269+
}
270+
271+
if (outptr) {
272+
fputs(".KAMAJI_STREAM\n", outptr);
273+
fprintf(outptr, ".CHECKSUM %X\n", _inf_checksum);
274+
fputs(".BEGIN_RUN:\n", outptr);
275+
fflush(outptr);
276+
}
277+
235278
uint32_t cur_entry_time = 0;
236279
uint32_t first_entry_time = 0;
237280
long long millis = 0;

0 commit comments

Comments
 (0)