Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3637

RTU_Initialize on owa5x

$
0
0

I am programming a REST interface in C++ and need the current GPS position of the owa5x device.However, I always get the following error: Error 23 in RTUControl_Initialise().Has anyone ever had this error or does anyone know if there is an error table?

Thank you and best regards

Heres the important Code:

#include "GpsPositionHandler.h"#include "GPS2_ModuleDefs.h"#include "pm_messages.h"#include "RTUControlDefs.h"#include "IOs_ModuleDefs.h"#include <cstring> // Für memset#include <iostream>#ifndef NO_ERROR#define NO_ERROR 0 // Dieser Wert kann je nach Kontext unterschiedlich sein#endif#ifdef _WIN32#ifndef B9600#define B9600 9600#endif#ifndef B115200#define B115200 115200#endif#ifndef CS8#define CS8 8#endif#ifndef IGNPAR#define IGNPAR 0#endif#include <windows.h> // Für Sleep unter Windows#else#include <unistd.h>  // Für sleep unter Unix-ähnlichen Systemen#include <termios.h> // Für Unix-ähnliche Systeme, z.B. Linux#endifbool GpsPositionHandler::initializeSystem(){    struct stat buf;    int ret;    // Warte bis zu 15 Sekunden, bis die Lock-Datei entfernt wird    for (int i = 0; i < 15; i++)    {        ret = stat("/var/lock/owaapi.lck", &buf);        if (ret == -1)        {            // Lock-Datei ist entfernt, weiter mit der Initialisierung            break;        }#ifdef _WIN32        Sleep(1000); // Warte eine Sekunde (Windows)#else        sleep(1); // Warte eine Sekunde (Linux)#endif    }    if (ret == 0)    {        std::cerr << "Problem with the system initialization. The lock file was not removed." << std::endl;        return false;    }    int ReturnCode;    // Initialisiere und starte RTUControl    if ((ReturnCode = RTUControl_Initialize(NULL)) != NO_ERROR)    {        std::cerr << "Error " << ReturnCode << " in RTUControl_Initialize()" << std::endl;        return false;    }    if ((ReturnCode = RTUControl_Start()) != NO_ERROR)    {        std::cerr << "Error " << ReturnCode << " in RTUControl_Start()" << std::endl;        RTUControl_Finalize();        return false;    }    // Initialisiere und starte IOs    if ((ReturnCode = IO_Initialize()) != NO_ERROR)    {        std::cerr << "Error " << ReturnCode << " in IO_Initialize()" << std::endl;        return false;    }    if ((ReturnCode = IO_Start()) != NO_ERROR)    {        std::cerr << "Error " << ReturnCode << " in IO_Start()" << std::endl;        IO_Finalize();        return false;    }    return true;}int GpsPositionHandler::initializeGPSModule(){    TGPS_MODULE_CONFIGURATION gpsConfig;    memset(&gpsConfig, 0, sizeof(gpsConfig));    // Predefined valid strings for type and protocol    char GpsValidType[][20] = {"NONE", "GPS_UBLOX"};    char GpsValidProtocol[][10] = {"NMEA", "BINARY"};    // Konfiguration der GPS-Einstellungen    strcpy(gpsConfig.DeviceReceiverName, GpsValidType[1]); // Verwenden Sie den korrekten Gerätetyp    gpsConfig.GPSPort = COM4;                              // Setzen des Ports auf COM4    gpsConfig.ParamBaud = B115200;                         // Setze auf 115200 Baudrate    gpsConfig.ParamParity = IGNPAR;                        // Keine Parität, IGNORE_PARITY    gpsConfig.ParamLength = CS8;                           // Datenbits    strcpy(gpsConfig.ProtocolName, GpsValidProtocol[0]); // Verwenden Sie NMEA-Protokoll    // Initialisiere das GPS-Modul    int initStatus = GPS_Initialize(&gpsConfig);    if (initStatus != NO_ERROR)    {        std::cerr << "Failed to initialize GPS module, error code: " << initStatus << std::endl;        // Detaillierte Fehleranalyse        if (initStatus == 2)        {            std::cerr << "Error code 2: This might indicate a configuration or resource issue." << std::endl;        }        return initStatus;    }    // Starte das GPS-Modul    int startStatus = GPS_Start();    if (startStatus != NO_ERROR)    {        std::cerr << "Failed to start GPS module, error code: " << startStatus << std::endl;        return startStatus;    }    return NO_ERROR;}std::string GpsPositionHandler::getCurrentGPSPosition(){    json gpsData = json::object(); // JSON-Objekt mit nlohmann/json erstellen    // System initialisieren    if (!initializeSystem())    {        gpsData["error"] = "Failed to initialize system components.";        return gpsData.dump();    }    // GPS-Modul initialisieren und starten    int initStatus = initializeGPSModule();    if (initStatus != NO_ERROR)    {        gpsData["error"] = "Failed to initialize GPS module, error code: " + std::to_string(initStatus);        return gpsData.dump();    }    // Überprüfen, ob das GPS-Modul aktiv ist    int gpsActive = 0;    int status = GPS_IsActive(&gpsActive);    if (status != NO_ERROR || !gpsActive)    {        gpsData["error"] = "GPS module is not active or failed to initialize.";        return gpsData.dump();    }    // Überprüfen des Antennenstatus    tANTENNA_NEW_STATUS antennaStatus;    int antennaStatusCode = GPS_GetStatusAntenna(&antennaStatus);    if (antennaStatusCode != NO_ERROR || antennaStatus.A_Status != OK)    {        gpsData["error"] = "GPS antenna issue: " + std::to_string(antennaStatus.A_Status);        return gpsData.dump();    }    // Positionsdaten abrufen    tPOSITION_DATA CurCoords;    int ReturnCode = GPS_GetAllPositionData(&CurCoords);    if (ReturnCode == NO_ERROR)    {        if (CurCoords.PosValid)        {            gpsData["latitude"] = CurCoords.LatDecimal;            gpsData["longitude"] = CurCoords.LonDecimal;            gpsData["altitude"] = CurCoords.Altitude;            gpsData["speed"] = CurCoords.Speed;            gpsData["course"] = CurCoords.Course;        }        else        {            std::cerr << "GPS data is invalid. Number of satellites: " << CurCoords.numSvs << std::endl;            gpsData["error"] = "GPS data is invalid, Number of satellites: " + std::to_string(CurCoords.numSvs);        }    }    else    {        std::cerr << "Failed to retrieve GPS data, error code: " << ReturnCode << std::endl;        gpsData["error"] = "Failed to retrieve GPS data";        gpsData["error"] = "Failed to retrieve GPS data"; // Fehlermeldung bei Fehler in GPS_GetAllPositionData    }    return gpsData.dump(); // JSON-Daten als String zurückgeben}

Viewing all articles
Browse latest Browse all 3637

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>