RTU_Initialize on owa5x

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
#endif

bool 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
}

New contributor

Fabian Unterberger is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật