added evrsrm reservation response

This commit is contained in:
gilteixeira 2023-04-22 15:35:00 +01:00
parent 40d8bf7b05
commit d2bdb38b5d
2 changed files with 45 additions and 9 deletions

View File

@ -8,6 +8,7 @@
"nativeenumerated.h": "c", "nativeenumerated.h": "c",
"asn_application.h": "c", "asn_application.h": "c",
"timestamputc.h": "c", "timestamputc.h": "c",
"availabilitystatus.h": "c" "availabilitystatus.h": "c",
"chargingspotlabel.h": "c"
} }
} }

View File

@ -46,9 +46,8 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) {
pthread_mutex_unlock(&facilities.id.lock); pthread_mutex_unlock(&facilities.id.lock);
uint64_t now = itss_time_get(); uint64_t now = itss_time_get();
evcsnm->evcsn.poiHeader.poiType = 1; // set to "EV charging station POI ID = 1"
asn_ulong2INTEGER(&evcsnm->evcsn.poiHeader.timeStamp, now); asn_ulong2INTEGER(&evcsnm->evcsn.poiHeader.timeStamp, now);
evcsnm->evcsn.poiHeader.poiType = 1; // set to "EV charging station POI ID = 1"
evcsnm->evcsn.poiHeader.relayCapable = 1; evcsnm->evcsn.poiHeader.relayCapable = 1;
evcsnm->evcsn.evcsnData.totalNumberOfStations = 1; evcsnm->evcsn.evcsnData.totalNumberOfStations = 1;
@ -116,6 +115,7 @@ cleanup:
} }
static int pre_reservation_id = 1; static int pre_reservation_id = 1;
static int reservation_id = 1;
int evrsrm_recv(EV_RSR_t *evrsr_request) { int evrsrm_recv(EV_RSR_t *evrsr_request) {
int rv = 0; int rv = 0;
@ -163,8 +163,8 @@ int evrsrm_recv(EV_RSR_t *evrsr_request) {
int evrsr_response; int evrsr_response;
if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_preReservationRequestMessage) if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_preReservationRequestMessage)
evrsr_response = evrsrm_pre_reservation_response(bpr->data.buf, (uint32_t *)&bpr->data.size); evrsr_response = evrsrm_pre_reservation_response(bpr->data.buf, (uint32_t *)&bpr->data.size);
// else if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_reservationRequestMessage) else if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_reservationRequestMessage)
// evrsr_response = evrsrm_reservation_response(evrsr_request); evrsr_response = evrsrm_reservation_response(evrsr_request, bpr->data.buf, (uint32_t *)&bpr->data.size);
if (evrsr_response != 0) { if (evrsr_response != 0) {
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -202,17 +202,53 @@ cleanup:
return rv; return rv;
} }
static int evrsrm_reservation_response(EV_RSR_t* evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len) {
int rv = 0;
EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t));
evrsr_response->header.protocolVersion = 1;
evrsr_response->header.messageID = 7;
pthread_mutex_lock(&facilities.id.lock);
evrsr_response->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_reservationResponseMessage;
ReservationResponseMessage_t *response = &evrsr_response->messageBody.choice.reservationResponseMessage;
// Assumes the pre reservation was successful
response->reservationResponseCode = ReservationResponseCode_ok;
response->reservation_ID = reservation_id;
response->reservation_Password->buf = calloc(4, sizeof(uint8_t));
response->reservation_Password->size = 4;
response->reservation_Password->buf[0] = 'i';
response->reservation_Password->buf[1] = 't';
response->reservation_Password->buf[2] = '2';
response->reservation_Password->buf[3] = 's';
// estimated arrival time + tolerance time
response->expirationTime = evrsrm_request->messageBody.choice.reservationRequestMessage.arrivalTime;
response->expirationTime += 15 * 60 * 1000; // 15 minutes
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512);
if (enc.encoded == -1) {
log_error("[ev] failed encoding evrsrm (%s)", enc.failed_type->name);
rv = 1;
goto cleanup;
}
*evrsrm_len = (enc.encoded + 7) / 8;
cleanup:
ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response);
return rv;
}
static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm_len) { static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm_len) {
int rv = 0; int rv = 0;
EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t)); EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t));
evrsr_response->header.protocolVersion = 1; evrsr_response->header.protocolVersion = 1;
evrsr_response->header.messageID = 1; evrsr_response->header.messageID = 7;
pthread_mutex_lock(&facilities.id.lock); pthread_mutex_lock(&facilities.id.lock);
evrsr_response->header.stationID = facilities.id.station_id; evrsr_response->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock); pthread_mutex_unlock(&facilities.id.lock);
evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_preReservationResponseMessage; evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_preReservationResponseMessage;
PreReservationResponseMessage_t* response = &evrsr_response->messageBody.choice.preReservationResponseMessage; PreReservationResponseMessage_t *response = &evrsr_response->messageBody.choice.preReservationResponseMessage;
response->preReservation_ID.buf = calloc(8, sizeof(uint8_t)); response->preReservation_ID.buf = calloc(8, sizeof(uint8_t));
response->preReservation_ID.size = 8; response->preReservation_ID.size = 8;
response->preReservation_ID.buf[0] = '0' + (pre_reservation_id >> 56) & 0xff; response->preReservation_ID.buf[0] = '0' + (pre_reservation_id >> 56) & 0xff;
@ -224,7 +260,6 @@ static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm
response->preReservation_ID.buf[6] = '0' + (pre_reservation_id >> 8) & 0xff; response->preReservation_ID.buf[6] = '0' + (pre_reservation_id >> 8) & 0xff;
response->preReservation_ID.buf[7] = '0' + pre_reservation_id & 0xff; response->preReservation_ID.buf[7] = '0' + pre_reservation_id & 0xff;
response->availabilityStatus = 0; response->availabilityStatus = 0;
response->supportedPaymentTypes.buf = calloc(1, sizeof(uint8_t)); response->supportedPaymentTypes.buf = calloc(1, sizeof(uint8_t));
@ -241,7 +276,7 @@ static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm
} }
*evrsrm_len = (enc.encoded + 7) / 8; *evrsrm_len = (enc.encoded + 7) / 8;
pre_reservation_id++; pre_reservation_id++;
cleanup: cleanup:
ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response); ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response);
return rv; return rv;