Change PCM encoding functions

This commit is contained in:
emanuel 2022-02-22 14:58:39 +00:00
parent 2e3eb8784e
commit b687ebc866
1 changed files with 12 additions and 9 deletions

View File

@ -118,12 +118,13 @@ static int pcm_check_handle_request(facilities_t* facilities, PCM_t* pcm) {
mvc->negotiation->choice.reply.acceptedTrajectoriesIds.list.array[0] = malloc(sizeof(long)); mvc->negotiation->choice.reply.acceptedTrajectoriesIds.list.array[0] = malloc(sizeof(long));
*mvc->negotiation->choice.reply.acceptedTrajectoriesIds.list.array[0] = pt->id; *mvc->negotiation->choice.reply.acceptedTrajectoriesIds.list.array[0] = pt->id;
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_PCM, pcm_rep, buf, buf_len); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_PCM, NULL, pcm_rep, buf, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [pc] PCM.reply encode failure (%s)", enc.failed_type->name); syslog_err("[facilities] [pc] PCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
ssize_t pcm_rep_len = (enc.encoded + 7) / 8;
tr = calloc(1, sizeof(TransportRequest_t)); tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_packet; tr->present = TransportRequest_PR_packet;
@ -144,9 +145,9 @@ static int pcm_check_handle_request(facilities_t* facilities, PCM_t* pcm) {
bpr->gn.trafficClass = 2; bpr->gn.trafficClass = 2;
bpr->data.buf = malloc(enc.encoded); bpr->data.buf = malloc(pcm_rep_len);
memcpy(bpr->data.buf, buf, enc.encoded); memcpy(bpr->data.buf, buf, pcm_rep_len);
bpr->data.size = enc.encoded; bpr->data.size = pcm_rep_len;
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1);
@ -181,7 +182,7 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm)
PCM_t* pcm_req = NULL; PCM_t* pcm_req = NULL;
TransportRequest_t* tr = NULL; TransportRequest_t* tr = NULL;
const ssize_t buf_len = 512; const ssize_t buf_len = 1024;
uint8_t buf[buf_len]; uint8_t buf[buf_len];
it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */
@ -262,12 +263,13 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm)
pt->priority = 1; pt->priority = 1;
pt->id = 0; pt->id = 0;
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_PCM, pcm_req, buf, buf_len); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_PCM, NULL, pcm_req, buf, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [pc] PCM.request encode failure (%s)", enc.failed_type->name); syslog_err("[facilities] [pc] PCM.request encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
ssize_t pcm_req_len = (enc.encoded + 7) / 8;
tr = calloc(1, sizeof(TransportRequest_t)); tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_packet; tr->present = TransportRequest_PR_packet;
@ -288,9 +290,9 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm)
bpr->gn.trafficClass = 2; bpr->gn.trafficClass = 2;
bpr->data.buf = malloc(enc.encoded); bpr->data.buf = malloc(pcm_req_len);
memcpy(bpr->data.buf, buf, enc.encoded); memcpy(bpr->data.buf, buf, pcm_req_len);
bpr->data.size = enc.encoded; bpr->data.size = pcm_req_len;
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1);
@ -354,6 +356,7 @@ int pcm_check(void* fc, PCM_t* pcm) {
if (mvc->negotiation) { if (mvc->negotiation) {
switch (mvc->negotiation->present) { switch (mvc->negotiation->present) {
case CoordinationNegotiation_PR_request: case CoordinationNegotiation_PR_request:
syslog_err("received PCM.request");
pcm_check_handle_request(facilities, pcm); pcm_check_handle_request(facilities, pcm);
break; break;
case CoordinationNegotiation_PR_reply: case CoordinationNegotiation_PR_reply: