/* ** probe_enq_ok() ** ** does the terminal do enq/ack handshaking? */ static void probe_enq_ok(void) { int tc, len, ulen; put_str("Testing ENQ/ACK, standby..."); fflush(stdout); can_test("u8 u9", FLAG_TESTED); tty_ENQ = user9 ? user9 : "\005"; tc_putp(tty_ENQ); event_start(TIME_SYNC); /* start the timer */ read_key(tty_ACK, TTY_ACK_SIZE - 1); if (event_time(TIME_SYNC) > 400000 || tty_ACK[0] == '\0') { /* These characters came from the user. Sigh. */ tty_can_sync = SYNC_FAILED; ptext("\nThis program expects the ENQ sequence to be"); ptext(" answered with the ACK character. This will help"); ptext(" the program reestablish synchronization when"); ptextln(" the terminal is overrun with data."); ptext("\nENQ sequence from (u9): "); putln(expand(tty_ENQ)); ptext("ACK received: "); putln(expand(tty_ACK)); len = user8 ? strlen(user8) : 0; sprintf(temp, "Length of ACK %d. Expected length of ACK %d.", (int) strlen(tty_ACK), len); ptextln(temp); if (len) { temp[0] = user8[len - 1]; temp[1] = '\0'; ptext("Terminating character found in (u8): "); putln(expand(temp)); } return; } tty_can_sync = SYNC_TESTED; if ((len = strlen(tty_ACK)) == 1) { /* single character acknowledge string */ ACK_terminator = tty_ACK[0]; ACK_length = 4096; return; } tc = tty_ACK[len - 1]; if (user8) { ulen = strlen(user8); if (tc == user8[ulen - 1]) { /* ANSI style acknowledge string */ ACK_terminator = tc; ACK_length = 4096; return; } } /* fixed length acknowledge string */ ACK_length = len; ACK_terminator = -2; }
/* ** spin_flush() ** ** Wait for the input stream to stop. ** Throw away all input characters. */ void spin_flush(void) { unsigned char buf[64]; fflush(stdout); event_start(TIME_FLUSH); /* start the timer */ do { if (char_ready()) { (void) read(fileno(stdin), &buf, sizeof(buf)); } } while (event_time(TIME_FLUSH) < 400000); }
void c_main (void) { uint core = sark_core_id (); // Get core ID io_printf (IO_BUF, "Started core %d\n", core); // and print it sark_srand ((sark_chip_id () << 8) + core * sv->time_ms); // Init randgen event_register_timer (SLOT_0); // Set up the timer event mechanism event_queue_proc (timer_proc, 0, 0, PRIO_0); // Queue the first timer call uint rc = event_start (0, 0, SYNC_NOWAIT); // Start event handling io_printf (IO_BUF, "Terminated rc %d\n", rc); // Printed if event_stop used... }
int tty_sync_error(void) { int ch, trouble, ack; trouble = FALSE; for (;;) { tt_putp(tty_ENQ); /* send ENQ */ ch = getnext(STRIP_PARITY); event_start(TIME_SYNC); /* start the timer */ /* The timer doesn't start until we get the first character. After that I expect to get the remaining characters of the acknowledge string in a short period of time. If that is not true then these characters are coming from the user and we need to send the ENQ sequence out again. */ for (ack = 0; ; ) { if (ack < TTY_ACK_SIZE - 2) { tty_ACK[ack] = ch; tty_ACK[ack + 1] = '\0'; } if (ch == ACK_terminator) { return trouble; } if (++ack >= ACK_length) { return trouble; } ch = getnext(STRIP_PARITY); if (event_time(TIME_SYNC) > 400000) { break; } } set_attr(0); /* just in case */ put_crlf(); if (trouble) { /* The terminal won't sync. Life is not good. */ return TRUE; } put_str(" -- sync -- "); trouble = TRUE; } }
/* ** pad_test_startup() ** ** Do the stuff needed to begin a test. */ void pad_test_startup( int do_clear) { if (do_clear) { put_clear(); } repeats = augment; raw_characters_sent = 0; test_complete = ttp = char_count = tt_delay_used = 0; letter = letters[letter_number = 0]; if (pad_test_duration <= 0) { pad_test_duration = 1; } tt_delay_max = pad_test_duration * 1000; set_alarm_clock(pad_test_duration); event_start(TIME_TEST); }
static int dm5_gaschange(void *param, int columns, char **data, char **column) { UNUSED(columns); UNUSED(column); struct parser_state *state = (struct parser_state *)param; event_start(state); if (data[0]) state->cur_event.time.seconds = atoi(data[0]); if (data[1]) { strcpy(state->cur_event.name, "gaschange"); state->cur_event.value = lrint(strtod_flags(data[1], NULL, 0)); } /* He part of the mix */ if (data[2]) state->cur_event.value += lrint(strtod_flags(data[2], NULL, 0)) << 16; event_end(state); return 0; }
int main(void) { srand(time(NULL)); cmockaTest(); puts("\nPress ANY KEY to continue..."); getch(); system("cls"); queue_t * myQueue = queue_new(); user_t * me = user_new("Me"); user_t * firstuser = user_new("First"); user_t * seconduser = user_new("Second"); user_t * users[] = { me, firstuser, seconduser }; int usersSize = sizeof(users) / sizeof(users[0]); event_t * firstEvent = event_new("10 measurements \\ everything OK (1st event)"); event_t * secondEvent = event_new("last 5 measurements \\ not everything OK (2d event)"); event_t * thirdEvent = event_new("last 5 measurements \\ everything NOT OK (3d event)"); event_addAlertSingle(me, firstEvent, alert_fantasy); event_addAlertSingle(me, secondEvent, alert_master); event_addAlertSeveral(users, usersSize, thirdEvent, alert_common); while (!kbhit()) { event_start(firstEvent, secondEvent, thirdEvent, myQueue); } event_free(firstEvent); event_free(secondEvent); event_free(thirdEvent); for (int i = 0; i < usersSize; i++) { user_free(users[i]); } queue_free(myQueue); getch(); puts("Press ANY KEY to exit the program..."); getch(); return 0; }
int main (int argc, char **argv) { int opt; enum log_level log_level = LOG_LEVEL; int err = 0; struct event_main *event_main; struct options options = { .resolver = "localhost", }; while ((opt = getopt_long(argc, argv, "hqvdR:", long_options, NULL)) >= 0) { switch (opt) { case 'h': help(argv[0]); return 0; case 'q': log_level = LOG_ERROR; break; case 'v': log_level = LOG_INFO; break; case 'd': log_level = LOG_DEBUG; break; case 'R': options.resolver = optarg; break; default: help(argv[0]); return 1; } } // apply log_set_level(log_level); if ((err = event_main_create(&event_main))) { log_fatal("event_main_create"); goto error; } if ((err = dns_create(event_main, &options.dns, options.resolver))) { log_fatal("dns_create: %s", options.resolver); goto error; } while (optind < argc && !err) { struct dns_task task = { .options = &options, .arg = argv[optind++], }; // start async task if ((err = event_start(event_main, dns, &task))) { log_fatal("event_start: %s", task.arg); } } // mainloop if ((err = event_main_run(event_main))) { log_fatal("event_main"); } error: if (options.dns) dns_destroy(options.dns); return err; }
static int dm4_events(void *param, int columns, char **data, char **column) { UNUSED(columns); UNUSED(column); struct parser_state *state = (struct parser_state *)param; event_start(state); if (data[1]) state->cur_event.time.seconds = atoi(data[1]); if (data[2]) { switch (atoi(data[2])) { case 1: /* 1 Mandatory Safety Stop */ strcpy(state->cur_event.name, "safety stop (mandatory)"); break; case 3: /* 3 Deco */ /* What is Subsurface's term for going to * deco? */ strcpy(state->cur_event.name, "deco"); break; case 4: /* 4 Ascent warning */ strcpy(state->cur_event.name, "ascent"); break; case 5: /* 5 Ceiling broken */ strcpy(state->cur_event.name, "violation"); break; case 6: /* 6 Mandatory safety stop ceiling error */ strcpy(state->cur_event.name, "violation"); break; case 7: /* 7 Below deco floor */ strcpy(state->cur_event.name, "below floor"); break; case 8: /* 8 Dive time alarm */ strcpy(state->cur_event.name, "divetime"); break; case 9: /* 9 Depth alarm */ strcpy(state->cur_event.name, "maxdepth"); break; case 10: /* 10 OLF 80% */ case 11: /* 11 OLF 100% */ strcpy(state->cur_event.name, "OLF"); break; case 12: /* 12 High pO₂ */ strcpy(state->cur_event.name, "PO2"); break; case 13: /* 13 Air time */ strcpy(state->cur_event.name, "airtime"); break; case 17: /* 17 Ascent warning */ strcpy(state->cur_event.name, "ascent"); break; case 18: /* 18 Ceiling error */ strcpy(state->cur_event.name, "ceiling"); break; case 19: /* 19 Surfaced */ strcpy(state->cur_event.name, "surface"); break; case 20: /* 20 Deco */ strcpy(state->cur_event.name, "deco"); break; case 22: case 32: /* 22 Mandatory safety stop violation */ /* 32 Deep stop violation */ strcpy(state->cur_event.name, "violation"); break; case 30: /* Tissue level warning */ strcpy(state->cur_event.name, "tissue warning"); break; case 37: /* Tank pressure alarm */ strcpy(state->cur_event.name, "tank pressure"); break; case 257: /* 257 Dive active */ /* This seems to be given after surface when * descending again. */ strcpy(state->cur_event.name, "surface"); break; case 258: /* 258 Bookmark */ if (data[3]) { strcpy(state->cur_event.name, "heading"); state->cur_event.value = atoi(data[3]); } else { strcpy(state->cur_event.name, "bookmark"); } break; case 259: /* Deep stop */ strcpy(state->cur_event.name, "Deep stop"); break; case 260: /* Deep stop */ strcpy(state->cur_event.name, "Deep stop cleared"); break; case 266: /* Mandatory safety stop activated */ strcpy(state->cur_event.name, "safety stop (mandatory)"); break; case 267: /* Mandatory safety stop deactivated */ /* DM5 shows this only on event list, not on the * profile so skipping as well for now */ break; default: strcpy(state->cur_event.name, "unknown"); state->cur_event.value = atoi(data[2]); break; } } event_end(state); return 0; }