Commit df6a7c96 authored by garciay's avatar garciay
Browse files

Merge with latest C2C

parent 5f9025a4
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -93,6 +93,13 @@ public interface IGnssSupport {
   */
  public BigInteger getGpsTime();
  
  /**
   * Signals when the requested time in the running scenario is reached
   * @param time The requested time in msec.
   * @return TRUE on success, FALSE otherwise
   */
  public boolean awaitTimeInRunningScenario(AdapterPort notifier, int time);
  
  /**
   * Dispose object
   */
+20 −1
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
    //private static final byte AcGn6Response = 1;
    public static final byte AcGnssResponse = 2;
    public static final byte AcGnssDistanceCovered = 3;
    public static final byte AcSecResponse = 4;
    public static final byte AcGnssTimeReached = 4;
    public static final byte AcSecResponse = 5;

    /* GN Commands */
    private static final byte AcStartBeaconing = 0;
@@ -55,6 +56,7 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
    private static final byte AcAwaitDistanceToCover = 0x73;
    private static final byte AcChangeSpead = 0x74;
    private static final byte AcChangeHeading = 0x75;
    private static final byte AcAwaitTimeInRunningScenario = 0x76;

    /* Set the certificate to be used by the Test Adapter */
    private static final byte AcEnableSecurity = 0x7a;
@@ -171,6 +173,10 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
                            case AcChangeHeading:
//                                ChangeHeading(heading);
                                break;
                            case AcAwaitTimeInRunningScenario:
                                int time = ByteHelper.byteArrayToInt(data);
                                AwaitTimeInRunningScenario(time);
                                break;
                        }
                    }
                    else {
@@ -284,6 +290,18 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
        }).start();
    }

   private void AwaitTimeInRunningScenario(final int time) {
        new Thread(new Runnable() {
            @Override
            public void run() { 
                boolean result = GNSS.awaitTimeInRunningScenario(AdapterControlPort.this, time);
                byte[] response = {(byte)AcGnssResponse, (byte)(result?AcFalse:AcTrue)};
                setChanged();
                notifyObservers(new PortEvent(response, getPortName(), getComponentName()));
            }
        }).start();
    }
    
    private void ProcessAcEnableSecurity(final byte[] data) {
        new Thread(new Runnable() {
            @Override
@@ -310,6 +328,7 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
        }).start();
    }


    @Override
    public void dispose() {
        if (gnssScenarioSupport) {
+7 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ public class AcGnssPrimitive extends Union {
        case 0x75:
            primitive = "changeHeading";
            break;
        case 0x76:
            primitive = "timeInRunningScenario";
            break;
        }

        mainCodec.setHint(decodingHypothesis.getName(), primitive);
@@ -76,6 +79,10 @@ public class AcGnssPrimitive extends Union {
        else if(variant.equals("changeHeading")) {
            primitiveId = 0x75;
        }
        else if(variant.equals("timeInRunningScenario")) {
            primitiveId = 0x76;
            mainCodec.setHint("integerLen", "32");
        }
        buf.appendBytes(ByteHelper.intToByteArray(primitiveId, 1));
    }
}
+123 −3
Original line number Diff line number Diff line
@@ -46,12 +46,17 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.etsi.adapter.IGnssSupport;
import org.etsi.adapter.ITERequired;
import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper;
import org.etsi.its.adapter.ports.AdapterControlPort;
import org.etsi.its.adapter.ports.AdapterPort;
import org.etsi.its.adapter.ports.PortEvent;
import org.etsi.ttcn.tci.CharstringValue;
import org.etsi.ttcn.tci.Value;
import org.etsi.ttcn.tri.TriAddress;
import org.etsi.ttcn.tri.TriCommunicationTE;
import org.etsi.ttcn.tri.TriMessage;
import org.etsi.ttcn.tri.TriStatus;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -90,6 +95,50 @@ public class GnssRemoteControl implements IGnssSupport {
    }
    
    public static void main(String[] args) {
        
        TERFactory.setImpl(new ITERequired() {
            
            @Override
            public void logError(String errorMessage) {
                System.out.println(errorMessage);
            }
            
            @Override
            public void logDebug(String debugMessage) {
                System.out.println(debugMessage);
            }
            
            @Override
            public TriStatus getTriStatus(int statusCode, String message) {
                return null;
            }
            
            @Override
            public TriStatus getTriStatus(int statusCode) {
                return null;
            }
            
            @Override
            public TriMessage getTriMessage(byte[] message) {
                return null;
            }
            
            @Override
            public TriAddress getTriAddress(byte[] message) {
                return null;
            }
            
            @Override
            public Value getTaParameter(String param) {
                return null;
            }
            
            @Override
            public TriCommunicationTE getCommunicationTE() {
                return null;
            }
        });
        
        try {
            for (int i = 0; i < 1; i++) {
                GnssRemoteControl grc = GnssRemoteControl.getInstance();
@@ -99,6 +148,7 @@ public class GnssRemoteControl implements IGnssSupport {
//            grc.getScenarioStatus();
//            grc.getScenarioDuration();
                grc.startScenario();
                grc.awaitTimeInRunningScenario(new AdapterControlPort("test", "TestComp"), 60000);
//                grc.awaitDistanceToCover(new AdapterControlPort("test", "TestComp"), 200.0);
                grc.getGpsTime();
//            grc.getScenarioStatus();
@@ -195,7 +245,7 @@ public class GnssRemoteControl implements IGnssSupport {
                address = ((CharstringValue)TERFactory.getInstance().getTaParameter("TestSystemIpAddress")).getString();
            }
            catch (Throwable th) {
                address = "10.73.100.38";
                address = "10.73.100.28";
            }
        }
        catch (Throwable th) {
@@ -241,6 +291,7 @@ public class GnssRemoteControl implements IGnssSupport {
    }
    
    public boolean stopScenario() {
        stopReceiver();
        return 2==handleCommand("-,EN,1");
    }
    
@@ -338,6 +389,75 @@ public class GnssRemoteControl implements IGnssSupport {
        return result;
    }
    
    public boolean awaitTimeInRunningScenario(final AdapterPort commPort, final int time) {
        boolean result = false;
        try {
            final DatagramSocket udpReceiverSoc = new DatagramSocket(15660);
            udpReceiverSoc.setSoTimeout(100);
            
            synchronized (receiverRunning) {
                receiverRunning = true;
            }
            
            Thread receiver = 
            new Thread(new Runnable() {
                
                @Override
                public void run() {
                    boolean result = false;
                    DatagramPacket packet = new DatagramPacket(new byte[1500], 1500);
                    
                    while(isReceiverRunning()) {
                        try {
                            udpReceiverSoc.receive(packet);
                            TabularDecoder dec = new TabularDecoder(new BitArrayInputStream(packet.getData(), packet.getLength()<<3));
                            try {
                                int type = dec.decodeInteger(false, 32, Endianness.LITTLE_ENDIAN);
                                if (type==0) {
                                    int version = dec.decodeInteger(false, 32, Endianness.LITTLE_ENDIAN);
                                    int time_into_run = dec.decodeInteger(false, 32, Endianness.LITTLE_ENDIAN);
                                    
                                    if (debug) {
                                        TERFactory.getInstance().logDebug("Version         : " + version);
                                        TERFactory.getInstance().logDebug("Time(into run)  : " + time_into_run);
                                    }
                                    
                                    if (time_into_run>=(time*1000)/*in ms*/) {
                                        result = true;
                                        stopReceiver();
                                    }
                                }
                            } catch (TabularException e) {
                                e.printStackTrace();
                            }
                        } catch (SocketTimeoutException ste) {
                            //nothing received, ignore
                        } catch (IOException e) {
                            e.printStackTrace();
                            result = false;
                            stopReceiver();
                        }
                    }
                    udpReceiverSoc.close();
                    commPort.setChanged();
                    byte[] response = {(byte)AdapterControlPort.AcGnssTimeReached, (byte)(result?AdapterControlPort.AcFalse:AdapterControlPort.AcTrue)};
                    commPort.notifyObservers(new PortEvent(response, commPort.getPortName(), commPort.getComponentName()));
                }
            }, "AwaitTimeIntoRun");
            receiver.start();
//            try {
//                receiver.join();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        } catch (SocketException e) {
            e.printStackTrace();
            result = false;
        }
        
        return result;
    }
    
    public boolean changeSpeed(double speed) {
        return false;
    }
@@ -529,12 +649,12 @@ public class GnssRemoteControl implements IGnssSupport {
                    }
                    else if (localName.equals("error")) {
                        inError=false;
                        TERFactory.getInstance().logError("error: " + sb.toString());
                        TERFactory.getInstance().logDebug("error: " + sb.toString());
                        sb.setLength(0);
                    }
                    else if (localName.equals("fatal")) {
                        inFatal=false;
                        TERFactory.getInstance().logError("fatal: " + sb.toString());
                        TERFactory.getInstance().logDebug("fatal: " + sb.toString());
                        sb.setLength(0);
                    }
                    super.endElement(uri, localName, qName);
+4 −6
Original line number Diff line number Diff line
@@ -77,6 +77,10 @@ public class PluginAdapter implements ISAPlugin, PortPluginProvider, PluginIdent
		return new TriStatusImpl();
	}

	public TriStatus reInit() {
		return tearDown();
	}

	@Override
	public TriStatus triCall(TriComponentId componentId, TriPortId tsiPortId,
			TriAddress sutAddress, TriSignatureId signatureId,
@@ -205,10 +209,4 @@ public class PluginAdapter implements ISAPlugin, PortPluginProvider, PluginIdent
		return ta.triUnmapParam(compPortId, tsiPortId, paramList);
	}

	@Override
	public TriStatus reInit() {
		// TODO Auto-generated method stub
		return null;
	}

}
Loading