DCM neighbour mgmt effortsNeighbour mgmt efforts
This commit is contained in:
parent
eea1f89a55
commit
f93d83438b
|
|
@ -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.
|
||||||
36
src/dcm.c
36
src/dcm.c
|
|
@ -317,6 +317,7 @@ cleanup:
|
||||||
|
|
||||||
int dcm_check(void* fc, DCM_t* dcm) {
|
int dcm_check(void* fc, DCM_t* dcm) {
|
||||||
facilities_t* facilities = (facilities_t*) fc;
|
facilities_t* facilities = (facilities_t*) fc;
|
||||||
|
coordination_s* coordination = &facilities->coordination;
|
||||||
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
|
@ -358,13 +359,31 @@ int dcm_check(void* fc, DCM_t* dcm) {
|
||||||
bool intersecting = false;
|
bool intersecting = false;
|
||||||
int index = 0;
|
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) {
|
if (dcm->dcm.negotiation) {
|
||||||
switch (dcm->dcm.negotiation->present) {
|
switch (dcm->dcm.negotiation->present) {
|
||||||
case CoordinationNegotiation_PR_request:
|
case CoordinationNegotiation_PR_request:
|
||||||
dcm_check_handle_request(facilities, dcm);
|
dcm_check_handle_request(facilities, dcm);
|
||||||
break;
|
break;
|
||||||
case CoordinationNegotiation_PR_reply:
|
case CoordinationNegotiation_PR_reply:
|
||||||
dcm_check_handle_reply(facilities, dcm);
|
dcm_check_handle_reply(facilities, dcm);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -380,10 +399,13 @@ int dcm_check(void* fc, DCM_t* dcm) {
|
||||||
if (intersecting) {
|
if (intersecting) {
|
||||||
syslog_info("[facilities] [dc] intersection danger with %ld @ (%d, %d) in %ld ms",
|
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);
|
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);
|
dcm_check_intersection_detected(facilities, dcm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&coordination->lock);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
@ -450,6 +472,7 @@ cleanup:
|
||||||
void* dc_service(void* fc) {
|
void* dc_service(void* fc) {
|
||||||
|
|
||||||
facilities_t* facilities = (facilities_t*) fc;
|
facilities_t* facilities = (facilities_t*) fc;
|
||||||
|
coordination_s* coordination = (coordination_s*) &facilities->coordination;
|
||||||
|
|
||||||
uint8_t dcm[512];
|
uint8_t dcm[512];
|
||||||
|
|
||||||
|
|
@ -494,9 +517,18 @@ void* dc_service(void* fc) {
|
||||||
|
|
||||||
queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, 3);
|
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);
|
usleep(SLEEP_TIME_MS * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void coordination_init(coordination_s* coordination) {
|
||||||
|
pthread_mutex_init(&coordination->lock, NULL);
|
||||||
|
}
|
||||||
|
|
|
||||||
16
src/dcm.h
16
src/dcm.h
|
|
@ -3,10 +3,26 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <dcm/DCM.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 {
|
typedef struct coordination {
|
||||||
bool active;
|
bool active;
|
||||||
|
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
|
||||||
|
mc_neighbour_s neighbours[MC_MAX_NEIGHBOURS];
|
||||||
|
uint8_t neighbours_len;
|
||||||
|
|
||||||
} coordination_s;
|
} coordination_s;
|
||||||
|
|
||||||
int dcm_check(void* fc, DCM_t* dcm);
|
int dcm_check(void* fc, DCM_t* dcm);
|
||||||
void* dc_service(void* fc);
|
void* dc_service(void* fc);
|
||||||
|
void coordination_init(coordination_s* coordination);
|
||||||
|
|
|
||||||
|
|
@ -678,6 +678,7 @@ int main() {
|
||||||
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
|
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
|
||||||
facilities.dissemination = dissemination_init();
|
facilities.dissemination = dissemination_init();
|
||||||
bulletin_init(&facilities.bulletin);
|
bulletin_init(&facilities.bulletin);
|
||||||
|
coordination_init(&facilities.coordination);
|
||||||
|
|
||||||
time_t t;
|
time_t t;
|
||||||
srand((unsigned) time(&t));
|
srand((unsigned) time(&t));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue