package art.servers.fleetserver.controller;
|
|
import art.library.model.devices.DeviceStatus;
|
import art.library.model.devices.vehicle.Vehicle;
|
import art.library.model.devices.vehicle.VehiclePosition;
|
import art.library.model.devices.vehicle.VehicleRealtime;
|
import art.servers.fleetserver.Shared;
|
import art.servers.fleetserver.configuration.ConfigurationRadio;
|
import art.servers.fleetserver.radio.sepura.CTSDSR;
|
import art.servers.fleetserver.radio.sepura.MOD_10_1147;
|
import art.servers.fleetserver.radio.sepura.MOD_10_1243;
|
import java.io.BufferedReader;
|
import java.io.InputStreamReader;
|
import java.net.Socket;
|
|
|
public class ControllerRadioSepura extends art.servers.controller.Controller
|
{
|
private ConfigurationRadio configurationRadio = null;
|
private Socket socket = null;
|
private BufferedReader reader = null;
|
private int status = DeviceStatus.STATUS_ALARM;
|
private String name = "";
|
|
|
public ControllerRadioSepura(ConfigurationRadio configurationRadio)
|
{
|
this.configurationRadio = configurationRadio;
|
this.setName(this.getClass().getName() + " : " + configurationRadio.name);
|
this.name = this.getName();
|
}
|
|
|
|
public void run()
|
{
|
Shared.traceInformation(configurationRadio.name, "Starting");
|
|
while ((isInterrupted() == false) && (exit == false))
|
{
|
try
|
{
|
connect();
|
}
|
catch (Exception e)
|
{
|
disconnect();
|
}
|
|
|
try
|
{
|
String command = readLine();
|
|
if (command.indexOf("+CTSDSR: ") == 0)
|
{
|
analyseCTSDSR(command);
|
}
|
}
|
catch (Exception e)
|
{
|
disconnect();
|
}
|
}
|
|
Shared.traceInformation(configurationRadio.name, "Finishing");
|
|
disconnect();
|
}
|
|
|
|
|
private void connect()
|
{
|
try
|
{
|
if (socket != null)
|
{
|
if (socket.isConnected() == true)
|
{
|
return;
|
}
|
}
|
|
socket = new Socket(configurationRadio.address, configurationRadio.port);
|
socket.setSoTimeout(configurationRadio.timeout);
|
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
|
if (status != DeviceStatus.STATUS_ONLINE)
|
{
|
String message = Shared.configuration.getMessage("Connected, address = %1, port = %2, timeout = %3");
|
message = message.replace("%1", configurationRadio.address);
|
message = message.replace("%2", "" +configurationRadio.port);
|
message = message.replace("%3", "" + configurationRadio.timeout);
|
Shared.println(configurationRadio.name, message);
|
status = DeviceStatus.STATUS_ONLINE;
|
}
|
|
}
|
catch (Exception e)
|
{
|
disconnect();
|
}
|
}
|
|
|
|
|
private void disconnect()
|
{
|
if (status == DeviceStatus.STATUS_ONLINE)
|
{
|
Shared.println(configurationRadio.name, Shared.configuration.getMessage("Disconnected"));
|
}
|
|
status = DeviceStatus.STATUS_ALARM;
|
|
try
|
{
|
sleep(5000);
|
}
|
catch (Exception e)
|
{
|
}
|
|
try { reader.close(); }catch (Exception e) {}
|
try { socket.close(); }catch (Exception e) {}
|
reader = null;
|
socket = null;
|
}
|
|
|
|
|
|
private void analyseCTSDSR(String command)
|
{
|
try
|
{
|
CTSDSR ctsdsr = MOD_10_1243.CTSDSR(this, command.replace("+CTSDSR: ", ""), readLine());
|
|
if ((ctsdsr.service == 108) || (ctsdsr.service == 12))
|
{
|
// 12 : SDS type 4
|
// 108 : SDS type 4 (incoming message to MT copied to TE)
|
|
if (ctsdsr.calledPartyIdentity.replace("21400080", "").equals(configurationRadio.SSI))
|
{
|
int protocoloIdentifier = Integer.parseInt(ctsdsr.userData.substring(0, 2), 16);
|
|
if (protocoloIdentifier == 0x03)
|
{
|
VehiclePosition vehiclePosition = MOD_10_1147.proprietaryFormatMinimalCompactFullLocationReport(ctsdsr.userData);
|
vehiclePosition.ISSI = ctsdsr.callingPartyIdentity.replace("21400080", "");
|
Vehicle vehicle = (Vehicle)Shared.model.getDevice(vehiclePosition.ISSI);
|
vehicle.realtime = new VehicleRealtime();
|
vehicle.realtime.identifier = vehicle.getIdentifier();
|
vehicle.getDeviceRealtime().position = vehiclePosition;
|
Shared.getModel().updateDevice(vehicle, vehiclePosition, null);
|
}
|
else
|
{
|
String message = Shared.configuration.getMessage("Protocol identifier %1 not valid");
|
message = message.replace("%1", String.format("%02X", protocoloIdentifier)) + ", " + ctsdsr.toString();
|
Shared.println(configurationRadio.name, message);
|
throw new Exception(message);
|
}
|
}
|
else
|
{
|
String message = Shared.configuration.getMessage("ISSI not valid");
|
message = message + ", " + ctsdsr.toString();
|
Shared.println(configurationRadio.name, message);
|
throw new Exception(message);
|
}
|
|
}
|
else
|
{
|
String message = Shared.configuration.getMessage("Service not implemented yet");
|
message = message + ", " + ctsdsr.toString();
|
Shared.println(configurationRadio.name, message);
|
throw new Exception(message);
|
}
|
}
|
catch (Exception e)
|
{
|
Shared.println(configurationRadio.name, e.getMessage());
|
}
|
}
|
|
|
|
|
|
private String readLine() throws Exception
|
{
|
try
|
{
|
return reader.readLine().trim();
|
}
|
catch (Exception e)
|
{
|
}
|
|
throw new Exception(Shared.configuration.getMessage("Timeout"));
|
}
|
|
|
|
|
|
|
/*
|
+CTSDSR: 12,214000806013507,1,214000806010005,1,81
|
038042A3B145701BD2840
|
|
+CTSDSR: 12,214000806013504,1,214000806010005,1,81
|
038042B3B186D01BD4B50
|
|
+CTSDSR: 12,214000806013907,1,214000806010005,1,81
|
038042B3B14BE01BB7D40
|
|
+CTSDSR: 12,214000806013413,1,214000806010005,1,81
|
03804373B11F401BD2440
|
|
+CTSDSR: 12,214000806013510,1,214000806010005,1,81
|
038043C3B187A01BD7750
|
|
|
+CTSDSR: 12,214000806013508,1,214000806010006,1,81
|
03804523B13A401BAE040
|
|
+CDTXC: 658,0
|
|
+CTXG: 658,3,0,0,1,214000806010002
|
|
+CDTXC: 658,0
|
|
+CTSDSR: 12,214000806014801,1,214000806010006,1,81
|
038045B3B15D401BCCF30
|
|
+CTSDSR: 12,214000806013343,1,214000806010006,1,81
|
03804283B143701BD00D0
|
|
+CTSDSR: 12,214000806013314,1,214000806010006,1,81
|
038045C3B14C001BB7D40
|
|
+CTXG: 658,3,0,0,1,214000806013414
|
|
+CTSDSR: 12,214000806013312,1,214000806010006,1,81
|
038045F3B14C901BB7D40
|
|
+CTSDSR: 12,214000806013509,1,214000806010006,1,81
|
03804613B13A001BAE350
|
|
+CDTXC: 658,0
|
|
+CTSDSR: 12,214000806013411,1,214000806010006,1,81
|
03804643B121501BD3640
|
|
+CTSDSR: 12,214000806013503,1,214000806010006,1,81
|
03804633B13BC01BD5D50
|
|
+CTXG: 658,3,0,0,1,214000806010002
|
|
+CTSDSR: 12,214000806013801,1,214000806010006,1,81
|
03804653B11B101BC4F40
|
|
+CTSDSR: 12,214000806011105,1,214000806010006,1,81
|
03804663B14B601BB9040
|
|
|
*/
|
|
}
|