Attr request support pt II

This commit is contained in:
emanuel 2020-11-05 19:03:11 +00:00
parent 7ed9820f69
commit 2bb7010dca
1 changed files with 45 additions and 24 deletions

View File

@ -259,7 +259,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
}
// Respond to [itss]
fdres->code = ResultCode_accepted;
fdres->code = FacilitiesResultCode_accepted;
fdres_oer = malloc(16);
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 16);
if (enc.encoded == -1) {
@ -326,28 +326,28 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
case FacilitiesDataRequest_PR_activeEvents:
pthread_mutex_lock(&facilities->den->lock);
fdres->code = ResultCode_accepted;
fdres->events = calloc(1, sizeof(Events_t));
fdres->code = FacilitiesResultCode_accepted;
fdres->result = calloc(1, sizeof(FacilitiesResult_t));
fdres->result->present = FacilitiesResult_PR_events;
uint16_t nae = facilities->den->n_active_events;
switch (fdreq->choice.activeEvents) {
case EventType_active:
fdres->events = calloc(1, sizeof(Events_t));
fdres->events->list.count = nae;
fdres->events->list.size = nae * sizeof(DENM_t *);
fdres->events->list.array = malloc(nae * sizeof(DENM_t *));
fdres->result->choice.events.list.count = nae;
fdres->result->choice.events.list.size = nae * sizeof(DENM_t *);
fdres->result->choice.events.list.array = malloc(nae * sizeof(DENM_t *));
for (int i = 0, j = 0; j < nae; ++i) {
if (facilities->den->events[i]->state == EVENT_ACTIVE) {
fdres->events->list.array[j] = calloc(1, sizeof(ItssMessage_t));
fdres->events->list.array[j]->itssMessageType = ItssMessageType_denm;
fdres->events->list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities->den->events[i]->denm, fdres->events->list.array[j]->data.buf, 2048);
fdres->result->choice.events.list.array[j] = calloc(1, sizeof(ItssMessage_t));
fdres->result->choice.events.list.array[j]->itssMessageType = ItssMessageType_denm;
fdres->result->choice.events.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities->den->events[i]->denm, fdres->result->choice.events.list.array[j]->data.buf, 2048);
if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding DENM for FDResult (%s)", enc.failed_type->name);
continue;
}
fdres->events->list.array[j]->data.size = (enc.encoded + 7) / 8;
fdres->result->choice.events.list.array[j]->data.size = (enc.encoded + 7) / 8;
++j;
}
}
@ -358,8 +358,9 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
rv = 1;
goto cleanup;
}
fdres_oer = malloc(16384);
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 16384);
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 16384);
if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding FDResult (%s)", enc.failed_type->name);
pthread_mutex_unlock(&facilities->den->lock);
@ -371,15 +372,37 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
pthread_mutex_unlock(&facilities->den->lock);
break;
case FacilitiesDataRequest_PR_attribute:
switch (fdreq->choice.attribute) {
case FacilitiesAttribute_stationId:
break;
default:
syslog_err("[facilities] unrecognized FDR attribute request received (%d)", fdreq->present);
rv = 1;
goto cleanup;
case FacilitiesDataRequest_PR_attributeTypes:
fdres->code = FacilitiesResultCode_accepted;
int nra = fdreq->choice.attributeTypes.list.count;
fdres->result = calloc(1, sizeof(FacilitiesResult_t));
fdres->result->present = FacilitiesResult_PR_attributes;
fdres->result->choice.attributes.list.count = nra;
fdres->result->choice.attributes.list.size = sizeof(void*) * nra;
fdres->result->choice.attributes.list.array = malloc(sizeof(void*) * nra);
for (int j = 0; j < nra; ++j) {
switch (*fdreq->choice.attributeTypes.list.array[j]) {
case FacilitiesAttributeType_stationId:
fdres->result->choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t) );
fdres->result->choice.attributes.list.array[j]->data.size = 8;
fdres->result->choice.attributes.list.array[j]->data.buf = malloc(8);
*((uint64_t*) fdres->result->choice.attributes.list.array[j]->data.buf) = facilities->station_id;
break;
default:
syslog_debug("[facilities] unrecognized FDR attribute type request");
goto cleanup;
}
}
fdres_oer = malloc(256);
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 256);
if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding FDResult (%s)", enc.failed_type->name);
rv = 1;
goto cleanup;
}
zmq_send(responder, fdres_oer, enc.encoded, 0);
break;
default:
syslog_err("[facilities] unrecognized FDR type received (%d)", fdreq->present);
@ -389,7 +412,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
cleanup:
if (rv) {
fdres->code = ResultCode_rejected;
fdres->code = FacilitiesResultCode_rejected;
uint8_t fdres_oer[32];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 32);
zmq_send(responder, fdres_oer, enc.encoded, 0);
@ -489,13 +512,11 @@ int main() {
// Infrastructure
pthread_create(&facilities.infrastructure_service, NULL, infrastructure_service, (void*) &facilities);
uint8_t buffer[PACKET_MAX_LEN];
uint8_t code;
syslog_info("[facilities] listening");
while (!facilities.exit) {
memset(buffer, 0x00, PACKET_MAX_LEN);
zmq_recv(responder, buffer, PACKET_MAX_LEN, 0);
switch (buffer[0]) {