Guillermo Stedile / NAVDATA

Dependents:   SNOCC_V1 SNOCC_V2

NAVDATA.cpp

Committer:
gstedile
Date:
2017-04-04
Revision:
5:ae5dfda6b0ab
Parent:
4:400b92fb528c
Child:
6:fc2eb58bac36

File content as of revision 5:ae5dfda6b0ab:

/* NAVIGATION DATA Library
 * Copyright (c) 2008-2010, sford
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
 
#include "NAVDATA.h"


/*############################################################################
##############################################################################*/

/* CONSTRUCTOR: Si no se pasan argumentos se toman los seteados en la declaracion; Latitud/Longitud expresadas en Millas Náuticas y Cte. del sensor en pulsos por Litro*/

    NAVDATA::NAVDATA(float Klongitud=49.38797982997941, float Klatitud=59.99999981628485, float Ksensor=2500, int ZoneHour=-3) : Klong(Klongitud), Klat(Klatitud), Ksen(Ksensor), ZH(ZoneHour) {  
    this->paddata();           
    }
    NAVDATA::NAVDATA(){  
    Klong= 49.38797982997941;
    Klat=59.99999981628485;
    Ksen=2500;
    ZH=-3;
    
    this->paddata();           
    }
    
    
    
int NAVDATA::rotate_data(float x, float y, float t, float c){    // Longitud, Latitud, Timestamp, Consumption;
    if ( t > LAST_NAV_DATA[time_f] ) {                           // Tiempo válido?
    this->LAST_NAV_DATA[longitude_i]=this->LAST_NAV_DATA[longitude_f];
    this->LAST_NAV_DATA[longitude_f]=x;           
    this->LAST_NAV_DATA[latitude_i]=this->LAST_NAV_DATA[latitude_f];
    this->LAST_NAV_DATA[latitude_f]=y;
    this->LAST_NAV_DATA[time_i]=this->LAST_NAV_DATA[time_f];                // EN HORAS
    this->LAST_NAV_DATA[time_f]=time_NMEA2hours(t) + ZH;                    // EN HORAS
    this->LAST_NAV_DATA[distance_p]= sqrt(pow(Klong*(this->LAST_NAV_DATA[longitude_f]-this->LAST_NAV_DATA[longitude_i]),2) + pow(Klat*(this->LAST_NAV_DATA[latitude_f]-this->LAST_NAV_DATA[latitude_i]),2)) ; // Distancia recorrida durante este período.
    this->LAST_NAV_DATA[speed_p]=this->LAST_NAV_DATA[distance_p]/(this->LAST_NAV_DATA[time_f]-this->LAST_NAV_DATA[time_i]);              
    this->LAST_NAV_DATA[consumption_i]=this->LAST_NAV_DATA[consumption_f];
    this->LAST_NAV_DATA[consumption_f]=c/Ksen;
    this->LAST_NAV_DATA[consumption_p]=this->LAST_NAV_DATA[consumption_f]-this->LAST_NAV_DATA[consumption_i];         // Consumo en litros del período.
    
    if (this->LAST_NAV_DATA[distance_p] != 0) this->LAST_NAV_DATA[cons_mile_p]=this->LAST_NAV_DATA[consumption_p]/this->LAST_NAV_DATA[distance_p];  //   Consumo en litros por milla nautica.
    else this->LAST_NAV_DATA[cons_mile_p]= -1;                                                                     // Variable no mensurable (-1)
    
    this->LAST_NAV_DATA[cons_hour_p]=this->LAST_NAV_DATA[consumption_p]/(this->LAST_NAV_DATA[time_f]-this->LAST_NAV_DATA[time_i]);                  // Consumo en litros por hora.
    return 1;
    }
    else     
    return 0;                                                     // Período no válido. Tiempo <=0!
}      

float NAVDATA::time_NMEA2hours(float timetickNMEA){
    float seconds, minutes, hours;
    hours= int(timetickNMEA/10000);                            //Formato NMEA: hhmmss,sss; => int(hh,mmssss)=hh 
    seconds= (timetickNMEA/100 - int(timetickNMEA/100))*100;  // => (hhmmss,sss/100 - int(hhmmss,sss/100))*100 = ss,sss
    minutes= int(timetickNMEA/100 - hours*100);             // => int((hh,mmsssss - hh)*100)= mm
    return (hours + minutes/60 + seconds/3600);                 // => expresado en horas, formato decimal
}    

void NAVDATA::paddata(){
    this->LAST_NAV_DATA[longitude_f]=-58.5797;    // Longitud y Latitud iniciales y finales correspondiente a Tigre.
    this->LAST_NAV_DATA[longitude_i]=-58.5797;
    this->LAST_NAV_DATA[latitude_f]=-34.4251;
    this->LAST_NAV_DATA[latitude_i]=-34.4251;
    this->LAST_NAV_DATA[time_f]=-1;                // El dato (timestamp al final del período en cuestion, en horas) se obtendrá luego proveniente del GPS.
    this->LAST_NAV_DATA[time_i]=0;                // Timestamp al inicio del período en horas.
    this->LAST_NAV_DATA[distance_p]=0;            // Distancia recorrida durante este período en millas nauticas.
    this->LAST_NAV_DATA[speed_p]=0;               // Velocidad media del período en nudos.
    this->LAST_NAV_DATA[consumption_i]=0;         // Consumo en litros al comienzo del período.
    this->LAST_NAV_DATA[consumption_f]=0;         // Consumo en litros al final del período.
    this->LAST_NAV_DATA[consumption_p]=0;         // Consumo en litros del período.
    this->LAST_NAV_DATA[cons_mile_p]=0;           // Consumo en litros por milla nautica.
    this->LAST_NAV_DATA[cons_hour_p]=0;           // Consumo en litros por hora.
}    


///  AGREGAR ACA     int NAVDATA::rotate_data(float x, float y, float t, float c) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<<<<