/*********************************************************************
*
*       _ServerTask
*
* Function description
*   This routine is the actual server task.
*   It executes some one-time init code, then runs in an ednless loop.
*   It therefor does not terminate.
*   In the endless loop it
*     - Waits for a conection from a client
*     - Runs the server code
*     - Closes the connection
*/
static void _ServerTask(void) {
  int s, Sock, AddrLen;
  U16 Port;

  //
  // Prepare socket (one time setup)
  //
  Port = 5900 + _Context.ServerIndex; // Default port for VNC is is 590x, where x is the 0-based layer index
  //
  // Loop until we get a socket into listening state
  //
  do {
    s = _ListenAtTcpAddr(Port);
    if (s != -1) {
      break;
    }
    OS_Delay(100); // Try again
  } while (1);
  //
  // Loop once per client and create a thread for the actual server
  //
  while (1) {
    //
    // Wait for an incoming connection
    //
    AddrLen = sizeof(_Addr);
    if ((Sock = accept(s, (struct sockaddr*)&_Addr, &AddrLen)) == SOCKET_ERROR) {
      continue; // Error
    }
    //
    // Run the actual server
    //
    GUI_VNC_Process(&_Context, _Send, _Recv, (void *)Sock);
    //
    // Close the connection
    //
    closesocket(Sock);
    memset(&_Addr, 0, sizeof(struct sockaddr_in));
  }
}
示例#2
0
/*********************************************************************
*
*       _Receive
*
*  Function description
*    Sends a command to server and receives data from server.
*/
static int _Receive(long TCPSockID) {
  U8  acBuffer[20];
  U8 Flag;
  int NumberOfBytesAtOnce;
  U32 ReceiveCnt;
  int r;

  //
  // Send command and receive data
  //
  acBuffer[0] = 'S';                                       // [0:0]: Command
  IP_StoreU32LE((void*)&acBuffer[1], NUMBER_OF_BYTES);     // [1:4]: Number of bytes
  r = send(TCPSockID, (void *) &acBuffer[0], 5, MSG_DONTWAIT); // Send command
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  ReceiveCnt = 0;
  do {
    if (USE_ZERO_COPY == 0) {                              // Using the socket interface
      NumberOfBytesAtOnce = recv(TCPSockID, _aRxTxBuffer, 1024, 0);
      if (NumberOfBytesAtOnce == SOCKET_ERROR) {
        return SOCKET_ERROR;
      } else {
        ReceiveCnt += NumberOfBytesAtOnce;
      }
    } else {                                              // Register callback for zero-copy interface
      setsockopt(TCPSockID, SOL_SOCKET, SO_CALLBACK, (void *)_rx_callback, 0);
      OS_Delay(1);
    }
  } while (ReceiveCnt < NUMBER_OF_BYTES);
  Flag = 'X';            // Confirmation
  r = send(TCPSockID, (void *) &Flag, 1, 0);
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  BSP_ToggleLED(1);
  return 0;
}
示例#3
0
文件: rtpnet.c 项目: maojxsir/upnp
/*----------------------------------------------------------------------*
                          rtp_net_connect
 *----------------------------------------------------------------------*/
