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