Example #1
0
int32 GPS_Command_Off(const char *port)
{
    static UC data[2];
    gpsdevh *fd;
    GPS_PPacket tra;
    GPS_PPacket rec;

    GPS_Util_Little();

    if(!GPS_Device_On(port, &fd))
	return gps_errno;

    if(!(tra = GPS_Packet_New()) || !(rec = GPS_Packet_New()))
	return MEMORY_ERROR;

    GPS_Util_Put_Short(data,COMMAND_ID[gps_device_command].Cmnd_Turn_Off_Pwr);
   
    /* robertl - LINK_ID isn't set yet.  Hardcode it to Garmin spec value */ 
    GPS_Make_Packet(&tra, 10, /* LINK_ID[gps_link_type].Pid_Command_Data, */
		    data,2);
    if(!GPS_Write_Packet(fd,tra))
	return gps_errno;

    if(!GPS_Device_Chars_Ready(fd))
    {
	if(!GPS_Get_Ack(fd, &tra, &rec))
	    return gps_errno;
	GPS_User("Power off command acknowledged");
    }

    GPS_Packet_Del(&tra);
    GPS_Packet_Del(&rec);

    if(!GPS_Device_Off(fd))
	return gps_errno;

    return 1;
}
Example #2
0
void VerifySerialPortClosed()
{
      if(g_gps_devh)
            GPS_Device_Off(g_gps_devh);
}
Example #3
0
/* @func GPS_Command_Send_Course ***************************************
**
** Send Courses to GPS. According to Garmin protocol specification, this
** includes sending all course laps, course tracks and course points
** to the device.
**
** @param [r] port [const char *] serial port
** @param [w] crs [GPS_PCourse **] course array
** @param [w] clp [GPS_PCourse_Lap *] course lap array
** @param [w] trk [GPS_PTrack *] track array
** @param [w] cpt [GPS_PCourse_Point *] course point array
** @param [w] n_crs [int32] number of course entries
** @param [w] n_clp [int32] number of lap entries
** @param [w] n_trk [int32] number of track entries
** @param [w] n_cpt [int32] number of course point entries
**
** @return [int32] Success
************************************************************************/
int32  GPS_Command_Send_Course
                (const char *port,
                 GPS_PCourse *crs,
                 GPS_PCourse_Lap *clp,
                 GPS_PTrack *trk,
                 GPS_PCourse_Point *cpt,
                 int32 n_crs,
                 int32 n_clp,
                 int32 n_trk,
                 int32 n_cpt)
{
    gpsdevh *fd;
    GPS_OCourse_Limits limits;
    int32 ret;
    int32 ret_crs=0;
    int32 ret_clp=0;
    int32 ret_trk=0;
    int32 ret_cpt=0;

    if(gps_course_transfer == -1 || gps_course_limits_transfer == -1)
       return GPS_UNSUPPORTED;

    /* Check course limits to make sure we're not exceeding the device's
     * capacity.
     */
    switch(gps_course_limits_transfer)
    {
       case pA1009:
           ret = GPS_A1009_Get(port,&limits);
           break;
       default:
           GPS_Error("Send_Course: Unknown course limitsprotocol");
           return PROTOCOL_ERROR;
    }

    if (n_crs > limits.max_courses
        || n_clp > limits.max_course_laps
        || n_trk > limits.max_course_trk_pnt
        || n_cpt > limits.max_course_pnt)
    {
	GPS_Error("Course upload would exceed device capacity:");
	GPS_Error("# of courses: %d, max: %d", n_crs, limits.max_courses);
	GPS_Error("# of laps: %d, max: %d", n_clp, limits.max_course_laps);
	GPS_Error("# of track points: %d, max: %d", n_trk, limits.max_course_trk_pnt);
	GPS_Error("# of course points: %d, max: %d", n_cpt, limits.max_course_pnt);
	return GPS_UNSUPPORTED;
    }

    /* Initialize device communication:
     * In contrast to other transfer protocols, this has to be handled here;
     * shutting off communication in between the different parts
     * could lead to data corruption on the device because all the courses
     * and their associated lap and track data have to be sent in one
     * transaction.
     */
    if(!GPS_Device_On(port,&fd))
        return gps_errno;

    switch(gps_course_transfer)
    {
       case pA1006:
           ret_crs = GPS_A1006_Send(port,crs,n_crs,fd);
           break;
       default:
           GPS_Error("Send_Course: Unknown course protocol");
           return PROTOCOL_ERROR;
    }

    switch(gps_course_lap_transfer)
    {
       case pA1007:
           ret_clp = GPS_A1007_Send(port,clp,n_clp,fd);
           break;
       default:
           GPS_Error("Send_Course: Unknown course lap protocol");
           return PROTOCOL_ERROR;
    }

    switch(gps_course_trk_transfer)
    {
        case pA1012:
           GPS_Error("Send_Course: Not implemented track protocol %d\n",
                            gps_trk_transfer);
           break;
        case pA302:
	    ret_trk = GPS_A301_Send(port,trk,n_trk,302,fd);
           break;
        default:
           GPS_Error("Send_Course: Unknown course track protocol %d\n",
                            gps_trk_transfer);
           return PROTOCOL_ERROR;
    }

    switch(gps_course_point_transfer)
    {
       case pA1008:
           ret_cpt = GPS_A1008_Send(port,cpt,n_cpt,fd);
           break;
       default:
           GPS_Error("Send_Course: Unknown course point protocol");
           return PROTOCOL_ERROR;
    }

    if(!GPS_Device_Off(fd))
        return gps_errno;


    return ret_crs * ret_clp * ret_trk * ret_cpt;
}