Exemple #1
0
void _dprintf(const char* fmt, ...) {
  va_list arg;
  
  va_start(arg, fmt);
  vsprintf(temp, fmt, arg);
  va_end(arg);

  csk_uart2_puts(temp);
}
/******************************************************************************
****                                                                       ****
**                                                                           **
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() */
Exemple #3
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()