package art.servers.etdserver.protocols.diamond;
|
|
import art.library.model.devices.Device;
|
import art.library.model.devices.DeviceStatus;
|
import art.library.model.devices.etd.Etd;
|
import art.library.model.devices.etd.EtdInformation;
|
import art.library.model.devices.etd.EtdStatus;
|
import art.library.model.devices.etd.status.EtdStatusLane;
|
import art.library.interop.serialization.Serialization;
|
import art.library.model.devices.etd.status.EtdStatusVehicle;
|
import art.servers.etdserver.Shared;
|
import art.servers.etdserver.controller.ControllerEtd;
|
import art.servers.etdserver.protocols.diamond.configuration.DIAMOND_LengthBinnedData;
|
import art.servers.etdserver.protocols.diamond.configuration.DIAMOND_SpeedBinnedData;
|
import art.servers.etdserver.protocols.diamond.file.DIAMOND_Binned;
|
import art.servers.etdserver.protocols.diamond.file.DIAMOND_File;
|
import art.servers.etdserver.protocols.diamond.files.DIAMOND_Directory;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.StringTokenizer;
|
|
|
public class Diamond_ProtocolAnalyser
|
{
|
public static final int MASK_CHAR = 0x7D;
|
public static final int FLAG_CHAR = 0x7E;
|
|
|
public static int[] getData(int[] command)
|
{
|
int[] result = new int[command.length-3];
|
System.arraycopy(command, 1, result, 0, result.length);
|
return(unapplyMask(result));
|
}
|
|
|
public static int[] unapplyMask(int[] command)
|
{
|
try
|
{
|
int newLength = 0;
|
for (int i=0; i<command.length; i++)
|
{
|
if (command[i] == MASK_CHAR)
|
newLength--;
|
newLength++;
|
}
|
|
int[] result = new int[newLength];
|
int index = 0;
|
result[index++] = command[0];
|
for (int i=1; i<command.length-1; i++)
|
{
|
if (command[i] == MASK_CHAR)
|
{
|
if (command[i+1] == 0x5D)
|
result[index++] = MASK_CHAR;
|
else if (command[i+1] == 0x5E)
|
result[index++] = FLAG_CHAR;
|
i++;
|
}
|
else
|
{
|
result[index++] = command[i];
|
}
|
}
|
|
result[index++] = command[command.length-1];
|
return(result);
|
}
|
catch (Exception e)
|
{
|
return(command);
|
}
|
}
|
|
|
public static int[] createMessage(int[] command, int crc)
|
{
|
int[] result = new int[command.length + 3];
|
int index = 0;
|
result[index++] = FLAG_CHAR;
|
for (int i=0; i<command.length; i++)
|
{
|
result[index++] = command[i];
|
}
|
|
result[index++] = crc;
|
result[index++] = FLAG_CHAR;
|
return(result);
|
}
|
|
|
public static int crc(int[] command)
|
{
|
int crc = 0;
|
for (int i=0; i<command.length; i++)
|
{
|
crc += command[i];
|
}
|
|
return(crc%256);
|
}
|
|
|
public static void analyseSendPasswordResponse(Diamond_Message message) throws Exception
|
{
|
String str = message.getResponseString();
|
if (str.indexOf("OK") < 0) throw new Exception("Error sending counter password");
|
}
|
|
|
public static void analyseStartMonitorTrafficDataResponse(Diamond_Message message) throws Exception
|
{
|
String str = message.getResponseString();
|
if (str.indexOf("M01") < 0) throw new Exception("Error starting monitor traffic data");
|
}
|
|
|
public static DIAMOND_LengthBinnedData analyseGetLengthBinTableResponse(String firmwareversion, Diamond_Message message) throws Exception
|
{
|
DIAMOND_LengthBinnedData lenghtBinnedData = new DIAMOND_LengthBinnedData(firmwareversion, message.getResponseString());
|
return(lenghtBinnedData);
|
}
|
|
|
public static DIAMOND_SpeedBinnedData analyseGetSpeedBinTableResponse(Diamond_Message message) throws Exception
|
{
|
DIAMOND_SpeedBinnedData speedBinnedData = new DIAMOND_SpeedBinnedData(message.getResponseString());
|
return(speedBinnedData);
|
}
|
|
|
public static DIAMOND_Directory analyseGetFilesDirectoryResponse(Etd etd, Diamond_Message message) throws Exception
|
{
|
DIAMOND_Directory directory = new DIAMOND_Directory(etd.getDeviceInformation().firmwareVersion, message.getResponseString());
|
return(directory);
|
}
|
|
// A vehicle response is
|
// "2: 19:46:45.87 60.4kph, Length= 420cm, S#4 L#2 \r\n"
|
// "9: 19:46:45.45 SnMis #1\r\n"
|
// "2: 19:46:48.70 68.9kph, Length= 466cm, S#4 L#2 \r\n"
|
// "9: 19:47:47.77 SnMis #1\r\n"
|
// "9: 19:48:03.63 SnMis #1\r\n"
|
// "1: 19:48:13.31 103.4kph, Length= 327cm, S#8 L#2 \r\n"
|
// "2: 19:48:13.23 101.9kph, Length= 637cm, S#8 L#2 \r\n"
|
// "2: 19:48:24.70 92.7kph, Length= 434cm, S#7 L#2 \r\n"
|
// "2: 19:48:59.06 71.0kph, Length= 462cm, S#5 L#2 \r\n"
|
// "9: 19:49:06.29 SnMis #1\r\n"
|
// "2: 19:49:09.97 81.5kph, Length= 479cm, S#6 L#2 \r\n"
|
// "2: 19:50:11.26 58.7kph, Length= 614cm, S#3 L#2 \r\n"
|
// "2: 19:50:47.02 79.3kph, Length= 448cm, S#5 L#2 \r\n"
|
// "2: 19:50:50.82 72.8kph, Length= 408cm, S#5 L#2 \r\n"
|
// "9: 19:50:51.25 SnMis #1\r\n"
|
// "2: 19:52:51.65 75.9kph, Length= 772cm, S#5 L#3 \r\n"
|
|
public static List<EtdStatusVehicle> analyseVehicleResponse(Etd device, String response) throws Exception
|
{
|
try
|
{
|
List<EtdStatusVehicle> lvehicle = new ArrayList<EtdStatusVehicle>();
|
|
// System.out.println(device.getIdentifier() + " - ResponseVehicles: " + response);
|
|
StringTokenizer strtokVehicles = new StringTokenizer(response, "\n");
|
int countVehicles = strtokVehicles.countTokens();
|
|
for (int c=0; c<countVehicles; c++)
|
{
|
String svehicle = strtokVehicles.nextToken();
|
|
if (isVehicleDetection(svehicle) == true)
|
{
|
EtdStatusVehicle vehicle = new EtdStatusVehicle();
|
|
StringTokenizer strtok = new StringTokenizer(svehicle, " ");
|
int count = strtok.countTokens();
|
for (int i=0; i<count; i++)
|
{
|
String str = strtok.nextToken();
|
if ((str.indexOf(":") > -1) && (str.indexOf(".") < 0))
|
{
|
vehicle.lane = Integer.parseInt(str.replaceAll("\\*", "").replaceAll(":", ""));
|
}
|
else if ((str.indexOf(":") > -1) && (str.indexOf(".") > -1))
|
{
|
String stime = str + "0";
|
StringTokenizer strtokTime = new StringTokenizer(stime, ":");
|
int count2 = strtokTime.countTokens();
|
int hour = Integer.parseInt(strtokTime.nextToken());
|
int min = Integer.parseInt(strtokTime.nextToken());
|
String ssec = strtokTime.nextToken();
|
StringTokenizer strtokSeconds = new StringTokenizer(ssec, ".");
|
int seconds = Integer.parseInt(strtokSeconds.nextToken());
|
int milliseconds = Integer.parseInt(strtokSeconds.nextToken());
|
|
Calendar calCurrent = Calendar.getInstance();
|
calCurrent.setTimeInMillis(System.currentTimeMillis());
|
if ((calCurrent.get(Calendar.HOUR_OF_DAY) == 0) && (hour == 23))
|
{
|
// Es un vehiculo detectado en el cambio de día
|
Calendar cal = Calendar.getInstance();
|
cal.setTimeInMillis(calCurrent.getTimeInMillis());
|
cal.set(Calendar.DATE, cal.get(Calendar.DATE)-1);
|
cal.set(Calendar.HOUR_OF_DAY, hour);
|
cal.set(Calendar.MINUTE, min);
|
cal.set(Calendar.SECOND, seconds);
|
cal.set(Calendar.MILLISECOND, milliseconds);
|
vehicle.timestamp = cal.getTimeInMillis();
|
}
|
else
|
{
|
Calendar cal = Calendar.getInstance();
|
cal.setTimeInMillis(calCurrent.getTimeInMillis());
|
cal.set(Calendar.HOUR_OF_DAY, hour);
|
cal.set(Calendar.MINUTE, min);
|
cal.set(Calendar.SECOND, seconds);
|
cal.set(Calendar.MILLISECOND, milliseconds);
|
vehicle.timestamp = cal.getTimeInMillis();
|
}
|
}
|
else
|
{
|
if (str.indexOf("kph") > -1)
|
{
|
vehicle.speed = Double.parseDouble(str.substring(0, str.indexOf("kph")));
|
}
|
else if (str.indexOf("cm") > -1)
|
{
|
vehicle.length = Integer.parseInt(str.substring(0, str.indexOf("cm")));
|
}
|
else if (str.indexOf("SnMis") > -1)
|
{
|
vehicle.speed = 0d;
|
vehicle.length = 0;
|
vehicle.axles = 0;
|
vehicle.axlesSpacing = new int[0];
|
}
|
else if (str.indexOf("S#") > -1)
|
{
|
// vehicle.speedBin = Integer.parseInt(str.substring(str.indexOf("S#")+2));
|
}
|
else if (str.indexOf("L#") > -1)
|
{
|
// vehicle.lengthBin = Integer.parseInt(str.substring(str.indexOf("L#")+2));
|
}
|
}
|
}
|
|
lvehicle.add(vehicle);
|
}
|
else
|
{
|
}
|
}
|
|
return(lvehicle);
|
}
|
catch (Exception e)
|
{
|
throw e;
|
}
|
}
|
|
|
public static boolean analyseRetrieveFileDataContent(Etd etdoriginal, Etd etd, DIAMOND_File file, DIAMOND_LengthBinnedData lengthBinnedData, DIAMOND_SpeedBinnedData speedBinnedData) throws Exception
|
{
|
long millis = System.currentTimeMillis();
|
boolean delete = false;
|
EtdInformation information = etd.getDeviceInformation();
|
|
int periods = file.ltimestamps.size();
|
periods = Math.min(periods, file.lbinnedSpeed.size());
|
periods = Math.min(periods, file.lbinnedLength.size());
|
|
DiamondLengthRelation[] lengthRelations8 = createLengthRelations8();
|
DiamondLengthRelation[] lengthRelations9 = createLengthRelations9();
|
DiamondLengthRelation[] lengthRelations11 = createLengthRelations11();
|
Shared.println(etd.information.name, "1.ANALYSE: #periods: " + periods + " - DIF: " + (System.currentTimeMillis()-millis));
|
|
for (int i=0; i<periods; i++)
|
{
|
try
|
{
|
EtdStatus statusOriginal = etdoriginal.getDeviceStatus();
|
long lastTimestamp = Device.getTimestamp(statusOriginal.getMeasurementTimestamp());
|
long timestampPeriod = file.ltimestamps.get(i).longValue() + (etd.getDeviceInformation().period*1000L);
|
|
if (timestampPeriod > lastTimestamp)
|
{
|
Shared.println(etd.information.name, "2.ANALYSE: period[" + i + "] LAST: " + new Date(lastTimestamp).toString() + " PERIOD: " + new Date(timestampPeriod).toString() + " - DIF: " + (System.currentTimeMillis()-millis));
|
Etd etdData = (Etd)Serialization.clone(etd);
|
EtdStatus status = etdData.getDeviceStatus();
|
status.period = etdData.getDeviceInformation().period;
|
if (status.llane.size() < information.lLane.size())
|
{
|
for (int f=status.llane.size(); f<information.lLane.size(); f++)
|
{
|
EtdStatusLane laneStatus = new EtdStatusLane();
|
laneStatus.number = information.lLane.get(f).number;
|
laneStatus.totalMeasurements = 1;
|
laneStatus.correctMeasurements = 1;
|
laneStatus.lengths = new int[information.lLengthClassification.size()];
|
laneStatus.speeds = new int[information.lSpeedClassification.size()];
|
laneStatus.speedxlength = new int[information.lSpeedClassification.size()][information.lLengthClassification.size()];
|
status.llane.add(laneStatus);
|
}
|
}
|
else if (status.llane.size() > information.lLane.size())
|
{
|
for (int f=status.llane.size()-1; f>=information.lLane.size(); f--)
|
{
|
status.llane.remove(status.llane.size()-1);
|
}
|
}
|
|
for (int f=0; f<status.llane.size(); f++)
|
{
|
EtdStatusLane laneStatus = status.llane.get(f);
|
laneStatus.totalMeasurements = 1;
|
laneStatus.correctMeasurements = 1;
|
if ((laneStatus.lengths.length != information.lLengthClassification.size()) || (laneStatus.speeds.length != information.lSpeedClassification.size()))
|
laneStatus.speedxlength = new int[information.lSpeedClassification.size()][information.lLengthClassification.size()];
|
if (laneStatus.lengths.length != information.lLengthClassification.size())
|
laneStatus.lengths = new int[information.lLengthClassification.size()];
|
if (laneStatus.speeds.length != information.lSpeedClassification.size())
|
laneStatus.speeds = new int[information.lSpeedClassification.size()];
|
|
for (int j=0; j<laneStatus.lengths.length; j++)
|
laneStatus.lengths[j] = 0;
|
for (int j=0; j<laneStatus.speeds.length; j++)
|
laneStatus.speeds[j] = 0;
|
for (int j=0; j<laneStatus.speedxlength.length; j++)
|
{
|
for (int k=0; k<laneStatus.speedxlength[j].length; k++)
|
laneStatus.speedxlength[j][k] = 0;
|
}
|
|
laneStatus.counting = 0;
|
laneStatus.unclassified = 0;
|
laneStatus.occupancy = 0;
|
laneStatus.speed = 0;
|
}
|
|
if (status.lsection.size() < information.lSection.size())
|
{
|
for (int f=status.lsection.size(); f<information.lSection.size(); f++)
|
{
|
EtdStatusLane sectionStatus = new EtdStatusLane();
|
sectionStatus.number = information.lSection.get(f).number;
|
sectionStatus.lengths = new int[information.lLengthClassification.size()];
|
sectionStatus.speeds = new int[information.lSpeedClassification.size()];
|
sectionStatus.speedxlength = new int[information.lSpeedClassification.size()][information.lLengthClassification.size()];
|
status.lsection.add(sectionStatus);
|
}
|
}
|
else if (status.lsection.size() > information.lSection.size())
|
{
|
for (int f=status.lsection.size()-1; f>=information.lSection.size(); f--)
|
{
|
status.lsection.remove(status.lsection.size()-1);
|
}
|
}
|
|
for (int f=0; f<status.lsection.size(); f++)
|
{
|
EtdStatusLane sectionStatus = status.lsection.get(f);
|
if ((sectionStatus.lengths.length != information.lLengthClassification.size()) || (sectionStatus.speeds.length != information.lSpeedClassification.size()))
|
sectionStatus.speedxlength = new int[information.lSpeedClassification.size()][information.lLengthClassification.size()];
|
if (sectionStatus.lengths.length != information.lLengthClassification.size())
|
sectionStatus.lengths = new int[information.lLengthClassification.size()];
|
if (sectionStatus.speeds.length != information.lSpeedClassification.size())
|
sectionStatus.speeds = new int[information.lSpeedClassification.size()];
|
|
for (int j=0; j<sectionStatus.lengths.length; j++)
|
sectionStatus.lengths[j] = 0;
|
for (int j=0; j<sectionStatus.speeds.length; j++)
|
sectionStatus.speeds[j] = 0;
|
for (int j=0; j<sectionStatus.speedxlength.length; j++)
|
{
|
for (int k=0; k<sectionStatus.speedxlength[j].length; k++)
|
sectionStatus.speedxlength[j][k] = 0;
|
}
|
|
sectionStatus.counting = 0;
|
sectionStatus.unclassified = 0;
|
sectionStatus.occupancy = 0;
|
sectionStatus.speed = 0;
|
}
|
|
status.total = new EtdStatusLane();
|
status.total.number = 0;
|
status.total.totalMeasurements = information.lLane.size();
|
status.total.correctMeasurements = information.lLane.size();
|
status.total.lengths = new int[information.lLengthClassification.size()];
|
status.total.speeds = new int[information.lSpeedClassification.size()];
|
status.total.speedxlength = new int[information.lSpeedClassification.size()][information.lLengthClassification.size()];
|
for (int j=0; j<status.total.lengths.length; j++)
|
status.total.lengths[j] = 0;
|
for (int j=0; j<status.total.speeds.length; j++)
|
status.total.speeds[j] = 0;
|
for (int j=0; j<status.total.speedxlength.length; j++)
|
{
|
for (int k=0; k<status.total.speedxlength[j].length; k++)
|
status.total.speedxlength[j][k] = 0;
|
}
|
|
status.total.counting = 0;
|
status.total.unclassified = 0;
|
status.total.occupancy = 0;
|
status.total.speed = 0;
|
|
|
status.setMeasurementTimestamp(Device.getDate(timestampPeriod));
|
|
try
|
{
|
int nlanes = etdData.getDeviceInformation().lLane.size();
|
|
if (nlanes == file.llaneConfiguration.size())
|
{
|
// Without directional lanes
|
|
DIAMOND_Binned binnedSpeed = file.lbinnedSpeed.get(i);
|
for (int l=0; l<file.llaneConfiguration.size(); l++)
|
{
|
int[] speeds = binnedSpeed.valores[l];
|
int total = 0;
|
for (int s=0; s<speeds.length; s++)
|
{
|
if (s < status.total.speeds.length)
|
{
|
status.llane.get(l).speeds[s] = speeds[s];
|
total += speeds[s];
|
}
|
}
|
|
float speed = 0f;
|
for (int s=0; s<speeds.length; s++)
|
{
|
speed += ((float)speeds[s]) * speedBinnedData.bins[s].avgSpeed;
|
}
|
|
if (total > 0)
|
{
|
status.llane.get(l).speed = (int)((speed / (float)total) / 10);
|
}
|
}
|
}
|
else if ((nlanes*2) == file.llaneConfiguration.size())
|
{
|
// With directional lanes
|
|
DIAMOND_Binned binnedSpeed = file.lbinnedSpeed.get(i);
|
for (int l=0; l<nlanes; l++)
|
{
|
int[] speeds1 = binnedSpeed.valores[l];
|
int oppositeLane = etd.getDeviceInformation().lLane.get(l).oppositeLane-9+nlanes;
|
int[] speeds2 = new int[speeds1.length];
|
if (oppositeLane >= 0)
|
{
|
speeds2 = binnedSpeed.valores[oppositeLane];
|
}
|
|
int total = 0;
|
for (int s=0; s<speeds1.length; s++)
|
{
|
if (s < status.total.speeds.length)
|
{
|
status.llane.get(l).speeds[s] = speeds1[s] + speeds2[s];
|
total += speeds1[s] + speeds2[s];
|
}
|
}
|
|
float speed = 0f;
|
for (int s=0; s<speeds1.length; s++)
|
{
|
speed += ((float)speeds1[s]) * speedBinnedData.bins[s].avgSpeed;
|
speed += ((float)speeds2[s]) * speedBinnedData.bins[s].avgSpeed;
|
}
|
|
if (total > 0)
|
{
|
status.llane.get(l).speed = (int)((speed / (float)total) / 10);
|
}
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
|
try
|
{
|
int nlanes = etdData.getDeviceInformation().lLane.size();
|
|
if (nlanes == file.llaneConfiguration.size())
|
{
|
// Without directional lanes
|
|
DIAMOND_Binned binnedLength = file.lbinnedLength.get(i);
|
for (int l=0; l<file.llaneConfiguration.size(); l++)
|
{
|
int total = 0;
|
int[] lengths = binnedLength.valores[l];
|
DiamondLengthRelation[] relations = null;
|
if (lengths.length == 8) relations = lengthRelations8;
|
if (lengths.length == 9) relations = lengthRelations9;
|
if (lengths.length == 11) relations = lengthRelations11;
|
for (int s=0; s<lengths.length; s++)
|
{
|
DiamondLengthRelation relation = getRelation(relations, s);
|
if (relation.lublinClassification < status.total.lengths.length)
|
{
|
status.llane.get(l).lengths[relation.lublinClassification] = status.llane.get(l).lengths[relation.lublinClassification] + lengths[s];
|
total += lengths[s];
|
}
|
}
|
|
status.llane.get(l).counting = total;
|
}
|
}
|
else if ((nlanes*2) == file.llaneConfiguration.size())
|
{
|
// With directional lanes
|
|
DIAMOND_Binned binnedLength = file.lbinnedLength.get(i);
|
for (int l=0; l<nlanes; l++)
|
{
|
int total = 0;
|
int[] lengths1 = binnedLength.valores[l];
|
int oppositeLane = etd.getDeviceInformation().lLane.get(l).oppositeLane-9+nlanes;
|
int[] lengths2 = new int[lengths1.length];
|
if (oppositeLane >= 0)
|
{
|
lengths2 = binnedLength.valores[oppositeLane];
|
}
|
|
DiamondLengthRelation[] relations = null;
|
if (lengths1.length == 8) relations = lengthRelations8;
|
if (lengths1.length == 9) relations = lengthRelations9;
|
if (lengths1.length == 11) relations = lengthRelations11;
|
for (int s=0; s<lengths1.length; s++)
|
{
|
DiamondLengthRelation relation = getRelation(relations, s);
|
if (relation.lublinClassification < status.total.lengths.length)
|
{
|
status.llane.get(l).lengths[relation.lublinClassification] = status.llane.get(l).lengths[relation.lublinClassification] + lengths1[s] + lengths2[s];
|
total += lengths1[s] + lengths2[s];
|
}
|
}
|
|
status.llane.get(l).counting = total;
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
|
try
|
{
|
DIAMOND_Binned binnedError = file.lbinnedError.get(i);
|
}
|
catch (Exception e)
|
{
|
}
|
|
|
// Sections calculation
|
Shared.setSectionsData(etdData);
|
|
// Total calculation
|
Shared.setTotalData(etdData);
|
|
|
if (etdData.alarms.alarm_offline > 0)
|
{
|
String message = art.servers.Shared.getMessage("Etd online");
|
try
|
{
|
art.servers.Shared.println(((ControllerEtd)art.servers.Shared.getDeviceController(etdData.getIdentifier())).getControllerName(), message);
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
}
|
|
etdData.setAlarm("alarm_offline", false);
|
etdData.setAlarm("alarm_invalid", false);
|
|
// if (i == periods-1)
|
{
|
// CHECK
|
// Shared.model.updateDeviceStatus(etdData, etdData.getDeviceStatus().measurementTimestamp);
|
etdData.setLastTimestampStatusUpdate(etdData.getDeviceStatus().measurementTimestamp);
|
Shared.println(etd.information.name, "3.ANALYSE: period[" + i + "] LAST: " + new Date(lastTimestamp).toString() + " PERIOD: " + etdData.getDeviceStatus().getMeasurementTimestamp() + " - DIF: " + (System.currentTimeMillis()-millis));
|
}
|
|
|
// Fill maxSpeed, overspeedCars, heavyTrucks
|
int speedLimit = etdData.getDeviceInformation().speedLimit;
|
if (speedLimit <= 0)
|
{
|
speedLimit = getSpeedLimit(etd.getIdentifier());
|
}
|
|
for (int l=0; l<etdData.getDeviceStatus().llane.size(); l++)
|
{
|
EtdStatusLane laneStatus = etdData.getDeviceStatus().llane.get(l);
|
int totalTrucksLane = 0;
|
int totalVehiclesLane = laneStatus.counting;
|
for (int j=0; j<laneStatus.lengths.length; j++)
|
{
|
if (laneStatus.lengths.length <= 2)
|
{
|
if (j == 1) totalTrucksLane += laneStatus.lengths[j];
|
}
|
else if (laneStatus.lengths.length >= 7)
|
{
|
if ((j == 3) || (j == 4) || (j == 5)) totalTrucksLane += laneStatus.lengths[j];
|
}
|
}
|
|
laneStatus.overspeedCars = 0;
|
for (int k=0; k<laneStatus.speeds.length; k++)
|
{
|
if (laneStatus.speeds[k] > 0)
|
{
|
laneStatus.maxSpeed = (double)((double)etdData.getDeviceInformation().lSpeedClassification.get(k).upperLimit + (double)etdData.getDeviceInformation().lSpeedClassification.get(k).lowerLimit) / 2d;
|
|
if (etdData.getDeviceInformation().lSpeedClassification.get(k).lowerLimit >= speedLimit)
|
{
|
laneStatus.overspeedCars += laneStatus.speeds[k];
|
}
|
}
|
}
|
|
if (totalVehiclesLane > 0)
|
{
|
laneStatus.heavyTrucks = (float)((float)totalTrucksLane / (float)totalVehiclesLane) * 100f;
|
int heavyTrucks = (int)(laneStatus.heavyTrucks*100f);
|
laneStatus.heavyTrucks = (float)((float)heavyTrucks / 100f);
|
}
|
|
if (laneStatus.maxSpeed > 0)
|
{
|
int maxSpeed = (int)(laneStatus.maxSpeed*100d);
|
laneStatus.maxSpeed = (double)((double)maxSpeed / 100d);
|
}
|
}
|
|
for (int s=0; s<etdData.getDeviceStatus().lsection.size(); s++)
|
{
|
EtdStatusLane sectionStatus = etdData.getDeviceStatus().lsection.get(s);
|
int totalTrucksLane = 0;
|
int totalVehiclesLane = sectionStatus.counting;
|
for (int j=0; j<sectionStatus.lengths.length; j++)
|
{
|
if (sectionStatus.lengths.length <= 2)
|
{
|
if (j == 1) totalTrucksLane += sectionStatus.lengths[j];
|
}
|
else if (sectionStatus.lengths.length >= 7)
|
{
|
if ((j == 3) || (j == 4) || (j == 5)) totalTrucksLane += sectionStatus.lengths[j];
|
}
|
}
|
|
sectionStatus.overspeedCars = 0;
|
for (int k=0; k<sectionStatus.speeds.length; k++)
|
{
|
if (sectionStatus.speeds[k] > 0)
|
{
|
sectionStatus.maxSpeed = (double)((double)etdData.getDeviceInformation().lSpeedClassification.get(k).upperLimit + (double)etdData.getDeviceInformation().lSpeedClassification.get(k).lowerLimit) / 2d;
|
|
if (etdData.getDeviceInformation().lSpeedClassification.get(k).lowerLimit >= speedLimit)
|
{
|
sectionStatus.overspeedCars += sectionStatus.speeds[k];
|
}
|
}
|
}
|
|
if (totalVehiclesLane > 0)
|
{
|
sectionStatus.heavyTrucks = (float)((float)totalTrucksLane / (float)totalVehiclesLane) * 100f;
|
int heavyTrucks = (int)(sectionStatus.heavyTrucks*100f);
|
sectionStatus.heavyTrucks = (float)((float)heavyTrucks / 100f);
|
}
|
|
if (sectionStatus.maxSpeed > 0)
|
{
|
int maxSpeed = (int)(sectionStatus.maxSpeed*100d);
|
sectionStatus.maxSpeed = (double)((double)maxSpeed / 100d);
|
}
|
}
|
|
|
EtdStatusLane totalStatus = etdData.getDeviceStatus().total;
|
int totalTrucksLane = 0;
|
int totalVehiclesLane = totalStatus.counting;
|
for (int j=0; j<totalStatus.lengths.length; j++)
|
{
|
if (totalStatus.lengths.length <= 2)
|
{
|
if (j == 1) totalTrucksLane += totalStatus.lengths[j];
|
}
|
else if (totalStatus.lengths.length >= 7)
|
{
|
if ((j == 3) || (j == 4) || (j == 5)) totalTrucksLane += totalStatus.lengths[j];
|
}
|
}
|
|
totalStatus.overspeedCars = 0;
|
for (int k=0; k<totalStatus.speeds.length; k++)
|
{
|
if (totalStatus.speeds[k] > 0)
|
{
|
totalStatus.maxSpeed = (double)((double)etdData.getDeviceInformation().lSpeedClassification.get(k).upperLimit + (double)etdData.getDeviceInformation().lSpeedClassification.get(k).lowerLimit) / 2d;
|
|
if (etdData.getDeviceInformation().lSpeedClassification.get(k).lowerLimit >= speedLimit)
|
{
|
totalStatus.overspeedCars += totalStatus.speeds[k];
|
}
|
}
|
}
|
|
if (totalVehiclesLane > 0)
|
{
|
totalStatus.heavyTrucks = (float)((float)totalTrucksLane / (float)totalVehiclesLane) * 100f;
|
int heavyTrucks = (int)(totalStatus.heavyTrucks*100f);
|
totalStatus.heavyTrucks = (float)((float)heavyTrucks / 100f);
|
}
|
|
if (totalStatus.maxSpeed > 0)
|
{
|
int maxSpeed = (int)(totalStatus.maxSpeed*100d);
|
totalStatus.maxSpeed = (double)((double)maxSpeed / 100d);
|
}
|
|
Shared.println(etd.information.name, "4.ANALYSE: period[" + i + "] LAST: " + new Date(lastTimestamp).toString() + " PERIOD: " + etdData.getDeviceStatus().getMeasurementTimestamp() + " - DIF: " + (System.currentTimeMillis()-millis) + " - " + new Date(etdoriginal.getLastTimestampStatusUpdate()) + " - " + new Date(etdData.getLastTimestampStatusUpdate()));
|
Shared.model.updateDevice(etdoriginal, etdData);
|
Shared.println(etd.information.name, "5.ANALYSE: period[" + i + "] LAST: " + new Date(lastTimestamp).toString() + " PERIOD: " + etdData.getDeviceStatus().getMeasurementTimestamp() + " - DIF: " + (System.currentTimeMillis()-millis) + " - " + new Date(etdoriginal.getLastTimestampStatusUpdate()) + " - " + new Date(etdData.getLastTimestampStatusUpdate()));
|
|
delete = true;
|
}
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
}
|
|
if (delete == false)
|
{
|
if (etd.alarms.alarm_offline > 0)
|
{
|
String message = art.servers.Shared.getMessage("Etd online");
|
art.servers.Shared.println(((ControllerEtd)art.servers.Shared.getDeviceController(etd.getIdentifier())).getControllerName(), message);
|
}
|
|
etd.setAlarm("alarm_offline", false);
|
etd.setAlarm("alarm_invalid", false);
|
Shared.model.updateDevice(etdoriginal, etd);
|
}
|
|
try
|
{
|
((ControllerEtd)art.servers.Shared.getDeviceController(etd.getIdentifier())).errorsNumber = 0;
|
String message = "Errors=0";
|
art.servers.Shared.println(((ControllerEtd)art.servers.Shared.getDeviceController(etd.getIdentifier())).getControllerName(), message);
|
}
|
catch (Exception e)
|
{
|
}
|
|
return(delete);
|
}
|
|
|
|
|
|
private static DiamondLengthRelation[] createLengthRelations8()
|
{
|
DiamondLengthRelation[] result = new DiamondLengthRelation[8];
|
for (int i=0; i<result.length; i++)
|
{
|
result[i] = new DiamondLengthRelation();
|
if (i == 0)
|
{
|
result[i].lublinClassification = 0;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 0;
|
}
|
else if (i == 1)
|
{
|
result[i].lublinClassification = 1;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 1;
|
}
|
else if (i == 2)
|
{
|
result[i].lublinClassification = 2;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 2;
|
}
|
else if (i == 3)
|
{
|
result[i].lublinClassification = 3;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 3;
|
}
|
else if (i == 4)
|
{
|
result[i].lublinClassification = 4;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 4;
|
}
|
else if (i == 5)
|
{
|
result[i].lublinClassification = 5;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 5;
|
}
|
else if (i == 6)
|
{
|
result[i].lublinClassification = 6;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 6;
|
result[i].realBins[1] = 7;
|
}
|
}
|
|
return(result);
|
}
|
|
|
|
|
|
private static DiamondLengthRelation[] createLengthRelations9()
|
{
|
DiamondLengthRelation[] result = new DiamondLengthRelation[9];
|
for (int i=0; i<result.length; i++)
|
{
|
result[i] = new DiamondLengthRelation();
|
if (i == 0)
|
{
|
result[i].lublinClassification = 0;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 1;
|
}
|
else if (i == 1)
|
{
|
result[i].lublinClassification = 1;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 0;
|
result[i].realBins[1] = 2;
|
}
|
else if (i == 2)
|
{
|
result[i].lublinClassification = 2;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 3;
|
}
|
else if (i == 3)
|
{
|
result[i].lublinClassification = 3;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 4;
|
}
|
else if (i == 4)
|
{
|
result[i].lublinClassification = 4;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 5;
|
}
|
else if (i == 5)
|
{
|
result[i].lublinClassification = 5;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 6;
|
}
|
else if (i == 6)
|
{
|
result[i].lublinClassification = 6;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 7;
|
result[i].realBins[1] = 8;
|
}
|
}
|
|
return(result);
|
}
|
|
|
|
|
|
private static DiamondLengthRelation[] createLengthRelations11()
|
{
|
DiamondLengthRelation[] result = new DiamondLengthRelation[8];
|
for (int i=0; i<result.length; i++)
|
{
|
result[i] = new DiamondLengthRelation();
|
if (i == 0)
|
{
|
result[i].lublinClassification = 0;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 0;
|
}
|
else if (i == 1)
|
{
|
result[i].lublinClassification = 1;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 1;
|
result[i].realBins[1] = 2;
|
}
|
else if (i == 2)
|
{
|
result[i].lublinClassification = 2;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 3;
|
}
|
else if (i == 3)
|
{
|
result[i].lublinClassification = 3;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 4;
|
result[i].realBins[1] = 5;
|
}
|
else if (i == 4)
|
{
|
result[i].lublinClassification = 4;
|
result[i].realBins = new int[1];
|
result[i].realBins[0] = 6;
|
}
|
else if (i == 5)
|
{
|
result[i].lublinClassification = 5;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 7;
|
result[i].realBins[1] = 8;
|
}
|
else if (i == 6)
|
{
|
result[i].lublinClassification = 6;
|
result[i].realBins = new int[2];
|
result[i].realBins[0] = 9;
|
result[i].realBins[1] = 10;
|
}
|
}
|
|
return(result);
|
}
|
|
|
|
|
|
private static DiamondLengthRelation getRelation(DiamondLengthRelation[] relations, int bin)
|
{
|
for (int i=0; i<relations.length; i++)
|
{
|
for (int j=0; j<relations[i].realBins.length; j++)
|
{
|
if (relations[i].realBins[j] == bin)
|
return(relations[i]);
|
}
|
}
|
|
return(null);
|
}
|
|
|
private static boolean isVehicleDetection(String response)
|
{
|
try
|
{
|
int firstChar = response.charAt(0);
|
if (((firstChar == 42) || ((firstChar >= 0x30) && (firstChar <= 0x39)))
|
&&
|
(response.indexOf(":") > -1))
|
{
|
return(true);
|
}
|
}
|
catch (Exception e)
|
{
|
|
}
|
|
return(false);
|
}
|
|
|
|
|
private static int getSpeedLimit(String etdIdentifier)
|
{
|
try
|
{
|
if (etdIdentifier.equalsIgnoreCase("etd-krzewica-1")) return(90);
|
if (etdIdentifier.equalsIgnoreCase("etd-terespol-1")) return(90);
|
if (etdIdentifier.equalsIgnoreCase("etd-wólkaokopska-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-żyrzyn-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-piaski-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-łopienniknadrzeczny-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-izbica-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-łabuniereforma-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-polanówka-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-hrebenne-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-międzyrzecpodlaski-1")) return(100);
|
if (etdIdentifier.equalsIgnoreCase("etd-radzyńpodlaski-1")) return(90);
|
if (etdIdentifier.equalsIgnoreCase("etd-sobieszyn-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-annopol-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-szczebrzeszyn-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-miączyn-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-łęczna-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-włodawa-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-wisznice-1")) return(70);
|
if (etdIdentifier.equalsIgnoreCase("etd-sławatycze-1")) return(50);
|
if (etdIdentifier.equalsIgnoreCase("etd-staraprawda-1")) return(60);
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
|
return(70);
|
}
|
|
}
|