diff --git a/sim_frontpanel.c b/sim_frontpanel.c index ef77816e..6d8559fc 100644 --- a/sim_frontpanel.c +++ b/sim_frontpanel.c @@ -1482,6 +1482,7 @@ while ((p->sock != INVALID_SOCKET) && pthread_mutex_unlock (&p->io_lock); new_data = sim_read_sock (p->sock, &buf[buf_data], sizeof(buf)-(buf_data+1)); if (new_data <= 0) { + pthread_mutex_lock (&p->io_lock); sim_panel_set_error ("%s", sim_get_err_sock("Unexpected socket read")); _panel_debug (p, DBG_RCV, "%s", NULL, 0, sim_panel_get_error()); p->State = Error; @@ -1491,9 +1492,11 @@ while ((p->sock != INVALID_SOCKET) && buf_data += new_data; buf[buf_data] = '\0'; s = buf; - while ((eol = strchr (s, '\r'))) { + while ((eol = strchr (s, '\n'))) { /* Line to process */ *eol++ = '\0'; + while ((*s) && (s[strlen(s)-1] == '\r')) + s[strlen(s)-1] = '\0'; e = strchr (s, ':'); if (e) { size_t i; @@ -1582,6 +1585,7 @@ while ((p->sock != INVALID_SOCKET) && /* Non Register Data Found (echo of EXAMINE or other commands and/or command output) */ if (p->io_waiting) { char *t; + if (p->io_response_data + strlen (s) + 3 > p->io_response_size) { t = (char *)_panel_malloc (p->io_response_data + strlen (s) + 3); if (t == NULL) { @@ -1649,11 +1653,15 @@ pthread_setschedparam (pthread_self(), sched_policy, &sched_priority); pthread_mutex_lock (&p->io_lock); p->callback_thread_running = 1; +pthread_mutex_unlock (&p->io_lock); pthread_cond_signal (&p->startup_cond); /* Signal we're ready to go */ +msleep (100); +pthread_mutex_lock (&p->io_lock); while ((p->sock != INVALID_SOCKET) && (p->callbacks_per_second) && (p->State != Error)) { int rate = p->callbacks_per_second; + pthread_mutex_unlock (&p->io_lock); ++callback_count; @@ -1662,7 +1670,7 @@ while ((p->sock != INVALID_SOCKET) && } msleep (1000/rate); pthread_mutex_lock (&p->io_lock); - if (((p->State == Run) || (0 == callback_count%(5*rate))) && + if (((p->State == Run) || ((p->State == Halt) && (0 == callback_count%(5*rate)))) && (p->io_reg_query_pending == 0)) { ++p->io_reg_query_pending; pthread_mutex_unlock (&p->io_lock); @@ -1672,6 +1680,8 @@ while ((p->sock != INVALID_SOCKET) && } pthread_mutex_lock (&p->io_lock); } + else + _panel_debug (p, DBG_XMT, "Waiting for prior register query completion", NULL, 0); } p->callback_thread_running = 0; pthread_mutex_unlock (&p->io_lock); @@ -1764,8 +1774,8 @@ while (1) { /* format passed string, arg if (buf != stackbuf) free (buf); bufsize = bufsize * 2; - if (bufsize < len + 2) - bufsize = len + 2; + if (bufsize < (len + post_fix_len + 2)) + bufsize = len + post_fix_len + 2; buf = (char *) _panel_malloc (bufsize); if (buf == NULL) return -1; diff --git a/sim_frontpanel.h b/sim_frontpanel.h index 2de866ed..cdd1ecd7 100644 --- a/sim_frontpanel.h +++ b/sim_frontpanel.h @@ -55,7 +55,7 @@ extern "C" { #include -#if !defined(__VAX) /* Supported platform */ +#if !defined(__VAX) /* Unsupported platform */ #define SIM_FRONTPANEL_VERSION 1 @@ -171,10 +171,14 @@ sim_panel_add_register_indirect (PANEL *panel, the current register state at the desired rate. - Note 1: The buffers described in a panel's register set will be dynamically - revised as soon as data is available from the simulator. The - callback routine merely serves as a notification that a complete - register set has arrived. + Note 1: The buffers described in a panel's register set will be + dynamically revised as soon as data is available from the + simulator. The callback routine merely serves as a notification + that a complete register set has arrived. + Note 2: The callback routine should, in general, not run for a long time + or frontpanel interactions with the simulator may be disrupted. + Setting a flag, signaling an event or posting a message are + reasonable activities to perform in a callback routine. */ int @@ -228,7 +232,8 @@ sim_panel_exec_step (PANEL *panel); sim_panel_gen_deposit - Deposit to register or memory sim_panel_mem_examine - Examine memory location sim_panel_mem_deposit - Deposit to memory location - sim_panel_set_register_value - + sim_panel_set_register_value - Deposit to a register or memory + location */ @@ -377,6 +382,8 @@ sim_panel_get_state (PANEL *panel); All APIs routines which return an int return 0 for success and -1 for an error. + + An API which returns an error (-1), will not change the panel state. sim_panel_get_error - the details of the most recent error sim_panel_clear_error - clears the error buffer