<commit_before>package net.gcdc;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.util.Arrays;

import net.gcdc.geonetworking.Address;
import net.gcdc.geonetworking.BtpPacket;
import net.gcdc.geonetworking.BtpSocket;
import net.gcdc.geonetworking.Destination;
import net.gcdc.geonetworking.GeonetData;
import net.gcdc.geonetworking.GeonetStation;
import net.gcdc.geonetworking.LinkLayer;
import net.gcdc.geonetworking.LinkLayerUdpToEthernet;
import net.gcdc.geonetworking.LongPositionVector;
import net.gcdc.geonetworking.MacAddress;
import net.gcdc.geonetworking.Optional;
import net.gcdc.geonetworking.Position;
import net.gcdc.geonetworking.PositionProvider;
import net.gcdc.geonetworking.StationConfig;
import net.gcdc.geonetworking.TrafficClass;
import net.gcdc.geonetworking.UpperProtocolType;
import net.gcdc.geonetworking.gpsdclient.GpsdClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.Instant;

public class BtpUdpClient {

    private final static Logger logger = LoggerFactory.getLogger(BtpUdpClient.class);

    private final static String usage =
            "Usage: java -cp gn.jar BtpClient --local-udp2eth-port <local-port> --remote-udp2eth-address <udp-to-ethernet-remote-host-and-port> --local-data-port <port> --remote-data-address <host:port> --gpsd-server <host:port> --mac-address <xx:xx:xx:xx:xx:xx>" + "\n" +
    "BTP ports: 2001 (CAM), 2002 (DENM), 2003 (MAP), 2004 (SPAT).";

    public static void main(String[] args) throws IOException {
        if (args.length < 7) {
            System.err.println(usage);
            System.exit(1);
        }

        int localUdp2EthPort = 0;
        InetSocketAddress remoteUdp2EthAddress = null;
        int localDataPort = 0;
        InetSocketAddress remoteDataAddress = null;
        int localDataCamPort = 0;
        InetSocketAddress remoteDataCamAddress = null;
        int localDataIclcmPort = 0;
        InetSocketAddress remoteDataIclcmAddress = null;
        boolean hasEthernetHeader = false;
        PositionProvider positionProvider = null;
        short btpDestinationPort = (short) 2001;  // CAM
        hasEthernetHeader = true;
        MacAddress macAddress = new MacAddress(0);

        for (int arg = 0; arg < args.length; arg++) {
            if (args[arg].startsWith("--local-udp2eth-port")) {
                arg++;
                localUdp2EthPort = Integer.parseInt(args[arg]);
            } else if (args[arg].startsWith("--remote-udp2eth-address")) {
                arg++;
                String[] hostPort = args[arg].split(":");
                if (hostPort.length != 2) { System.err.println("Bad udp2eth host:port.\n" + usage); System.exit(1); }
                remoteUdp2EthAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--local-data-port")) {
                arg++;
                localDataPort = Integer.parseInt(args[arg]);
            } else if (args[arg].startsWith("--remote-data-address")) {
                arg++;
                String[] hostPort = args[arg].split(":");
                if (hostPort.length != 2) { System.err.println("Bad DATA host:port.\n" + usage); System.exit(1); }
                remoteDataAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--local-data-cam-port")) {
                arg++;
                localDataCamPort = Integer.parseInt(args[arg]);
            } else if (args[arg].startsWith("--remote-data-cam-address")) {
                arg++;
                String[] hostPort = args[arg].split(":");
                if (hostPort.length != 2) { System.err.println("Bad DATA host:port.\n" + usage); System.exit(1); }
                remoteDataCamAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--local-data-iclcm-port")) {
                arg++;
                localDataIclcmPort = Integer.parseInt(args[arg]);
            } else if (args[arg].startsWith("--remote-data-iclcm-address")) {
                arg++;
                String[] hostPort = args[arg].split(":");
                if (hostPort.length != 2) { System.err.println("Bad DATA host:port.\n" + usage); System.exit(1); }
                remoteDataIclcmAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--position")) {
                arg++;
                String[] latLon = args[arg].split(",");
                if (latLon.length != 2) { System.err.println("Bad lat,lon.\n" + usage); System.exit(1); }
                final double lat = Double.parseDouble(latLon[0]);
                final double lon = Double.parseDouble(latLon[1]);
                final boolean isPositionConfident = true;  // Let's say we know it.
                positionProvider = new PositionProvider() {
                    final Optional<Address> emptyAddress = Optional.empty();
                    @Override public LongPositionVector getLatestPosition() {
                        return new LongPositionVector(emptyAddress, Instant.now(),
                                new Position(lat, lon), isPositionConfident, 0, 0);
                    }
                };
            } else if (args[arg].startsWith("--gpsd-server")) {
                arg++;
                String[] hostPort = args[arg].split(":");
                if (hostPort.length != 2) { System.err.println("Bad gpsd host:port.\n" + usage); System.exit(1); }
                positionProvider = new GpsdClient(
                        new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]))).startClient();
            } else if (args[arg].startsWith("--mac-address")) {
                arg++;
                macAddress = new MacAddress(MacAddress.parseFromString(args[arg]));
            } else {
                throw new IllegalArgumentException("Unrecognized argument: " + args[arg]);
            }
        }

        runSenderAndReceiver(localUdp2EthPort, remoteUdp2EthAddress,
                localDataPort, remoteDataAddress,
                localDataCamPort, remoteDataCamAddress,
                localDataIclcmPort, remoteDataIclcmAddress,
                hasEthernetHeader, positionProvider, btpDestinationPort, macAddress);
    }