int rtp_net_connect (RTP_HANDLE sockHandle, 
                     unsigned char *ipAddr, 
                     int port, int type)
{
    int sinLen;
    struct sockaddr_in sin;
    unsigned long in_addr = 0;
	int connectStatus;

    sinLen = sizeof(sin);
    memset(&sin, 0, sinLen);

    if (ipAddr)
    {
        unsigned char *ptr = (unsigned char *) &in_addr;

        ptr[0] = ipAddr[0];
        ptr[1] = ipAddr[1];
        ptr[2] = ipAddr[2];
        ptr[3] = ipAddr[3];
    }
    else
    {
        /* invalid address */
        return (-1);
    }

    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = in_addr;
    sin.sin_port = htons((unsigned short)port);

#ifdef DO_IFACE_CHECK
	while (IP_IFaceIsReady() == 0) {
	OS_Delay(100);
	}
#endif
	
	connectStatus = connect((int) sockHandle, ( struct sockaddr *) &sin, sinLen);
    if (connectStatus != 0)
    {
	  int errVal = _rtp_get_last_socket_error(sockHandle);
	  
        if ((errVal == EINPROGRESS) || 
            (errVal == EWOULDBLOCK) ||
            (errVal == EALREADY) ||
            (errVal == EISCONN))
        {
#ifdef RTP_DEBUG
            RTP_DEBUG_OUTPUT_STR("rtp_net_connect: non-fatal error returned ");
            RTP_DEBUG_OUTPUT_INT(errVal);
            RTP_DEBUG_OUTPUT_STR(".\n");
#endif
            return (-2);
        }
#ifdef RTP_DEBUG
        RTP_DEBUG_OUTPUT_STR("rtp_net_connect: error returned ");
        RTP_DEBUG_OUTPUT_INT(errVal);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    return (0);
}
示例#4
0
文件: rtpnet.c 项目: maojxsir/upnp
/*----------------------------------------------------------------------*
                           rtp_net_accept
 *----------------------------------------------------------------------*/
int rtp_net_accept (RTP_HANDLE *connectSock, RTP_HANDLE serverSock, 
                    unsigned char *ipAddr, int *port, int *type)
{
    struct sockaddr_in clientAddr;
    int clientLen;
    int conSocket;

    clientLen = sizeof(clientAddr);
    memset(&clientAddr, 0, clientLen);

#ifdef DO_IFACE_CHECK
	while (IP_IFaceIsReady() == 0) {
	OS_Delay(100);
	}
#endif
	
    conSocket = accept((int) serverSock, (struct sockaddr *) &clientAddr, &clientLen);

    if (conSocket == -1)
    {
		int errVal = _rtp_get_last_socket_error(serverSock);
	  
        *connectSock = ((RTP_HANDLE)-1);
        /* The man page for accept(2) indicates that due to Linux
           passing already-pending errors through accept, the following
           TCP/IP errors should be treated as EAGAIN:
           ENETDOWN, EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET,
           EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH. */
        if (//(errVal == EAGAIN) || 
            (errVal == EWOULDBLOCK) ||
            //(errVal == EINTR) ||
            //(errVal == ENETDOWN) ||
            //(errVal == EPROTO) ||
            (errVal == ENOPROTOOPT) ||
            //(errVal == EHOSTDOWN) ||
            //(errVal == ENONET) ||
            //(errVal == EHOSTUNREACH) ||
            (errVal == EOPNOTSUPP) ||
            (errVal == ENETUNREACH))
        {
#ifdef RTP_DEBUG
            RTP_DEBUG_OUTPUT_STR("rtp_net_accept: non-fatal error returned ");
            RTP_DEBUG_OUTPUT_INT(errVal);
            RTP_DEBUG_OUTPUT_STR(".\n");
#endif
            return (-2);
        }
#ifdef RTP_DEBUG
        RTP_DEBUG_OUTPUT_STR("rtp_net_accept: error returned ");
        RTP_DEBUG_OUTPUT_INT(errVal);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    *connectSock = (RTP_HANDLE)conSocket;
    
    if (ipAddr)
    {
        unsigned long d = clientAddr.sin_addr.s_addr;
        unsigned char *ptr = (unsigned char *) &d;
        
        *type = RTP_NET_TYPE_IPV4;
        
        ipAddr[0] = ptr[0];
        ipAddr[1] = ptr[1];
        ipAddr[2] = ptr[2];
        ipAddr[3] = ptr[3];
    }

    if (port)
    {
        *port = ntohs(clientAddr.sin_port);       
    }
    
    return (0);
}
示例#5
0
/*********************************************************************
*
*       IP_OS_Delay
*
*  Function description
*    Blocks the calling task for a given time.
*/
void IP_OS_Delay(unsigned ms) {
  OS_Delay(ms + 1);
}
/******************************************************************************
****                                            
 ****
**                                                                           **
task_supmcu_qa()


**                                                                           **
****                                                                       ****
******************************************************************************/
void task_supmcu_qa(void) {
  static int i;
  //user_debug_msg(STR_TASK_SUPMCU_QA "Stopped.");
  OS_Stop();
  user_debug_msg(STR_TASK_SUPMCU_QA  "Starting.");


#if 1
  // Init -- don't show messages yet
  sup_led_off(FALSE);
  sup_clk_off(FALSE);

  // Instructions to technician
  user_debug_msg(STR_TASK_SUPMCU_QA "Note: Ref. designators are on GPSRM module!");
  user_debug_msg(STR_TASK_SUPMCU_QA "Remove: All jumpers on Pumpkin USB Debug\r\n\t\t\t\t Adapter.");
  user_debug_msg(STR_TASK_SUPMCU_QA "Monitor: SUPMCU via Pumpkin USB Debug Adapter.");
  user_debug_msg(STR_TASK_SUPMCU_QA "Record: Minimum current from power supply.");

  // Verify Status LED can be OFF
  sup_led_on(TRUE);
  OS_Delay(250); OS_Delay(250);

  // Verify Status LED can flash
  sup_led_flash(TRUE);
  OS_Delay(250); OS_Delay(250);

  // Verify Status LED can be ON
  sup_led_off(TRUE);
  OS_Delay(250); OS_Delay(250);

  sup_led_flash(TRUE);

  // Test CLK Out signal on GPSRM 1.
  // By doing this test now, after all the other stuff is done, it gives the OEM615
  //  a chance to lock to GPS while we're testing the CLK Out functionality ...
  // Verify CLK Out commands all work -- requires a frequency counter attached to J6 (Clk Out).
  OS_Delay(250); OS_Delay(250);

  // Verify that Clk Out is OFF (i.e., 0Hz).
  sup_clk_off(TRUE);
   OS_Delay(150); OS_Delay(200); 

   /***********************************************************************************/
   /**************************************************************************************/
   /***************************************************************************************/
   // CHANGE BACK TO I<16
  // Verify that Clk Out works over the specified ranges.
  for(i=0; i<16; i++) {  //i<16
   sup_clk_on(TRUE, (15-i));
   OS_Delay(150); OS_Delay(200); 
  }
  // Leave clock at div=0 on so that Sup MCU's clock frequency can be recorded.
  #endif


  user_debug_msg(STR_TASK_SUPMCU_QA "Record: Max. frequency of CLK Out (J6).");
  OS_Delay(250);
  

if (MODULE == SIM)
    OSStartTask(TASK_SIM_QA_P);
else if (MODULE == GPS)
    OSStartTask( TASK_GPS_QA_P);
else if (MODULE == BIM)
    OSStartTask( TASK_BIM_QA_P);
else if (MODULE == PIM)
    OSStartTask( TASK_PIM_QA_P);
else if (MODULE == ALL){
    OSStartTask( TASK_PIM_QA_P);
    OS_Delay(250);
    OSStartTask( TASK_GPS_QA_P);
    OS_Delay(250);
    OSStartTask( TASK_BIM_QA_P);
    OS_Delay(250);
    OSStartTask( TASK_SIM_QA_P);
    OS_Delay(250);
}
else
   user_debug_msg(STR_TASK_SUPMCU_QA "Unrecognized SUPMCU");

  while(1) { 
    OS_Delay(250);
  }
} /* task_supmcu_qa() */
示例#7
0
/*********************************************************************
*
*       GUI_X_ExecIdle()
*
*/
void GUI_X_ExecIdle(void) {
  OS_Delay(1);
}
示例#8
0
//---------------------------------------------------------------------------//
//                                                                           //
//函数:char Proc_Show_Clock(char *NC)                                       //
//描述:电子时钟程序                                                         //
//参数:NC ——无意义                                                        //
//                                                                           //
//---------------------------------------------------------------------------//
char Proc_Show_Clock(char *NC)
{
  unsigned int temp[2]                               ;
  unsigned int Hour ,Minute,Second                   ;
  Hour    = GetRTCHOUR()                             ;
  while(Hour>=12)
  {
    Hour -= 12                                       ;
  }
  Minute  = GetRTCMIN()                              ;
  Second  = GetRTCSEC()                              ;
  Ini_Clock_Contex()                                 ;
  ShowBMP240320(BMP_CLOCK)                           ;
  Gen_Hour_Hand(Hour*30+Minute/2)                    ;
  Save_Hour_Hand_BK()                                ; 
  Draw_Hour_Hand(White)                              ;
  Gen_Minu_Hand(Minute*6+Second/10)                  ;
  Save_Minu_Hand_BK()                                ; 
  Draw_Minu_Hand(White)                              ;
  Gen_Second_Hand(Second*6)                          ;
  Save_Second_Hand_BK()                              ; 
  Draw_Second_Hand(White)                            ;
  for(;;)
  {
    if(Second==GetRTCSEC())     continue             ;
    Second   = GetRTCSEC()                           ;
    Minute  = GetRTCMIN()                            ;
    Hour    = GetRTCHOUR()                           ;
    while(Hour>=12)
    {
      Hour -= 12                                     ;
    }
    if(Minute%6==0&&Second==0)                        // 时针转动
    {
      Restore_Second_Hand_BK()                       ;
      Restore_Minu_Hand_BK()                         ;
      Restore_Hour_Hand_BK()                         ;
      Gen_Hour_Hand(Hour*30+Minute/2)                ;
      if(Second%10==0)
        Gen_Minu_Hand(Minute*6+Second/10)            ;
      Gen_Second_Hand(Second*6)                      ;
      Save_Hour_Hand_BK()                            ; 
      Draw_Hour_Hand(White)                          ;    
      Save_Minu_Hand_BK()                            ; 
      Draw_Minu_Hand(White)                          ;
      Save_Second_Hand_BK()                          ; 
      Draw_Second_Hand(White)                        ;
    }
    else if(Second%10==0)                             // 分针转动
    {
      Restore_Second_Hand_BK()                       ;
      Restore_Minu_Hand_BK()                         ;      
      Gen_Minu_Hand(Minute*6+Second/10)              ;
      Gen_Second_Hand(Second*6)                      ;
      Save_Minu_Hand_BK()                            ; 
      Draw_Minu_Hand(White)                          ;
      Save_Second_Hand_BK()                          ; 
      Draw_Second_Hand(White)                        ;
    }
    else
    {
      Restore_Second_Hand_BK()                       ;
      Gen_Second_Hand(Second*6)                      ;
      Save_Second_Hand_BK()                          ; 
      Draw_Second_Hand(White)                        ;      
    }
    OS_Delay(100)                                    ;
    if(Read_TP_Twice(&temp[0],&temp[1]))
      break                                          ;    
  }
  return 0x00                                        ;
}
示例#9
0
/******************************************************************************
****                                                                       ****
**                                                                           **
task_monitor()

This task proves the proper functioning of the passthrough feature of the
GPSRM 1. Passthrough connects the OEM615V's COM1 port to one of three pairs
of IO lines on the CSK bus: IO.[5,4], IO.[17,16] or IO.[33,32]. Which pair
is implemented depends on the GPSRM 1's Assembly Revision (ASSY REV).

task_gps() initially configures the GPSRM 1 with passthrough enabled, but
without any logging active in the OEM615V.

task_monitor() (re-)starts once commanded to by task_gps() ... this happens
after all the basic tests (I2C working, can power OEM615V on and off) are 
concluded, the OEM615V is on and not in reset, and is ready to talk via COM1.

task_monitor() then commands the OEM615V to start logging, and then scans
the resulting NMEA strings from the OEM615V for valid GPS fix and GPS data.

**                                                                           **
****                                                                       ****
******************************************************************************/
void task_monitor(void) {

  // Initially we're stopped, waiting for task_gps to configure the GPSRM1 and OEM615V.
  user_debug_msg(STR_TASK_MONITOR "Stopped.");
  OS_Stop();

  // Eventually task_gps() starts this task.
  user_debug_msg(STR_TASK_MONITOR "Starting.");

  // With GPS silent, now it's time to initialize the NMEA buffer handler.
  gps_open();

  // Init all the variables we'll be reading from the GPS (e.g. longitude).
  gps_init();

  // Now that we're ready for NMEA messages from the OEM615V, tell it to 
  //  start logging them at 1Hz on its COM1.
  // We need to send this out to all three possible paths into the GPSRM 1's
  //  passthrough port.
  // Don't forget to terminate the string with CRLF!
  csk_uart1_puts("LOG COM1 GPGGA ONTIME 1\r\n");
  csk_uart2_puts("LOG COM1 GPGGA ONTIME 1\r\n");
  csk_uart3_puts("LOG COM1 GPGGA ONTIME 1\r\n");

  // Additionally, tell the OEM615V to output a pulsetrain (2ms @ 125kHz) via the VARF output
  csk_uart1_puts("FREQUENCYOUT ENABLE 200 800\r\n");
  csk_uart2_puts("FREQUENCYOUT ENABLE 200 800\r\n");
  csk_uart3_puts("FREQUENCYOUT ENABLE 200 800\r\n");

  // Wait a few seconds for the NMEA buffers to fill ...
  OS_Delay(200);
  OS_Delay(200);


  // We remain here forever, parsing NMEA strings from the OEM615 for GPS status
  //  and data. While this is happening (and after a GPS fix has been achieved),
  //  it's a good time to test disconnecting and reconnecting the GPS antenna from
  //  the OEM615V, to see that its GPS Position Valid LED goes out when the
  //  antenna is disconnected.
  while(1) { 
    // Update gps values from incoming NMEA strings.
    gps_update();

    // Display current sats in view, HDOP, altitude, latitude & longitude if we have a fix.
    if((gps_read().fixflag&gps_fix)||(gps_read().fixflag&diffgps_fix)) {
      sprintf(strTmp, STR_TASK_MONITOR "  GMT    Sat HDOP   Alt.   Latitude   Longitude\r\n" \
                               "\t\t\t\t-----------------------------------------------\r\n" \
                               "\t\t\t\t%s %02u  %3.1f %6.1fm  %8.4f %8.4f\r\n", 
                               gps_NMEA_GMT_time_hhmmss(), gps_read().num_sat, gps_read().hdop, gps_read().altitude, gps_read().latitude, gps_read().longitude);
    } /* if() */ 
    // O/wise indicate that we do not have a fix.   
    else {
      sprintf(strTmp, STR_TASK_MONITOR "No valid GPS position -- check antenna.\r\n");
    } /* else() */
    user_debug_msg(strTmp);

    // Repeat every 5s.
    OS_Delay(250);
    OS_Delay(250);
  } /* while() */

} /* task_monitor() */
示例#10
0
/**********************************************************
*
*       USB_OS_Delay
*
* Function description
*   Delays for a given number of ms.
*/
void USB_OS_Delay(int ms) {
  OS_Delay(ms);
}
示例#11
0
void task_pi_listen(void) {
  static int received = 0;
  //static char tx_test[] = {"The quick brown fox jumps over the lazy dog!\r\n"};
  static unsigned char rx_pi_cmd[265];
  static char PI_HDR[] = "$$$";
  static char cmd[]="PITAKEIMG";
  static char msg[100];
  static char tmp[51];
  static int i=0;
  static int j;
  static int msg_length; // used for message length to/from Pi
  static BOOL PI_ON = FALSE; // flag used if Pi is on or off
  static BOOL RTS_FROM_PI = FALSE; // when Pi needs to talk to PIC
  static BOOL CTS_FROM_PI = FALSE; // when Pi needs to talk to PIC
 
  //TAKEPICPI = FALSE;
  
  dprintf("Starting task_pi_listen...\r\n");
  
  while(1) {
    while (!csk_uart0_count()) { OS_Delay(50); }
    dprintf("In task_pi_listen...\tOERR=%d\r\n",U1STAbits.OERR);

     // check for UART0 RX buffer Overflow Error and reset bit
     if (U1STAbits.OERR==1) {
         U1STAbits.OERR=0;
         csk_uart2_puts("Reset OERR in main while!\r\n");
       }

    i = 0;
    msg_length = 0;
    while(csk_uart0_count()) {
      rx_pi_cmd[i] = csk_uart0_getchar();
      if (i==4) { 
  // take the 2 hex array elements and convert to int
        sprintf(tmp,"%c%c",rx_pi_cmd[i-1],rx_pi_cmd[i]);
        msg_length = (int)strtol(tmp,NULL,16);
        //dprintf("msg_length type: %s",typeof(msg_length));
       // dprintf("i= %d  msg_length= %d %c %c",i,msg_length,rx_pi_cmd[i-1],rx_pi_cmd[i]*1);
      }
      i++;
      // check for max msg_length (cases where byte 3 isn't valid
      // OR bounds checking w/ i & msg_length
   //   if ((msg_length > 20) || (i > (msg_length+4))) { break; }
    } // end: while(csk_uart0_count())
    
    // Message from Pi header: check for "$$$"
    if (rx_pi_cmd[0]=='$' && rx_pi_cmd[1]=='$' && rx_pi_cmd[2]=='$'){
      if (!(OSReadBinSem(BINSEM_PI_ISON)) && (rx_pi_cmd[5]=='P' && rx_pi_cmd[6]=='I' && rx_pi_cmd[7]=='P' && rx_pi_cmd[8]=='O' && rx_pi_cmd[9]=='W' && rx_pi_cmd[10]=='E' && rx_pi_cmd[11]=='R' && rx_pi_cmd[12]=='E' && rx_pi_cmd[13]=='D' && rx_pi_cmd[14]=='O' && rx_pi_cmd[15]=='N') ) {
      //if (!PI_ON && msg=="PIPOWEREDON"){
      //if (msg=="PIPOWEREDON"){
       // PI_ON = TRUE;
        OSSignalBinSem(BINSEM_PI_ISON);
        //csk_uart0_puts("$$$ROGERTHAT");
        //csk_uart0_puts("$$$ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
        //csk_uart2_puts("in ROGERTHAT response\r\n");
        //sprintf(tmp, "\r\nin PIPOWERED response. PI_ON = %d\r\n", PI_ON);
       // sprintf(tmp, "$$$09ROGERTHAT\r\n");
        if (OSReadBinSem(BINSEM_TAKEPICPI)){
          csk_uart0_puts("$$$09ROGERTHAT");
        }
        //DEBUG...
//        dprintf("tmp: %s\t ",tmp);
//        dprintf("rx_pi_cmd before memset: %s\r\n",rx_pi_cmd);
      }
    } // end rx_pi_cmd header check
    //rx_pi_cmd[0] = '\0';
    memset(rx_pi_cmd, 0, sizeof(rx_pi_cmd)); // testing array clear
   // dprintf("rx_pi_cmd AFTER memset: %s\r\n",rx_pi_cmd);
    //RTS_FROM_PI = FALSE;

/*
    if (PI_ON) { // process commands for Pi...
      if (TAKEPICPI) {
        csk_uart0_puts("$$$09TAKEPICPI");
      } // end: if(TAKEPICPI)
    } // end: if(PI_ON)
*/
    
    OS_Delay(50);
  } // end while(1)
} // end task_pi_listen()
示例#12
0
/*********************************************************************
*
*       _Send
*
*  Function description
*    Sends a command to server and sends data to server.
*/
static int _Send(long TCPSockID) {
  U8  acBuffer[20];
  int NumBytesAtOnce;
  U32 SendCnt;
  U8  Flag;
  IP_PACKET * pPacket;
  int e;
  int r;

  //
  // Send command and data
  //
  acBuffer[0] = 'R';                                       // [0:0]: Command
  IP_StoreU32LE((void*)&acBuffer[1], NUMBER_OF_BYTES);     // [1:4]: Number of bytes
  r = send(TCPSockID, (void *) &acBuffer[0], 5, MSG_DONTWAIT); // Send command
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  SendCnt = 0;
  do {
    if (USE_ZERO_COPY == 0) {    // Send using sockets
      NumBytesAtOnce = send(TCPSockID, (void *)&_aRxTxBuffer[0], sizeof(_aRxTxBuffer), 0);
      if (NumBytesAtOnce == SOCKET_ERROR) {
        return NumBytesAtOnce;
      } else {
        SendCnt += NumBytesAtOnce;
      }
    } else {  // Send using Zero-copy
      U8 * pData;
      NumBytesAtOnce = sizeof(_aRxTxBuffer);
      do {
        pPacket = IP_TCP_Alloc(NumBytesAtOnce);
      } while (!pPacket);
      //
      // Fill buffer with data to send
      //
      pData = (U8*)pPacket->pData;
      memcpy(pData, "MyData", 6);
      //
      // Send data. We have to do this in the loop since we may try to send faster than we can transmit.
      //
      for (;;) {
        e = IP_TCP_Send(TCPSockID, pPacket);
        if (e >= 0) {
          break;     // Packet sent succesfully
        }
        OS_Delay(1);
      }
      SendCnt += NumBytesAtOnce;
    }
  } while (SendCnt < NUMBER_OF_BYTES);
  Flag = 0;
  //
  // Wait for response to make sure data has been sent completly
  //
  r = recv(TCPSockID, (void *) &Flag, 1, 0);
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  BSP_ToggleLED(1);
  return 0;
}
示例#13
0
extern "C" void DisplayMainTask(void)
{
  int  start_task_time, end_task_time, task_time_diff;
#ifndef __PC__
  int i;

  for (i = 4*INITIAL_BACKLIGHT; i > 0; i -= 4)
  {
    SetDutyCycleHW_1(i);
    GUI_Delay(1);
  }
#endif

  #ifdef __PC__ // Kill the rest of the system running on PC
  HWND main_wnd_handle = PcDevToolService::GetInstance()->GetControllerWindow();
  if(main_wnd_handle)
  {
    ShowWindow(main_wnd_handle, SW_SHOWNORMAL);
  }
  #endif // __PC__

  while (display_running)
  {
    start_task_time = OS_GetTime();
    mpc::display::DisplayController::GetInstance()->Run();
    GUI_Delay(5);

    #ifdef __PC__
    if( HasOSMessage() )
    {
      OS_EnterRegion();
      OS_IncDI();
      OSMessage* msg;

      // Get message from queue without removing it.
      msg = PeekOSMessage();
      switch(msg->message)
      {
      case 0:
        break;
      case OSMSG_LOAD_DISPLAY:
        msg->rc = PcDevToolService::GetInstance()->LoadDisplay((const char*)(msg->data));
        break;
      case OSMSG_LOAD_DISPLAY_ID:
        msg->rc = PcDevToolService::GetInstance()->LoadDisplay(*(int*)(msg->data));
        break;
      case OSMSG_SET_LANGUAGE:
        Languages::GetInstance()->SetLanguage(*((LANGUAGE_TYPE*)msg->data));
        msg->rc = 0;
        break;
      case OSMSG_GET_LANGUAGE:
        msg->rc = Languages::GetInstance()->GetLanguage();        
        break;
      case OSMSG_DUMP_SCREEN:
        mpc::display::DisplayDumper::GetInstance()->DumpScreen(false);
        msg->rc = 0;
        break;
      case OSMSG_DUMP_SCREENS:
        mpc::display::DisplayDumper::GetInstance()->DumpScreens(true, false);
        msg->rc = 0;
        break;
      case OSMSG_SET_SUBJECT_VALUE:
        msg->rc = PcDevToolService::GetInstance()->SetSubjectValue( ((SubjectValueParameters*)msg->data) );
        break;
      case OSMSG_GET_SUBJECT_VALUE_AS_FLOAT:
        msg->rc = PcDevToolService::GetInstance()->GetSubjectValue( ((SubjectValueParameters*)msg->data) );
        break;
      case OSMSG_SET_SUBJECT_QUALITY:
        msg->rc = PcDevToolService::GetInstance()->SetSubjectQuality( ((QualityParameters*)msg->data) );
        break;
      case OSMSG_SET_DI_VALUE:
        msg->rc = PcSimulatorService::GetInstance()->SetDiValue( ((DiParameters*)msg->data) );
        break;
      case OSMSG_SET_AI_VALUE_PERCENT:
        msg->rc = PcSimulatorService::GetInstance()->SetAiValueInPercent( ((AiParameters*)msg->data) );
        break;
      case OSMSG_SET_AI_VALUE_INTERNAL:
        msg->rc = PcSimulatorService::GetInstance()->SetAiValueInInternalUnit( ((AiParameters*)msg->data) );
        break;
      case OSMSG_SELECT_LISTVIEW_ITEM_BY_INDEX:
        msg->rc = PcDevToolService::GetInstance()->SelectListViewItem(*(int*)(msg->data));
        break;
      case OSMSG_KEY_PRESS:
        GUI_StoreKey(*(int*)(msg->data));
        msg->rc = 0;
        break;
      case OSMSG_SET_ERROR_PRESENT:
        msg->rc = PcSimulatorService::GetInstance()->SimulateAlarm( ((AlarmParameters*)msg->data) );
        break;
      case OSMSG_EXPORT_STRING_LENGTHS:
        mpc::display::StringWidthCalculator::GetInstance()->ExportStringWidths((const char*)(msg->data));
        msg->rc = 0;
        break;
      case OSMSG_EXPORT_STRING_LENGTHS_ADV:
        mpc::display::StringWidthCalculator::GetInstance()->ExportStringWidthsAdv(((mpc::display::StringWidthParameters*)(msg->data)));
        msg->rc = 0;
        break;
      case OSMSG_SET_IO111_VALUES:
        msg->rc = PcSimulatorService::GetInstance()->SetIO111Values( ((Io111Parameters*)msg->data) );
        break;
      default:
        msg->rc = -1;
        break;
      }
      // Remove message from queue
      DisposeOSMessage();

      OS_DecRI();
      OS_LeaveRegion();
      OS_Delay(1);
    }
    #endif //__PC__

    // calculate time to wait
    end_task_time = OS_GetTime();
    task_time_diff = end_task_time - start_task_time;

    if( task_time_diff <= 1 )
      OS_WaitSingleEventTimed( POWER_DOWN_EVENT, DISPLAY_SAMPLE_TIME );         // We will skip ...
    else if ( task_time_diff > (DISPLAY_SAMPLE_TIME-1) )
      OS_WaitSingleEventTimed( POWER_DOWN_EVENT, 1 );                          // Run again, now
    else
      OS_WaitSingleEventTimed( POWER_DOWN_EVENT, DISPLAY_SAMPLE_TIME - task_time_diff );
  }
#ifndef __PC__
  LCDPowerDown();                     // TODO: Check the for-loops !! It takes a lot of time
#endif
  SignalEventToPowerDown(DISPLAY_POWERED_DOWN_EVENT);
#ifndef __PC__
  while (1)                                                                    // We will die anyway
  {
    GUI_Delay(1000);
  }
#endif
}
示例#14
0
/******************************************************************************
****                                                                       ****
**                                                                           **
task_gps()

Interfaces to the GPSRM 1 as part of test.


**                                                                           **
****                                                                       ****
******************************************************************************/
void task_gps_qa(void) {
  
  //user_debug_msg(STR_TASK_GPS_QA "Stopped.");
  OS_Stop();

  user_debug_msg(STR_TASK_GPS_QA  "Starting.");

#if 1
  OS_Delay(250); OS_Delay(250);

  // Init -- don't show messages yet
  gps_res_off(FALSE);
  gps_pow_off(FALSE);
  gps_pass_off(FALSE);
  gps_log_off(FALSE); // NOT RECOGNIZED

  // Instructions to technician
  user_debug_msg(STR_TASK_GPS_QA  "Note: Ref. designators are on GPSRM module!");
  user_debug_msg(STR_TASK_GPS_QA  "Plug: GPS antenna with MCX connector into\r\n\t\t\t\t GPSRM from below.");
  user_debug_msg(STR_TASK_GPS_QA  "Install: +5V_USB Interruptor onto Dev Board.");
  user_debug_msg(STR_TASK_GPS_QA  "Install: GPSRM onto +5V_USB Interruptor.");
  user_debug_msg(STR_TASK_GPS_QA  "Monitor: GPSRM via Pumpkin USB Debug Adapter.");


  // Verify GPS power can be forced ON and OFF. Requires that GPSRM be plugged into the bus such that
  //  it does not receive USB power ... easily done with an H1/H2 connector pair with H1.32 (+5V_USB) 
  //  cut off
 // gps_led_gps(FALSE);
  // OS_Delay(250); OS_Delay(250);
  gps_pow_on(TRUE);
  OS_Delay(250); OS_Delay(250);
  gps_res_off(FALSE);
  OS_Delay(250); OS_Delay(250);
  user_debug_msg(STR_TASK_GPS_QA  "Verify: GPSRM LED (D2) is ON."); 
  OS_Delay(250); OS_Delay(250);
  OS_Delay(250); OS_Delay(250);

  gps_res_on(FALSE);
   OS_Delay(250); OS_Delay(250);
  gps_pow_off(TRUE);
   OS_Delay(250); OS_Delay(250);
  user_debug_msg(STR_TASK_GPS_QA  "Verify: GPSRM LED (D2) is OFF."); 
  OS_Delay(250); OS_Delay(250);
  OS_Delay(250); OS_Delay(250);

  // OK, done with that, continue with GPS powered and indicated.
  gps_res_off(FALSE);
   OS_Delay(250); OS_Delay(250);
  gps_pow_on(FALSE);
   OS_Delay(250); OS_Delay(250);
 // gps_led_gps(TRUE);
//   OS_Delay(250); OS_Delay(250);

  // Verify that the -RESET signal can be used to force the OEM615 into reset ...
  //  (Cover must not be on OEM615 during this test).
  gps_res_on(TRUE);
  user_debug_msg(STR_TASK_GPS_QA  "Verify: OEM615 LED is RED.");
  OS_Delay(250); OS_Delay(250);

  gps_res_off(TRUE);
  user_debug_msg(STR_TASK_GPS_QA  "Verify: OEM615 LED is GREEN.");
  OS_Delay(250); OS_Delay(250);

#else
  // bypass for faster debugging
  gps_pow_on(TRUE);
  gps_res_off(TRUE);
  gps_log_off(FALSE);
#endif
  gps_pass_on(TRUE);
  //gps_log_gga(TRUE);

  // Everything looks pretty good -- go ahead and let the OEM615 run without interference,
  //  so that it can acquire a lock. The direct USB connection to the OEM615 can be made at this time ...
  //user_debug_msg(STR_TASK_TEST "OEM615 will now acquire GPS satellites ...");
  //user_debug_msg(STR_TASK_TEST "Connect NovAtel CDU software to GPSRM\r\n\t\t\t\t via GPS (micro) USB connector.");

  user_debug_msg(STR_TASK_GPS_QA  "Verify: GPS is talking.");
  
  user_debug_msg(STR_TASK_GPS_QA  "Connect: CLK Out (J6) to freq. counter.");
  user_debug_msg(STR_TASK_GPS_QA  "Connect: PPS Out (J7) to oscilloscope.");
  user_debug_msg(STR_TASK_GPS_QA  "Connect: VARF Out (J8) to oscilloscope.");


  // Now we're ready to see if GPS is talking ...
  // Firmware update to GPSRM 1 Rev C should allow us to know when lock has been achieved ...
  OSStartTask(TASK_MONITOR_P);

  while(1) { 
    OS_Delay(250);

    // Hit it with a burst of commands, just to exercise the counters ...
    /* aek 20141027
    gps_led_on(FALSE);
    gps_led_gps(FALSE);
    gps_led_on(FALSE);
    gps_led_gps(FALSE);
    */
  }
} /* task_gps_qa() */
示例#15
0
/*----------------------------------------------------------------------*
                          rtp_term_promptstring
 *----------------------------------------------------------------------*/
int rtp_term_promptstring (char * string, unsigned int handle_arrows)
{
/* ----------------------------------- */
/*  Endptr always points to            */
/*  null-terminator.                   */
/* ----------------------------------- */
char * endptr = &string[rtp_strlen(string)];
int ch;
char clbuff[80];

	rtp_memset((unsigned char *)clbuff, ' ', 79);
	clbuff[0] = '\r';
	clbuff[78] = '\r';
	clbuff[79] = 0;

#define CLEAR_LINE() rtp_term_cputs(clbuff)

    /* ----------------------------------- */
	/*  Print out the default answer.      */
	/* ----------------------------------- */
	rtp_term_cputs(string);

    while (!rtp_term_kbhit( ))
    {
        /* ----------------------------------- */
        /*  Free resources to time critical    */
        /*  events.                            */
        /* ----------------------------------- */
        OS_Delay(2);
    }
    
    ch = rtp_term_getch( );
	while (ch != -1)
	{
		switch(ch)
		{
		    /* ----------------------------------- */
			/*  Return.                            */
			/* ----------------------------------- */
		    case '\n':
		    case '\r':
			    rtp_term_putc('\n');
			    return (0);

            /* ----------------------------------- */
			/*  Backspace.                         */
			/* ----------------------------------- */
		    case '\b':
			    if(endptr > string)
			    {
				    rtp_term_cputs("\b \b");
				    *(--endptr) = 0;
			    }               /* ----------------------------------- */
			    goto getnext;   /*  Get next character.                */
			                    /* ----------------------------------- */
			                
		    case TERMINAL_UP_ARROW:
			    if(handle_arrows)
			    {
			        /* ----------------------------------- */
				    /*  Erase the current line.            */
				    /* ----------------------------------- */
				    CLEAR_LINE();                       /* ----------------------------------- */
				    return (rtp_term_up_arrow ( ));     /*  TERMINAL_UP_ARROW                  */
			    }                                       /* ----------------------------------- */
			    break;

		    case TERMINAL_DOWN_ARROW:
			    if(handle_arrows)
			    {
			        /* ----------------------------------- */
				    /*  Erase the current line.            */
				    /* ----------------------------------- */
				    CLEAR_LINE();                       /* ----------------------------------- */
				    return (rtp_term_down_arrow ( ));   /*  TERMINAL_DOWN_ARROW                */
			    }                                       /* ----------------------------------- */
			    break;

		    case TERMINAL_ESCAPE:
			    if(handle_arrows)
			    {
				    /* ----------------------------------- */
				    /*  Erase the current line.            */
				    /* ----------------------------------- */
				    CLEAR_LINE();                       /* ----------------------------------- */
				    return (rtp_term_escape_key ( ));   /*  TERMINAL_ESCAPE                    */
			    }                                       /* ----------------------------------- */
			    break;
		}

        /* ----------------------------------- */
		/*  Display the editing.               */
		/* ----------------------------------- */
		rtp_term_putc((char)ch);
		*endptr++ = (char)ch;
		*endptr = 0;

getnext:
        while (!rtp_term_kbhit( ))
        {
            /* ----------------------------------- */
            /*  Free resources to time critical    */
            /*  events.                            */
            /* ----------------------------------- */
            OS_Delay(2);
        }
        
        ch = rtp_term_getch( );
	}
	return (-1);
}
示例#16
0
/*********************************************************************
*
*       HPTask
*/
static void HPTask(void) {
  while (1) {
    BSP_ToggleLED(0);
    OS_Delay (50);
  }
}
static void HPTask(void) {
    _start_kernel(0);
  while (1) {
    OS_Delay (1000);
  }
}
示例#18
0
void GUI_X_Delay(int Period) {
  OS_Delay(Period);
}
void osDelayTask(systime_t delay)
{
   //Delay the task for the specified duration
   OS_Delay(OS_MS_TO_SYSTICKS(delay));
}
示例#20
0
//---------------------------------------------------------------------------//
//                                                                           //
//函数:void Key_TP_Task(void)                                               //
//描述:键盘与触摸屏扫描,编辑控件光标闪烁                                   //
//		                                                             //
//---------------------------------------------------------------------------//
void Key_TP_Task(void)
{
  unsigned char flicker_cnt = 0                             ;
  char key = 0xFF,last_key = 0xFF, down_cnt = 0, tp_cnt = 0 ;
  char rx_char                                              ;
  union 
  {
    unsigned int  pos[2]                                    ;
    char byte[4]                                            ;
  }TPoint                                                   ;
  char event                                                ;
  Init_KeyPad()                                             ; 
  TP_Init()                                                 ;
  OS_CREATEMB(&MBKeyTP, 1, sizeof(MBKeyTPBuffer),
              &MBKeyTPBuffer                     )          ; // 创建键盘、触摸屏消息邮箱
  OS_CREATEMB(&MBRX,1,sizeof(MBRXBuffer),&MBRXBuffer)       ; // 创建端口接收邮箱
  for(;;)
  {
    event  = 0x00                                           ;
    if(++flicker_cnt>50)                                      // 界面闪烁元素
    {
      flicker_cnt = 0x00                                    ;
      event = EVENT_FLICKER                                 ;
    }
    key = ReadKey()                                         ; // 按键扫描
    if(key!=last_key&&key!=0xFF)
      down_cnt  =  0                                        ;
    else if(key!=last_key&&key==0xFF)
    {
      if(down_cnt>3)
        event    |= EVENT_KEY_PRESSED                       ;
    }
    else if(key==last_key&&key!=0xFF)
      if(++down_cnt>4) down_cnt = 4                         ;
    OS_Use(&SemaSPI)                                        ;
    Init_TPSPI()                                            ;
    if(!Read_TP_Twice(&TPoint.pos[0],&TPoint.pos[1]))         // 触摸屏扫描         
    {
      if(tp_cnt>3)
        event  |= EVENT_TP_PRESSED                          ;
      tp_cnt   = 0                                          ;
    }
    else 
    {
      if(++tp_cnt>8)      tp_cnt     = 8                    ;
      if(tp_cnt>4)
      {
        Convert_Pos( TPoint.pos[0], TPoint.pos[1],   
                    &TPoint.pos[0],&TPoint.pos[1] )         ;
        event  |= EVENT_TP_TOUCHED                          ;
      }
    }
    OS_Unuse(&SemaSPI)                                      ;
    
    if(OS_GetMessageCnt(&MBRX))
    {
      OS_GetMail(&MBRX,&rx_char)                            ;
      event    |= RX_RECEIVED                               ;
    }
    if(event)                                                 // 发送系统消息
    {
      if(  !OS_GetSuspendCnt(&LCD_TASK_TCB)
         ||!OS_GetSuspendCnt(&MENU_OP_TASK_TCB))
      {
        OS_PutMail1(&MBKeyTP, &event)                       ;
        OS_PutMail1(&MBKeyTP, &last_key)                    ;
        OS_PutMail1(&MBKeyTP, &rx_char)                     ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[0])              ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[1])              ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[2])              ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[3])              ; 
      }
    }
    last_key = key                                          ;
    OS_Delay(10)                                            ;
  }
}