Ejemplo n.º 1
0
int32 GPS_Command_Get_Route(const char *port, GPS_PWay **way)
{
    int32 ret=0;

    switch(gps_route_transfer)
    {
    case pA200:
	ret = GPS_A200_Get(port,way);
	break;
    case pA201:
	ret = GPS_A201_Get(port,way);
	break;
    default:
	GPS_Error("Get_Route: Unknown route protocol");
	return PROTOCOL_ERROR;
    }

    return ret;
}    
Ejemplo n.º 2
0
int Garmin_GPS_SendRoute( wxString &port_name, Route *pr, wxGauge *pProgress)
{
      int ret_val = 0;

      int route_number = 1;

      //    If the device supports unique numbered waypoints,
      //    Then we must query the device to find an empty number
      if((gps_rte_hdr_type == pD200) || (gps_rte_hdr_type == pD201))
      {
      //    Retrieve <ALL> routes from the device
            GPS_PWay *pprouteway;
            int32 npacks = GPS_A200_Get(port_name.mb_str(), &pprouteway);
            if(npacks < 0)
                  return npacks;

            if ( pProgress )
            {
                  pProgress->SetValue ( 60 );
                  pProgress->Refresh();
                  pProgress->Update();
            }

            //  Iterate on the packets, finding the first route number from [0..9] that is not present

            //    An array of route numbers, set element to true as encountered
            bool brn[10];
            for(int i=0 ; i < 10 ; i++)
               brn[i] = false;

            for(int ip=0 ; ip < npacks ; ip++)
            {
                  GPS_PWay pway = pprouteway[ip];
                  if(pway->isrte)
                  {
                        if((pway->rte_num < 10))
                              brn[pway->rte_num] = true;
                  }
            }

            //    Find the first candidate within [1..9] that is unused
            bool bfound_empty = false;
            for(int i=1 ; i < 10 ; i++)
            {
                  if(brn[i] == false)
                  {
                        route_number = i;
                        bfound_empty = true;
                        break;
                  }
            }

            //  Ask the user if it is all right to overwrite
            if(!bfound_empty)
            {
                  int rv = OCPNMessageBox(NULL, _("Overwrite Garmin device route number 1?"),
                                          _("OpenCPN Message"), wxOK | wxCANCEL | wxICON_QUESTION);
                  if(rv != wxOK)
                        return 0;
            }

      }


      // Based on the route transfer protocol create the array of transfer packets
      GPS_SWay **ppway;
      int elements = 0;
      if (gps_route_transfer == pA201)
	ppway = Garmin_GPS_Create_A201_Route(pr, route_number, &elements);
      else
	ppway = Garmin_GPS_Create_A200_Route(pr, route_number, &elements);


      //    Transmit the Route to the GPS receiver
      int xfer_result = GPS_Command_Send_Route(port_name.mb_str(), ppway, elements);
      ret_val = xfer_result;

      //  Free all the memory
      for(int i=0 ; i < elements ; i++)
            GPS_Way_Del(&ppway[i]);

      free(ppway);


      if ( pProgress )
      {
            pProgress->SetValue ( 80 );
            pProgress->Refresh();
            pProgress->Update();
      }

      VerifyPortClosed();
      return ret_val;
}