-
- // We have a completed response.
- memcpy(command, rx, sizeof(UsbCommand));
- return true;
- }
-
- if (prx == rx) {
- // We got no complete command while waiting, give up control
- return false;
- }
- }
-
- // did not get a complete command before being cancelled.
- return false;
-}
-
-// Worker thread for processing incoming events from the PM3
-void *uart_receiver(void *targ) {
- receiver_arg *conn = (receiver_arg*)targ;
- UsbCommand rx;
-
- while (conn->run) {
- #ifdef COMMS_DEBUG
- printf("uart_receiver: get lock\n");
- #endif
- // Lock up receives, in case they try to take it away from us.
- pthread_mutex_lock(&conn->recv_lock);
- #ifdef COMMS_DEBUG
- printf("uart_receiver: lock acquired\n");
- #endif
-
- if (port == NULL) {
- #ifdef COMMS_DEBUG
- printf("uart_receiver: port disappeared\n");
- #endif
- // Our port disappeared, stall. This code path matters for the flasher,
- // where it is fiddling with the serial port under us.
- pthread_mutex_unlock(&conn->recv_lock);
- msleep(10);
- continue;