diff --git a/src/cam.c b/src/cam.c index 97558fa..fdb49fc 100644 --- a/src/cam.c +++ b/src/cam.c @@ -260,24 +260,34 @@ int check_cam(void* fc, BTPDataIndication_t *bdi, CAM_t* cam) { cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU) { ProtectedCommunicationZonesRSU_t *pzs = cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU; if (pzs->list.count > 0 && pzs->list.count + lightship->pz_len < 256) { - for (int i = lightship->pz_len; i < lightship->pz_len + pzs->list.count; ++i) { + for (int k = 0; k < pzs->list.count; ++k) { - lightship->pz[i] = calloc(1, sizeof(ProtectedCommunicationZone_t)); - lightship->pz[i]->protectedZoneLatitude = pzs->list.array[i]->protectedZoneLatitude; - lightship->pz[i]->protectedZoneLongitude = pzs->list.array[i]->protectedZoneLongitude; - lightship->pz[i]->protectedZoneType = pzs->list.array[i]->protectedZoneType; + bool found = false; + for (int j = 0; j < lightship->pz_len; ++j) { + if (lightship->pz[j]->protectedZoneLatitude == pzs->list.array[k]->protectedZoneLatitude && + lightship->pz[j]->protectedZoneLongitude == pzs->list.array[k]->protectedZoneLongitude) { + found = true; + break; + } + } + if (found) continue; - if (pzs->list.array[i]->expiryTime) { - lightship->pz[i]->expiryTime = malloc(8); - *lightship->pz[i]->expiryTime = *pzs->list.array[i]->expiryTime; + lightship->pz[k + lightship->pz_len] = calloc(1, sizeof(ProtectedCommunicationZone_t)); + lightship->pz[k + lightship->pz_len]->protectedZoneLatitude = pzs->list.array[k]->protectedZoneLatitude; + lightship->pz[k + lightship->pz_len]->protectedZoneLongitude = pzs->list.array[k]->protectedZoneLongitude; + lightship->pz[k + lightship->pz_len]->protectedZoneType = pzs->list.array[k]->protectedZoneType; + + if (pzs->list.array[k]->expiryTime) { + lightship->pz[k + lightship->pz_len]->expiryTime = malloc(8); + *lightship->pz[k + lightship->pz_len]->expiryTime = *pzs->list.array[k]->expiryTime; } - if (pzs->list.array[i]->protectedZoneID) { - lightship->pz[i]->protectedZoneID = malloc(8); - *lightship->pz[i]->protectedZoneID = *pzs->list.array[i]->protectedZoneID; + if (pzs->list.array[k]->protectedZoneID) { + lightship->pz[k + lightship->pz_len]->protectedZoneID = malloc(8); + *lightship->pz[k + lightship->pz_len]->protectedZoneID = *pzs->list.array[k]->protectedZoneID; } - if (pzs->list.array[i]->protectedZoneRadius) { - lightship->pz[i]->protectedZoneRadius = malloc(8); - *lightship->pz[i]->protectedZoneRadius = *pzs->list.array[i]->protectedZoneRadius; + if (pzs->list.array[k]->protectedZoneRadius) { + lightship->pz[k + lightship->pz_len]->protectedZoneRadius = malloc(8); + *lightship->pz[k + lightship->pz_len]->protectedZoneRadius = *pzs->list.array[k]->protectedZoneRadius; } ++lightship->pz_len; }