开发者

Program not capturing

I have a program running as an alerting system in my station. I am brand new to Java and learning as I go. Anyway the program compiles and runs but does not capture any of the packets. Im hoping you all can give me a little input on what I am missing. Thanks in advance.

Listener

package prealert;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import jpcap.JpcapCaptor;
import jpcap.NetworkInterface;

public class Listener {

    private NetworkInterface[] devices;
    private NetworkInterface deviceName;
    private Reciever Reciever;
    private JpcapCaptor jpcap;
    public static Logger log;


    public Listener() {
        PropertyConfigurator.configure("log4j.properties");
        log = Logger.getRootLogger();
        log.debug("Log4j has been initialized");
        devices = JpcapCaptor.getDeviceList();
        for (int i = 0; i < devices.length; i++) {
            log.info(devices[i].description);
        }
        deviceName = devices[1];
        Reciever = new Reciever();
        try {
            jpcap = JpcapCaptor.openDevice(deviceName, 2000, true, 100);
        } catch (Exception e) {
            log.error("Error with JPcapCreation", e);
        }
        Reciever.jpcap = jpcap;
        Reciever.start();
        new SetBoard(SetBoard.DEFAULT).start();
    }

    public static void main(String args[]) {
        try {
            Listener listener = new Listener();
        } catch (Exception e) {
            log.error("ERROR IN THE MAIN METHOD OF LISTENER!", e);
        }
    }
}

Receiver

package prealert;

import jpcap.JpcapCaptor;
import jpcap.PacketReceiver;
import jpcap.packet.*;
import java.util.HashMap;
import java.util.Map;

import java.io.IOException;
import java.nio.charset.Charset;

public class Reciever extends Thread implements PacketReceiver {

    public JpcapCaptor jpcap;
    private int sign = 0;
    private long lastHeaderTime;

    private enum PacketPart {ID, DATA, OTHER};

    public static final int MEDIC = 1;
    public static final int AMBO = 2;
    public static final int ENGINE = 3;
    public static final int BoxAlarm = 4;
    public static final int StreetAlarm = 5;
    public static final int FIRSTDUE = 6;
    public static final int HAZMAT = 7;

    private Map<String, PrintOut> calls = new HashMap<String, PrintOut>();
    private PrintOut recentPrintOut;

    public void receivePacket(Packet packet) {

        if ((((IPPacket) packet).dst_ip.toString().equals("172.20.XX.XXX")) || (((IPPacket) packet).src_ip.toString().equals("/172.20.XX.XXX"))) {

            String data = new String(packet.data, Charset.forName("US-ASCII"));

            PacketPart part = whatPart(data);

            if (part == PacketPart.ID) {

                prealert.Listener.log.info(part + ": " + data);

                String id = getId(data);
                lastHeaderTime = packet.sec;

                if (calls.containsKey(id)) {
                    prealert.Listener.log.info("The ID: [" + id + "] was already in the calls, adding a new part");
                    recentPrintOut = calls.get(id);
                    recentPrintOut.addPart(data);
                } else {
                    //prealert.Listener.log.info("The ID: [" + id + "] is new, making a new printout");
                    recentPrintOut = new PrintOut(data);
                    calls.put(id, recentPrintOut);
                }
            }

            if ((part == PacketPart.DATA) && ((packet.sec - lastHeaderTime) < ((long) 3))) {

                prealert.Listener.log.info(part + ": " + data);

                recentPrintOut.addPart(data);

                if(data.contains("PrimeUnit:")){
                    /*
                    int tempd=data.indexOf("PrimeUnit:");
                    data=data.substring(0,tempd)+data.substring(tempd+13);
                    */
                    return;
                }


                if (recentPrintOut.alertFirstDue() == true) {
                    new AudioPlayer("house.wav").start();
                    sign = FIRSTDUE;
                }
                                if (recentPrintOut.alertboxalarm() == true) {
                    new AudioPlayer("enginebox.wav").start();
                    sign = BoxAlarm;
                }
                                if (recentPrintOut.alertstreet() == true) {
                    new AudioPlayer("enginestreet.wav").start();
                    sign = StreetAlarm;
                }
                if (recentPrintOut.alertFirstDue() != true) {
                    if (recentPrintOut.alertPE830() == true) {
                        new AudioPlayer("engine.wav").start();
                        sign = ENGINE;
                    }
                    if (recentPrintOut.alertMD830() == true) {
                        new AudioPlayer("medics.wav").start();
                        sign = MEDIC;
                    }
                    if (recentPrintOut.alertA830() == true) {
                        new AudioPlayer("ambo.wav").start();
                        sign = AMBO;
                    }
                    }
                if (sign != 0) {
                    int tempSign = sign;
                    try {
                        new SetBoard(recentPrintOut, tempSign).start();
                    } catch (Exception e) {
                        prealert.Listener.log.error("Exception while setboard: ", e);
  开发者_StackOverflow中文版                  }
                                        sign = 0;
                }
            }
        }
    }

    private static PacketPart whatPart(String data) {

        if (data.contains("Call #F")) {
            return PacketPart.ID;
        }
        if (data.contains("Darea:") || (data.contains("PrimeUnit:")) || (data.contains("Location:")) || (data.contains("Station:"))
                || (data.contains("CREATE")) || (data.contains("GeoLong:")) || (data.contains("ALIGEO")) || (data.contains("PROQA"))
                || (data.contains("Statement:")) || (data.contains("ENTRY")) || (data.contains("RSPMOD")) || (data.contains("Classify:"))
                || (data.contains("Dispatch")) || (data.contains(". 2.")) || (data.contains(". 6.")) || (data.contains("TIBNUM")) || (data.contains("Text:"))
                || (data.contains("DISP")) || (data.contains("NOMORE")) || (data.contains("INFO")) || (data.contains("PRIU")) || (data.contains("Name:"))
                || (data.contains("830")) || (data.contains("Sig4:")) || (data.contains("TypeDesc:")) || (data.contains("E911"))) {
            return PacketPart.DATA;
        }

        return PacketPart.OTHER;
    }

    public static String getId(String data) {
        int index = data.indexOf("Call #");
        return data.substring(index + 7, index + 16);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