Jump to content

Recommended Posts

Geschrieben

@ufechner: Ihr hattet die API leider nicht richtig verstanden. Der Index mit dem auf die Satellitennummer zugegriffen wird läuft immer von 1-32.

 

Der Code müsste so aussehen:

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "ip_connection.h"
#include "bricklet_gps_v2.h"

//#define HOST "192.168.1.6"
#define HOST "localhost"
#define PORT 4223
#define UID "CHk" // Change XYZ to the UID of your GPS Bricklet 2.0

volatile sig_atomic_t terminate = 0;
GPSV2 gps;

void sig_handler(int signo)
{
    if (signo == SIGINT) {
        printf("received SIGINT\n");
        terminate = 1;
    }
}

void readSatelliteStatus()
{
    uint8_t satellite_system;
    uint8_t ret_satellite_numbers_length;
    uint8_t ret_satellite_numbers_data[12];
    int16_t ret_elevation;
    int16_t ret_azimuth;
    int16_t ret_snr;
    uint8_t ret_fix;
    uint16_t ret_pdop, ret_hdop, ret_vdop;
uint8_t satellite_index;
    int sum_satellite = 0;
    for (satellite_system = 0; satellite_system < 2; satellite_system++) {
        if (gps_v2_get_satellite_system_status_low_level(
                    &gps, satellite_system,
                    &ret_satellite_numbers_length,
                    ret_satellite_numbers_data,
                    &ret_fix, &ret_pdop, &ret_hdop, &ret_vdop)< 0) {
            fprintf(stderr, "Could not get satellite status_low_level, probably timeout\n");

        }
        if (satellite_system == 0){
            printf("GPS satellite (Satellite system number = %d)\n", satellite_system);
            printf("Number of GPS satellite in use = %hu\n", ret_satellite_numbers_length);
        } else if (satellite_system == 1) {
            printf("Glonass satellite (Satellite system number = %d)\n", satellite_system);
            printf("Number of Glonass satellite in use = %hu\n", ret_satellite_numbers_length);
        } else {
            fprintf(stderr, "Not proper satellite system\n");
        }
        for (int i=0; i<ret_satellite_numbers_length; i++) {
            switch (i) {
            case 0:
                printf("First ");
                break;
            case 1:
                printf("Second ");
                break;
            case 2:
                printf("Third ");
                break;
            default:
                printf("%dth", i);
                break;
            }
            printf("satellite number = %d\n", ret_satellite_numbers_data[i]);

		if (satellite_system == 0) {
			satellite_index = ret_satellite_numbers_data[i];
		} else if (satellite_system == 1) {
			satellite_index = ret_satellite_numbers_data[i] - 64;
		} else {
			fprintf(stderr, "Not proper satellite system\n");
		}
            if (gps_v2_get_satellite_status(
                        &gps, satellite_system,
                        satellite_index, &ret_elevation,
                        &ret_azimuth, &ret_snr) < 0) {
                fprintf(stderr, "Could not get satellite status, probably timeout\n");
            }
            printf("signal_noise = %d\n", ret_snr);
        }
        usleep(1e5);
    }
}

int main(void) {

    /* Register a signal handling function */
    if (signal(SIGINT, sig_handler) == SIG_ERR) {
        fprintf(stderr, "Can't catch SIGINT\n");
        abort();
    }

    // Create IP connection
    IPConnection ipcon;
    ipcon_create(&ipcon);

    // Create device object
    gps_v2_create(&gps, UID, &ipcon);

    // Connect to brickd
    if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
        fprintf(stderr, "Could not connect\n");
        return 1;
    }
    readSatelliteStatus();

    printf("Press key to exit\n");
    getchar();
    gps_v2_destroy(&gps);
    ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
    return 0;
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...