static int _setAISDel (_ais_t *ais) { if (NULL == ais) { printf("AIS is NULL!\n"); g_assert(0); } #ifdef S52_USE_DBUS _signal_delMarObj(_dbus, ais->vesselH, ais->name); #endif #ifdef S52_USE_SOCK _encodeNsend("S52_delMarObj", "%lu", ais->vesselH); #else ais->vesselH = S52_delMarObj(ais->vesselH); if (NULL != ais->vesselH) { g_print("s52ais:_setAISDel(): WARNING: unkown vesselH [%s]\n", ais->name); ais->vesselH = NULL; } #endif #ifdef S52_USE_AFGLOW #ifdef S52_USE_SOCK _encodeNsend("S52_delMarObj", "%lu", ais->afglowH); #else ais->afglowH = S52_delMarObj(ais->afglowH); if (NULL != ais->afglowH) { g_print("s52ais:_setAISDel(): WARNING: unkown afglowH [%s]\n", ais->name); ais->afglowH = NULL; } #endif #endif return TRUE; }
static int _setAISPos (unsigned int mmsi, double lat, double lon, double heading) { _ais_t *ais = _getAIS(mmsi); if (NULL == ais) return FALSE; #ifdef S52_USE_SOCK _encodeNsend("S52_pushPosition", "%lu,%lf,%lf,%lf", (long unsigned int *)ais->vesselH, lat, lon, heading); #else S52_pushPosition(ais->vesselH, lat, lon, heading); #endif #ifdef S52_USE_AFGLOW #ifdef S52_USE_SOCK _encodeNsend("S52_pushPosition", "%lu,%lf,%lf,%lf", (long unsigned int *)ais->afglowH, lat, lon, heading); #else S52_pushPosition(ais->afglowH, lat, lon, 0.0); #endif #endif #ifdef S52_USE_DBUS _signal_setPosition (_dbus, ais->vesselH, lat, lon, heading); _signal_setVESSELlabel(_dbus, ais->vesselH, ais->name); #endif g_get_current_time(&ais->lastUpdate); return TRUE; }
static int _setAISSta (unsigned int mmsi, int status, int turn) { /* from doc in 'gpsd' "0 - Under way using engine", "1 - At anchor", "2 - Not under command", "3 - Restricted manoeuverability", "4 - Constrained by her draught", "5 - Moored", "6 - Aground", "7 - Engaged in Fishing", "8 - Under way sailing", "9 - Reserved for future amendment of Navigational Status for HSC", "10 - Reserved for future amendment of Navigational Status for WIG", "11 - Reserved for future use", "12 - Reserved for future use", "13 - Reserved for future use", "14 - Reserved for future use", "15 - Not defined (default)" */ _ais_t *ais = _getAIS(mmsi); if (NULL == ais) return FALSE; if ((status!=ais->status) || (turn!=ais->turn)) { if (1==status || 5==status || 6==status) { int vestat = 2; // AIS sleeping #ifdef S52_USE_SOCK _encodeNsend("S52_setVESSELstate", "%lu,%i,%i,%i", ais->vesselH, 0, vestat, turn); #else S52_setVESSELstate(ais->vesselH, 0, vestat, turn); // AIS sleeping #endif } else { // AIS active int vestat = 1; // normal //int vestat = 3; // red, close quarters #ifdef S52_USE_SOCK _encodeNsend("S52_setVESSELstate", "%lu,%i,%i,%i", ais->vesselH, 0, vestat, turn); #else S52_setVESSELstate(ais->vesselH, 0, vestat, turn); // AIS active #endif } ais->status = status; ais->turn = turn; } #ifdef S52_USE_DBUS // need to send the status every time because AIS-monitor.js // can be restarted wild libS52 is running hence status is not updated (ie no change) _signal_setVESSELstate(_dbus, ais->vesselH, 0, status, turn); #endif return TRUE; }
static int _setAISVec (unsigned int mmsi, double course, double speed) { _ais_t *ais = _getAIS(mmsi); if (NULL == ais) return FALSE; int vecstb = 1; // overground // ground vector (since AIS transmit the GPS) ais->course = course; ais->speed = speed; #ifdef S52_USE_SOCK _encodeNsend("S52_setVector", "%lu,%i,%lf,%lf", ais->vesselH, vecstb, course, speed); #else // FIXME: test ship's head up setView() S52_setVector(ais->vesselH, vecstb, course, speed); #endif #ifdef S52_USE_DBUS _signal_setVector(_dbus, ais->vesselH, 1, course, speed); #endif g_get_current_time(&ais->lastUpdate); return TRUE; }
static int _setAISLab (unsigned int mmsi, const char *name) // update AIS label { // debug //if (316006302 == mmsi) // g_print("s52ais:_setAISLab(): mmsi:%i name:[%s]\n", mmsi, name); _ais_t *ais = _getAIS(mmsi); if (NULL == ais) return FALSE; if (NULL != name) { g_snprintf(ais->name, AIS_SHIPNAME_MAXLEN+1, "%s", name); #ifdef S52_USE_SOCK _encodeNsend("S52_setVESSELlabel", "%lu,\"%s\"", ais->vesselH, name); #else S52_setVESSELlabel(ais->vesselH, name); #endif #ifdef S52_USE_DBUS _signal_setVESSELlabel(_dbus, ais->vesselH, ais->name); #endif } g_get_current_time(&ais->lastUpdate); return TRUE; }
static int _updateTimeTag(void) // then update time tag of AIS { if (NULL == _ais_list) return FALSE; /* { // check global time - update time tag of all AIS each sec // FIXME: should be 0.5 sec GTimeVal now; g_get_current_time(&now); if ((now.tv_sec-_timeTick.tv_sec) < 1) return FALSE; g_get_current_time(&_timeTick); } */ // keep removing old AIS while (TRUE == _removeOldAIS()) _dumpAIS(); GTimeVal now; g_get_current_time(&now); for (guint i=0; i<_ais_list->len; ++i) { gchar str[127+1] = {'\0'}; _ais_t *ais = &g_array_index(_ais_list, _ais_t, i); if (-1.0 != ais->course) { #ifdef S52_USE_SOCK g_snprintf(str, 127, "%s %lis%s%03.f deg / %3.1f kt", ais->name, (now.tv_sec - ais->lastUpdate.tv_sec), NL, ais->course, ais->speed); #else g_snprintf(str, 127, "%s %lis%c%03.f deg / %3.1f kt", ais->name, (now.tv_sec - ais->lastUpdate.tv_sec), (int)NL, ais->course, ais->speed); #endif } else { g_snprintf(str, 127, "%s %lis", ais->name, now.tv_sec - ais->lastUpdate.tv_sec); } #ifdef S52_USE_SOCK _encodeNsend("S52_setVESSELlabel", "%lu,\"%s\"", ais->vesselH, str); #else if (FALSE == S52_setVESSELlabel(ais->vesselH, str)) { g_print("s52ais:_updateTimeTag(): FAIL setVESSELlabel = %s\n", str); _setAISDel(ais); g_array_remove_index_fast(_ais_list, i); //g_assert(0); } #endif } return TRUE; }
static int _setAISDim (unsigned int mmsi, double a, double b, double c, double d) { _ais_t *ais = _getAIS(mmsi); if (NULL == ais) return FALSE; #ifdef S52_USE_SOCK _encodeNsend("S52_setDimension", "%lu,%lf,%lf,%lf,%lf", ais->vesselH, a, b, c, d); #else S52_setDimension(ais->vesselH, a, b, c, d); #endif g_get_current_time(&ais->lastUpdate); return TRUE; }
static int _updateTimeTag(void) // then update time tag of AIS { if (NULL == _ais_list) return FALSE; // keep removing old AIS while (TRUE == _removeOldAIS()) _dumpAIS(); GTimeVal now; g_get_current_time(&now); for (guint i=0; i<_ais_list->len; ++i) { gchar str[128] = {'\0'}; _ais_t *ais = &g_array_index(_ais_list, _ais_t, i); if (-1.0 != ais->course) { #ifdef S52_USE_SOCK g_snprintf(str, 128, "%s %lis%s%03.f deg / %3.1f kt", ais->name, (now.tv_sec - ais->lastUpdate.tv_sec), NL, ais->course, ais->speed); #else g_snprintf(str, 128, "%s %lis%c%03.f deg / %3.1f kt", ais->name, (now.tv_sec - ais->lastUpdate.tv_sec), (int)NL, ais->course, ais->speed); #endif } else { g_snprintf(str, 128, "%s %lis", ais->name, now.tv_sec - ais->lastUpdate.tv_sec); } #ifdef S52_USE_SOCK _encodeNsend("S52_setVESSELlabel", "%lu,\"%s\"", ais->vesselH, str); #else //Note: can't use _setAISLab() as it update timetag - long str if (FALSE == S52_setVESSELlabel(ais->vesselH, str)) { ais->lost = TRUE; } #endif } return TRUE; }
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; }