DCM neighbour mgmt effortsNeighbour mgmt efforts

This commit is contained in:
emanuel 2022-02-15 18:14:56 +00:00
parent eea1f89a55
commit f93d83438b
4 changed files with 80 additions and 2 deletions

29
README.md Normal file
View File

@ -0,0 +1,29 @@
## IT2S ITS-S Facilities
IT2S implementation of the ETSI ITS Facilities layer.
### Implemented services and messages
- CAM
- DENM
- IVIM
- CPM
- SAEM (modded)
- TPM (IT2S - Tolling Payments)
- DCM (IT2S - Maneuver Coordination)
### Compilation
Install with CMake:
```
mkdir build
cd build
cmake ..
make
```
### Usage
Run the compiled `it2s-itss-facilities` executable.
Needs IT2S ITS-S Transport, Security, Management and the Applications services to also be running.

View File

@ -317,6 +317,7 @@ cleanup:
int dcm_check(void* fc, DCM_t* dcm) {
facilities_t* facilities = (facilities_t*) fc;
coordination_s* coordination = &facilities->coordination;
int rv = 0;
@ -358,13 +359,31 @@ int dcm_check(void* fc, DCM_t* dcm) {
bool intersecting = false;
int index = 0;
pthread_mutex_lock(&coordination->lock);
// Find neighbours
int ni = -1;
for (int i = 0; i < coordination->neighbours_len; ++i) {
if (coordination->neighbours->station_id == dcm->header.stationID) {
ni = i;
break;
}
}
// Add it if not found
if (ni == -1 && coordination->neighbours_len + 1 < MC_MAX_NEIGHBOURS) {
coordination->neighbours[coordination->neighbours_len].station_id = dcm->header.stationID;
ni = coordination->neighbours_len;
++coordination->neighbours_len;
}
if (dcm->dcm.negotiation) {
switch (dcm->dcm.negotiation->present) {
case CoordinationNegotiation_PR_request:
dcm_check_handle_request(facilities, dcm);
dcm_check_handle_request(facilities, dcm);
break;
case CoordinationNegotiation_PR_reply:
dcm_check_handle_reply(facilities, dcm);
dcm_check_handle_reply(facilities, dcm);
break;
default:
break;
@ -380,10 +399,13 @@ int dcm_check(void* fc, DCM_t* dcm) {
if (intersecting) {
syslog_info("[facilities] [dc] intersection danger with %ld @ (%d, %d) in %ld ms",
dcm->header.stationID, trajectoryA[index].latitude, trajectoryA[index].longitude, trajectoryA[index].timestamp - now);
coordination->neighbours[ni].intersecting = true;
coordination->neighbours[ni].t_iid = now;
dcm_check_intersection_detected(facilities, dcm);
}
}
pthread_mutex_unlock(&coordination->lock);
return rv;
}
@ -450,6 +472,7 @@ cleanup:
void* dc_service(void* fc) {
facilities_t* facilities = (facilities_t*) fc;
coordination_s* coordination = (coordination_s*) &facilities->coordination;
uint8_t dcm[512];
@ -494,9 +517,18 @@ void* dc_service(void* fc) {
queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, 3);
pthread_mutex_lock(&coordination->lock);
pthread_mutex_unlock(&coordination->lock);
usleep(SLEEP_TIME_MS * 1000);
}
return NULL;
}
void coordination_init(coordination_s* coordination) {
pthread_mutex_init(&coordination->lock, NULL);
}

View File

@ -3,10 +3,26 @@
#include <stdbool.h>
#include <dcm/DCM.h>
#define MC_MAX_NEIGHBOURS 32
#define MC_RESOLUTION_TIMEOUT 1000
typedef struct {
uint64_t station_id;
bool intersecting;
uint64_t t_iid; /* initial intersection detection */
} mc_neighbour_s;
typedef struct coordination {
bool active;
pthread_mutex_t lock;
mc_neighbour_s neighbours[MC_MAX_NEIGHBOURS];
uint8_t neighbours_len;
} coordination_s;
int dcm_check(void* fc, DCM_t* dcm);
void* dc_service(void* fc);
void coordination_init(coordination_s* coordination);

View File

@ -678,6 +678,7 @@ int main() {
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
facilities.dissemination = dissemination_init();
bulletin_init(&facilities.bulletin);
coordination_init(&facilities.coordination);
time_t t;
srand((unsigned) time(&t));