MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / main

Function main

tools/serial2xsbug/serial2xsbug_lin.c:281–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281int main(int argc, char* argv[])
282{
283 txSerialTool self = &tool;
284 int result = fxArguments(self, argc, argv);
285 if (result)
286 return result;
287 self->serialConnection = -1;
288 signal(SIGINT, handler);
289 if (setjmp(self->_jmp_buf) == 0) {
290 fxOpenSerial(self);
291 self->count = 1;
292 self->fds[0].fd = self->serialConnection;
293 self->fds[0].events = POLLIN;
294 self->fds[0].revents = 0;
295 for (;;) {
296 if (self->reconnecting) {
297 fxOpenSerial(self);
298 if (self->serialConnection >= 0) {
299 self->reconnecting = 0;
300 self->fds[0].fd = self->serialConnection;
301 }
302 else
303 usleep(500000);
304 }
305 else {
306 int res;
307 res = poll(self->fds, self->count, 1000);
308 mxThrowElse(res >= 0);
309 if (res) {
310 if (self->fds[0].revents & (POLLERR | POLLHUP)) {
311 fxCloseSerial(self);
312 self->reconnecting = 1;
313 usleep(500000);
314 continue;
315 }
316 if (self->fds[0].revents & POLLIN)
317 fxReadSerial(self);
318 if (self->count > 1) {
319 txSerialMachine machine = self->firstMachine;
320 int index = 1;
321 while (index < self->count) {
322 if (self->fds[index].revents & (POLLERR | POLLHUP))
323 mxThrowError(EPIPE);
324 if (self->fds[index].revents & POLLIN)
325 fxReadNetwork(machine);
326 machine = machine->nextMachine;
327 index++;
328 }
329 }
330 }
331 }
332 }
333 }
334 else {
335 fprintf(stderr, "%s:%d: %s\n", self->file, self->line, strerror(self->error));
336 result = 1;
337 }
338 fxCloseSerial(self);

Callers

nothing calls this directly

Calls 5

fxArgumentsFunction · 0.85
fxOpenSerialFunction · 0.70
fxCloseSerialFunction · 0.70
fxReadSerialFunction · 0.70
fxReadNetworkFunction · 0.70

Tested by

no test coverage detected