Exemplo n.º 1
0
static int      _s52_setupVESSEL(s52droid_state_t *state)
{
    // ARPA
    //_vessel_arpa = S52_newVESSEL(1, dummy, "ARPA label");
    //_vessel_arpa = S52_newVESSEL(1, "ARPA label");
    //S52_pushPosition(_vessel_arpa, _engine.state.cLat + 0.01, _engine.state.cLon - 0.02, 045.0);
    //S52_setVector(_vessel_arpa, 2, 060.0, 3.0);   // water

    // AIS active
    _vessel_ais = S52_newVESSEL(2, NULL);
    S52_setDimension(_vessel_ais, 100.0, 100.0, 15.0, 15.0);
    //S52_pushPosition(_vessel_ais, _engine.state.cLat - 0.02, _engine.state.cLon + 0.02, 045.0);
    //S52_pushPosition(_vessel_ais, state->cLat - 0.04, state->cLon + 0.04, 045.0);
    S52_pushPosition(_vessel_ais, state->cLat - 0.01, state->cLon + 0.01, 045.0);
    S52_setVector(_vessel_ais, 1, 060.0, 16.0);   // ground

    // (re) set label
    S52_setVESSELlabel(_vessel_ais, VESSELLABEL);
    int vesselSelect = 0;  // OFF
    int vestat       = 1;
    int vesselTurn   = VESSELTURN_UNDEFINED;
    S52_setVESSELstate(_vessel_ais, vesselSelect, vestat, vesselTurn);

    // AIS sleeping
    //_vessel_ais = S52_newVESSEL(2, 2, "MV Non Such - sleeping"););
    //S52_pushPosition(_vessel_ais, _engine.state.cLat - 0.02, _engine.state.cLon + 0.02, 045.0);

    // VTS (this will not draw anything!)
    //_vessel_vts = S52_newVESSEL(3, dummy);

#ifdef S52_USE_AFGLOW
    // afterglow
    _vessel_ais_afglow = S52_newMarObj("afgves", S52_LINES, MAX_AFGLOW_PT, NULL, NULL);
#endif

    return TRUE;
}
Exemplo n.º 2
0
static _ais_t       *_getAIS    (unsigned int mmsi)
{
    // return this
    _ais_t *ais = NULL;

    // check that gps_done() haven't flush this
    if (NULL == _ais_list) {
        g_print("s52ais:_getAIS() no AIS list\n");
        return NULL;
    }

    unsigned int i = 0;
    for (i=0; i<_ais_list->len; ++i) {
        ais = &g_array_index(_ais_list, _ais_t, i);
        if (mmsi == ais->mmsi) {
            return ais;
        }
    }

    {   // NEW AIS (not found hence new)
        _ais_t newais;
        __builtin_bzero(&newais, sizeof(_ais_t));
        newais.mmsi     = mmsi;
        newais.status   = -1;     // 0 indicate that status form report is needed
        //newais.name[AIS_SHIPNAME_MAXLEN + 1] = '\0';
        newais.name[0]  = '\0';
        g_get_current_time(&newais.lastUpdate);
        newais.course   = -1.0;
        newais.speed    =  0.0;

        // create an active symbol, put mmsi since status is not known yet
        g_sprintf(newais.name, "%i", mmsi);

#ifdef S52_USE_SOCK
        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi) {
            gchar *resp = _encodeNsend("S52_newOWNSHP", "\"%s\"", newais.name);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.vesselH);
            }
            g_print("s52ais:_getAIS(): new ownshpH:%lu\n", (long unsigned int) newais.vesselH);
        } else {
            gchar *resp = _encodeNsend("S52_newVESSEL", "%i,\"%s\"", 2, newais.name);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.vesselH);
            }
            g_print("s52ais:_getAIS(): new vesselH:%lu\n", (long unsigned int) newais.vesselH);
        }

#else   // S52_USE_SOCK

        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi) {
            newais.vesselH = S52_newOWNSHP(newais.name);
        } else {
            //int vesrce = 1;  // ARPA
            int vesrce = 2;  // AIS
            //int vesrce = 3;  // VTS
            newais.vesselH = S52_newVESSEL(vesrce, newais.name);
        }

#endif  // S52_USE_SOCK

        // new AIS failed
        if (NULL == newais.vesselH) {
            g_print("s52ais:_getAIS(): new vesselH fail\n");
            return NULL;
        }

#ifdef S52_USE_AFGLOW
#ifdef S52_USE_SOCK
        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi) {
            gchar *resp = _encodeNsend("S52_newMarObj", "\"%s\",%i,%i", "afgshp", S52_LINES, MAX_AFGLOW_PT);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.afglowH);
            }
            g_print("s52ais:_getAIS(): new afglowH:%lu\n", (long unsigned int) newais.afglowH);

        } else {
            gchar *resp = _encodeNsend("S52_newMarObj", "\"%s\",%i,%i", "afgves", S52_LINES, MAX_AFGLOW_PT);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.afglowH);
            }
            g_print("s52ais:_getAIS(): new afglowH:%lu\n", (long unsigned int) newais.afglowH);

        }

#else   // S52_USE_SOCK

        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi)
            newais.afglowH = S52_newMarObj("afgshp", S52_LINES, MAX_AFGLOW_PT, NULL, NULL);
        else
            newais.afglowH = S52_newMarObj("afgves", S52_LINES, MAX_AFGLOW_PT, NULL, NULL);

#endif  // S52_USE_SOCK

        if (NULL == newais.afglowH) {
            g_print("s52ais:_getAIS(): new afglowH fail\n");
            return NULL;
        }
#endif

        // save S52obj handle after registered in libS52
        g_array_append_val(_ais_list, newais);
        ais = &g_array_index(_ais_list, _ais_t, _ais_list->len - 1);


#ifdef S52_USE_DBUS
        _signal_newVESSEL(_dbus, newais.vesselH, newais.name);
#endif

    }

    return ais;
}