mt333-gps-glonass-galileo

gabbapeople/on-board-computer/mt333-gps-glonass-galileo

Reads date, time, lattitude coordinates, longitude coordinates, altitude value from a GPS Receiver based on MT333 Module.
mt333-gps-glonass-galileo
@/mt333-gps-glonass-galileo
Reads date, time, lattitude coordinates, longitude coordinates, altitude value from a GPS Receiver based on MT333 Module.
UARTnumber
Hardware serial port number.
BAUDnumber
The data rate in bits per second (baud) for serial data transmission.
UPDpulse
Triggers a new reading, i.e. date, time, latitude, longtitude, altitude values update
RSTpulse
Triggers UART initialization.
mt333-gps-glonass-galileo
UART
BAUD
UPD
RST
DATE
TIME
LTTD
LNGT
ALTT
ERR
ERRpulse
Fires if reading failed
ALTTstring
Altitude value in meters.
LNGTstring
Longitude coordinates.
LTTDstring
Tatitude coordinates.
TIMEstring
Сurrent time.
DATEstring
Сurrent date.
To use the node in your project you should have the gabbapeople/on-board-computer library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

{{#global}}
#include <TroykaGPS.h>
{{/global}}

struct State {
    GPS* gps;
    char timeGPS[16];
    char dateGPS[16];
    char altitudeGPS[16];
    char latitudeBase60GPS[16];
    char longitudeBase60GPS[16];
    CStringView viewTIME, viewDATE, viewLTTD, viewLNGT, viewALTT;
    State() 
        : viewTIME(timeGPS)
        , viewDATE(dateGPS)
        , viewLTTD(latitudeBase60GPS)
        , viewALTT(altitudeGPS)               
        , viewLNGT(longitudeBase60GPS){ }
};

{{ GENERATED_CODE }}

HardwareSerial* getSerial(int8_t no) {
#if defined(HAVE_HWSERIAL0)
    if (no == 0)
        return &Serial;
#endif
#if defined(HAVE_HWSERIAL1)
    if (no == 1)
        return &Serial1;
#endif
#if defined(HAVE_HWSERIAL2)
    if (no == 2)
        return &Serial2;
#endif
#if defined(HAVE_HWSERIAL3)
    if (no == 3)
        return &Serial3;
#endif

    return nullptr;
}

template<typename TSerial>
void begin(Context ctx, TSerial* serial, uint32_t baud) {
    if (!serial)
        //emitValue<output_ERR>(ctx, 1);
        return;
    serial->begin(baud);
}

void getParam(Context ctx){
    State* state = getState(ctx);
    float floatAltitudeGPS;
    auto dataError = XStringCString("DATA ERROR");
    auto satError = XStringCString("NO SAT");
    if (state->gps->available()) {
        state->gps->readParsing();
        switch(state->gps->getState()) {
            case GPS_OK:
                state->gps->getTime(state->timeGPS, 16);
                state->gps->getDate(state->dateGPS, 16);
                state->gps->getLatitudeBase60(state->latitudeBase60GPS, 16);
                state->gps->getLongitudeBase60(state->longitudeBase60GPS, 16);
                floatAltitudeGPS  = state->gps->getAltitude();
                dtostrf(floatAltitudeGPS, 0, 2, state->altitudeGPS);
                emitValue<output_DATE>(ctx,XString(&state->viewDATE));
                emitValue<output_TIME>(ctx,XString(&state->viewTIME));
                emitValue<output_LTTD>(ctx,XString(&state->viewLTTD));
                emitValue<output_LNGT>(ctx,XString(&state->viewLNGT));
                emitValue<output_ALTT>(ctx,XString(&state->viewALTT));
                break;
            case GPS_ERROR_DATA:
                emitValue<output_DATE>(ctx,dataError);
                emitValue<output_TIME>(ctx,dataError);
                emitValue<output_LTTD>(ctx,dataError);
                emitValue<output_LNGT>(ctx,dataError);
                emitValue<output_ALTT>(ctx,dataError);
                break;
            case GPS_ERROR_SAT:
                emitValue<output_DATE>(ctx,satError);
                emitValue<output_TIME>(ctx,satError);
                emitValue<output_LTTD>(ctx,satError);
                emitValue<output_LNGT>(ctx,satError);
                emitValue<output_ALTT>(ctx,satError);
                break;
        }

    } else {
        emitValue<output_ERR>(ctx, 1);
    }
}


void evaluate(Context ctx) {
    State* state = getState(ctx);
    if(isInputDirty<input_RST>(ctx)){
        auto uartNo = getValue<input_UART>(ctx);
        auto baud = getValue<input_BAUD>(ctx);
        Stream *serialPort;	
        serialPort = getSerial(uartNo);
        begin(ctx,getSerial(uartNo), baud);
        auto gps = state->gps;
        state->gps = gps = new GPS(*serialPort);
    }
    if(isInputDirty<input_UPD>(ctx)){
        getParam(ctx);
    }
}