void TimerClass::Notify () { int i; // Service the joystick. In all cases, the idea here is that yaAcaFrame's // Roll, Pitch, and Yaw structures are updated with current information // with respect to the joystick hardware and/or joystick drivers. ServiceJoystick_wxWidgets (); // Convert the readings to the form expected by yaAcaFrame, update screen, // output to yaAGC. yaAcaFrame->UpdateJoystick (); // Service the socket connection. if (StartupDelay > 0) { StartupDelay -= PULSE_INTERVAL; return; } // Try to connect to the server (yaAGC) if not already connected. if (ServerSocket == -1) { ServerSocket = CallSocket (Hostname, Portnum); if (ServerSocket != -1) printf ("yaACA2 is connected, socket=%d.\n", ServerSocket); } if (ServerSocket != LastServerSocket) { if (ServerSocket == -1) yaAcaFrame->StatusLabel->SetLabel (wxT ("Waiting for connection to yaAGC ...")); else yaAcaFrame->StatusLabel->SetLabel (wxT ("Connected to yaAGC")); LastServerSocket = ServerSocket; } }
static int PulseACA (void) { if (StartupDelay > 0) { StartupDelay -= UPDATE_INTERVAL; return (1); } // Try to connect to the server (yaAGC) if not already connected. if (ServerSocket == -1) { ServerSocket = CallSocket (Hostname, Portnum); if (ServerSocket != -1) fprintf (stdout, "\nConnection to server established on socket %d\n", ServerSocket); else StartupDelay = 1000; } if (ServerSocket != -1) { static unsigned char Packet[4]; static int PacketSize = 0; int i; unsigned char c; for (;;) { i = recv (ServerSocket, &c, 1, MSG_NOSIGNAL); if (i == -1) { // The condition i==-1,errno==0 or 9 occurs only on Win32, and // I'm not sure exactly what it corresponds to---I assume // means "no data" rather than error. if (errno == EAGAIN || errno == 0 || errno == 9) i = 0; else { fprintf (stdout, "\nyaACA3 reports server error %d\n", errno); close (ServerSocket); ServerSocket = -1; break; } } if (i == 0) break; if (0 == (0xc0 & c)) PacketSize = 0; if (PacketSize != 0 || (0xc0 & c) == 0) { Packet[PacketSize++] = c; if (PacketSize >= 4) { PacketSize = 0; // *** Do something with the input packet. *** } } } } return (1); }
void TimerClass::Notify() { static unsigned char Packet[4]; static int PacketSize = 0; static int FlashCounter = 1, FlashStatus = 0; int i; unsigned char c; if (StartupDelay > 0) { StartupDelay -= PULSE_INTERVAL; return; } // If the noun/verb-flash flag is set, then flash them. if (frame->flashing) { frame->flashCounter++; if (frame->flashCounter >= 1000 / PULSE_INTERVAL) { frame->flashCounter = 0; frame->flashStateLit = !frame->flashStateLit; if (frame->flashStateLit) { //frame->labelVerb->SetBitmap(frame->imageVerbLabelOn); //frame->labelNoun->SetBitmap(frame->imageNounLabelOn); frame->digitVerbLeft->SetBitmap(frame->image7Seg0); frame->digitVerbRight->SetBitmap(frame->image7Seg0); frame->digitNounLeft->SetBitmap(frame->image7Seg0); frame->digitNounRight->SetBitmap(frame->image7Seg0); } else { //frame->labelVerb->SetBitmap(frame->imageVerbLabelOff); //frame->labelNoun->SetBitmap(frame->imageNounLabelOff); frame->digitVerbLeft->SetBitmap(frame->officialVerbLeft); frame->digitVerbRight->SetBitmap(frame->officialVerbRight); frame->digitNounLeft->SetBitmap(frame->officialNounLeft); frame->digitNounRight->SetBitmap(frame->officialNounRight); } } } // Try to connect to the server (yaAGC) if not already connected. if (ServerSocket == -1) { ServerSocket = CallSocket(Hostname, Portnum); if (ServerSocket != -1) printf("yaDSKY is connected.\n"); } if (ServerSocket != -1) { for (;;) { i = recv(ServerSocket, (char *) &c, 1, MSG_NOSIGNAL); if (i == -1) { // The conditions i==-1,errno==0 or 9 occur only on Win32, // and I'm not sure exactly what they corresponds to---but // empirically I find that ignoring them makes no difference // to the operation of the program. if (errno == EAGAIN || errno == 0 || errno == 9) i = 0; else { printf("yaDSKYb1: server error %d\n", errno); close(ServerSocket); ServerSocket = -1; break; } } if (i == 0) break; // This (newer) code will accept any packet signature of the form // 00 XX XX XX. if (0 == (0xc0 & c)) PacketSize = 0; if (PacketSize != 0 || (0xc0 & c) == 0) { Packet[PacketSize++] = c; if (PacketSize >= 4) { ActOnIncomingIO(Packet); PacketSize = 0; } } } } }