<commit_msg>Fixing squid: ForLoopCounterChangedCheck "for" loop stop conditions should be invariant 110 min TD.<commit_after>package net.gcdc;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.util.Arrays;

import net.gcdc.geonetworking.Address;
import net.gcdc.geonetworking.BtpPacket;
import net.gcdc.geonetworking.BtpSocket;
import net.gcdc.geonetworking.Destination;
import net.gcdc.geonetworking.GeonetData;
import net.gcdc.geonetworking.GeonetStation;
import net.gcdc.geonetworking.LinkLayer;
import net.gcdc.geonetworking.LinkLayerUdpToEthernet;
import net.gcdc.geonetworking.LongPositionVector;
import net.gcdc.geonetworking.MacAddress;
import net.gcdc.geonetworking.Optional;
import net.gcdc.geonetworking.Position;
import net.gcdc.geonetworking.PositionProvider;
import net.gcdc.geonetworking.StationConfig;
import net.gcdc.geonetworking.TrafficClass;
import net.gcdc.geonetworking.UpperProtocolType;
import net.gcdc.geonetworking.gpsdclient.GpsdClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.Instant;

public class BtpUdpClient {

    private final static Logger logger = LoggerFactory.getLogger(BtpUdpClient.class);

    private final static String usage =
            "Usage: java -cp gn.jar BtpClient --local-udp2eth-port <local-port> --remote-udp2eth-address <udp-to-ethernet-remote-host-and-port> --local-data-port <port> --remote-data-address <host:port> --gpsd-server <host:port> --mac-address <xx:xx:xx:xx:xx:xx>" + "\n" +
    "BTP ports: 2001 (CAM), 2002 (DENM), 2003 (MAP), 2004 (SPAT).";

