102 lines
3.3 KiB
C
102 lines
3.3 KiB
C
#include "sa.h"
|
|
#include "facilities.h"
|
|
|
|
#include <it2s-tender/time.h>
|
|
|
|
SAEM_CODE_R saem_check(void* fc, press_t* press, SAEM_t* saem) {
|
|
|
|
facilities_t* facilities = (facilities_t*) fc;
|
|
|
|
int rv = 0;
|
|
|
|
if (saem->header.messageID != ItsPduHeader__messageID_saem) {
|
|
return SAEM_INVALID_HEADER_MESSAGE_ID;
|
|
}
|
|
|
|
if (saem->header.protocolVersion != 1) {
|
|
return SAEM_INVALID_HEADER_VERSION;
|
|
}
|
|
|
|
|
|
if (saem->sam.body.serviceInfos) {
|
|
for (int i = 0; i < saem->sam.body.serviceInfos->list.count; ++i) {
|
|
ServiceInfo_t* si = saem->sam.body.serviceInfos->list.array[i];
|
|
|
|
uint16_t its_aid = 0;
|
|
switch (si->serviceID.present) {
|
|
case VarLengthNumber_PR_content:
|
|
its_aid = si->serviceID.choice.content;
|
|
break;
|
|
case VarLengthNumber_PR_extension:
|
|
// TODO
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (!its_aid) {
|
|
continue;
|
|
}
|
|
|
|
int index = -1;
|
|
for (int a = 0; a < press->announcements_len; ++a) {
|
|
/* Check existence through stationID and itsAid */
|
|
if (saem->header.stationID == press->announcements[a]->station_id &&
|
|
its_aid == press->announcements[a]->its_aid) {
|
|
index = a;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (index == -1) {
|
|
if (press->announcements_len + 1 < MAX_ANNOUNCEMENTS_LEN) {
|
|
press->announcements[press->announcements_len]->its_aid = its_aid;
|
|
press->announcements[press->announcements_len]->station_id = saem->header.stationID;
|
|
press->announcements[press->announcements_len]->timestamp = it2s_tender_get_clock(&facilities->epv);
|
|
index = press->announcements_len;
|
|
++press->announcements_len;
|
|
}
|
|
}
|
|
|
|
uint16_t ci_index = si->channelIndex;
|
|
|
|
// TODO chOptions
|
|
for (int o = 0; o < si->chOptions.extensions->list.count; ++o) {
|
|
Extension_34P0_t* sie = (Extension_34P0_t*) si->chOptions.extensions->list.array[o];
|
|
switch (sie->value.present) {
|
|
case Extension_34P0__value_PR_TwoDLocation:
|
|
press->announcements[index]->position.latitude = sie->value.choice.TwoDLocation.latitude;
|
|
break;
|
|
case Extension_34P0__value_PR_ThreeDLocation:
|
|
break;
|
|
case Extension_34P0__value_PR_RepeatRate:
|
|
break;
|
|
case Extension_34P0__value_PR_AdvertiserIdentifier:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// TODO channelInfos
|
|
if (saem->sam.body.channelInfos) {
|
|
if (saem->sam.body.channelInfos->list.count >= ci_index + 1) {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
void press_init(press_t* press) {
|
|
|
|
press->announcements_len = 0;
|
|
for (int i = 0; i < MAX_ANNOUNCEMENTS_LEN; ++i) {
|
|
press->announcements[i] = calloc(1, sizeof(announcement_t));
|
|
|
|
}
|
|
}
|