Jump to content

gps_v2_get_satellite_status fehlerhaft


Recommended Posts

@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;
}

Link to comment
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...