    public static void main(String[] args) throws IOException {
        if (args.length < 7) {
            System.err.println(usage);
            System.exit(1);
        }

        int localUdp2EthPort = 0;
        InetSocketAddress remoteUdp2EthAddress = null;
        int localDataPort = 0;
        InetSocketAddress remoteDataAddress = null;
        int localDataCamPort = 0;
        InetSocketAddress remoteDataCamAddress = null;
        int localDataIclcmPort = 0;
        InetSocketAddress remoteDataIclcmAddress = null;
        boolean hasEthernetHeader = false;
        PositionProvider positionProvider = null;
        short btpDestinationPort = (short) 2001;  // CAM
        hasEthernetHeader = true;
        MacAddress macAddress = new MacAddress(0);

        for (int arg = 0; arg < args.length; arg += 2) {
            if (args[arg].startsWith("--local-udp2eth-port")) {
                localUdp2EthPort = Integer.parseInt(args[arg + 1]);
            } else if (args[arg].startsWith("--remote-udp2eth-address")) {
                String[] hostPort = args[arg + 1].split(":");
                if (hostPort.length != 2) { System.err.println("Bad udp2eth host:port.\n" + usage); System.exit(1); }
                remoteUdp2EthAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--local-data-port")) {
                localDataPort = Integer.parseInt(args[arg + 1]);
            } else if (args[arg].startsWith("--remote-data-address")) {
                String[] hostPort = args[arg + 1].split(":");
                if (hostPort.length != 2) { System.err.println("Bad DATA host:port.\n" + usage); System.exit(1); }
                remoteDataAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--local-data-cam-port")) {
                localDataCamPort = Integer.parseInt(args[arg + 1]);
            } else if (args[arg].startsWith("--remote-data-cam-address")) {
                String[] hostPort = args[arg + 1].split(":");
                if (hostPort.length != 2) { System.err.println("Bad DATA host:port.\n" + usage); System.exit(1); }
                remoteDataCamAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--local-data-iclcm-port")) {
                localDataIclcmPort = Integer.parseInt(args[arg + 1]);
            } else if (args[arg].startsWith("--remote-data-iclcm-address")) {
                String[] hostPort = args[arg + 1].split(":");
                if (hostPort.length != 2) { System.err.println("Bad DATA host:port.\n" + usage); System.exit(1); }
                remoteDataIclcmAddress = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));
            } else if (args[arg].startsWith("--position")) {
                String[] latLon = args[arg + 1].split(",");
                if (latLon.length != 2) { System.err.println("Bad lat,lon.\n" + usage); System.exit(1); }
                final double lat = Double.parseDouble(latLon[0]);
                final double lon = Double.parseDouble(latLon[1]);
                final boolean isPositionConfident = true;  // Let's say we know it.
                positionProvider = new PositionProvider() {
                    final Optional<Address> emptyAddress = Optional.empty();
                    @Override public LongPositionVector getLatestPosition() {
                        return new LongPositionVector(emptyAddress, Instant.now(),
                                new Position(lat, lon), isPositionConfident, 0, 0);
                    }
                };
            } else if (args[arg].startsWith("--gpsd-server")) {
                String[] hostPort = args[arg + 1].split(":");
                if (hostPort.length != 2) { System.err.println("Bad gpsd host:port.\n" + usage); System.exit(1); }
                positionProvider = new GpsdClient(
                        new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]))).startClient();
            } else if (args[arg].startsWith("--mac-address")) {
                macAddress = new MacAddress(MacAddress.parseFromString(args[arg + 1]));
            } else {
                throw new IllegalArgumentException("Unrecognized argument: " + args[arg]);
            }
        }

        runSenderAndReceiver(localUdp2EthPort, remoteUdp2EthAddress,
                localDataPort, remoteDataAddress,
                localDataCamPort, remoteDataCamAddress,
                localDataIclcmPort, remoteDataIclcmAddress,
                hasEthernetHeader, positionProvider, btpDestinationPort, macAddress);
    }

{'fraction_non_alphanumeric': 0.12781487808665942, 'fraction_numerical': 0.011570119583786303, 'mean_word_length': 2.554788849020149, 'pattern_counts': {'":': 10, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '368773', 'n_tokens_mistral': 3914, 'n_tokens_neox': 3755, 'n_words': 723}