Esempio n. 1
0
        static void Main(string[] args)
        {
            NetworkUDP myUDPinterface;
            TextWriter logFile;
            Object     lockFileLog    = new object();
            Object     lockInputState = new object();

            if (args.Length != 3)
            {
                Console.WriteLine("Please provide (1) the address of the multisim engine, (2) the name of the XML configuration file, (3) the name of the log file");
                Console.WriteLine("E.g: MSIMAutomate 127.0.0.1 TSW_config.xml log.txt");
                return;
            }
            logFile = new StreamWriter(args[2], true);
            XMLReader     myReader         = new XMLReader(args[1]);
            string        IPDst            = args[0];
            FSFB2Node     myFSFB2Node      = new FSFB2Node();
            FSFB2DataFlow myFSFB2_DataFlow = new FSFB2DataFlow();

            myFSFB2Node.NameHost = myReader.ZC_NAME;
            if (myFSFB2Node.InitListNotes() != ERRORS.NO_ERROR)
            {
                string[] listOfNodes = myFSFB2Node.getListNodes();
            }
            if (myFSFB2_DataFlow.InitFSFB2DataFlow(myReader.SIO_NAME, myFSFB2Node) == ERRORS.NO_ERROR)
            {
                Console.WriteLine("FSFB2 data structure initialised");
            }
            else
            {
                Console.WriteLine("Error encountered while attempting to initialised {0} FSFB2 data structure", myFSFB2Node.NameHost);
                return;
            }

            myUDPinterface = new NetworkUDP();
            List <string> inputList = new List <string>();

            foreach (TrkObject trkObj in myReader.trkObjectList)
            {
                foreach (TrkInterface trkInt in trkObj.listTrkInterface)
                {
                    inputList.Add(trkInt.inputId);
                }
            }
            string[] inputArray = inputList.ToArray();

            myUDPinterface.InitUDP(IPDst, myFSFB2_DataFlow.GetIndex(inputArray, "RX"), myReader.SrcAddr, myReader.DstAddr, ref lockInputState);
            Automata.InitAutomata(myReader, myUDPinterface, myFSFB2_DataFlow, inputArray, logFile, ref lockInputState, version);
        }
Esempio n. 2
0
        public static void ComputeStatus(object source, ElapsedEventArgs e)
        {
            List <string> listOutputSet = new List <string>();

            sizeTX = myFSFB2_DataFlow.GetLength("TX");

            currentTime += cycleTime;
            lock (lockInputState) {
                foreach (TrkObject TrkObj in automataInput.trkObjectList)
                {
                    int localTime = currentTime / 1000 % TrkObj.period;
                    foreach (TrkInterface TrkInt in TrkObj.listTrkInterface)
                    {
                        if ((localTime >= TrkInt.timeOperate) && (localTime < TrkInt.timeOperate + commandDuration))
                        {
                            if (TrkInt.command == false)
                            {
                                logFile.WriteLine(DateTime.Now + "::" + TrkInt.outputId + ": Set");
                            }
                            TrkInt.command = true; listOutputSet.Add(TrkInt.outputId);
                        }
                        else if (((localTime >= TrkInt.timeOperate + commandDuration) || (localTime < TrkInt.timeOperate)) && (TrkInt.command == true))
                        {
                            TrkInt.command = false; logFile.WriteLine(DateTime.Now + "::" + TrkInt.outputId + ": UnSet");
                        }
                    }
                }
                if (listOutputSet.Count > 0)
                {
                    UDPinterface.SendMessage(sizeTX, myFSFB2_DataFlow.GetIndex(listOutputSet.ToArray(), "TX"));
                }
                else
                {
                    UDPinterface.SendMessage(sizeTX, new int[0]);
                }
                Display(listOutputSet, currentTime);
            }
        }
Esempio n. 3
0
        static int Main(string[] args)
        {
            IntPtr myPcap; // pointer on Pcap
            IntPtr pStr;   // pointer on char

            byte[]    myBSD;
            const int BSD_offset   = 0x4E; // Offset to the BSD start (from the start of the IP Packet)
            const int DstID_offset = 0x3E; // Offset to the dest_ID (from the start of the IP Packet)

            int[] bitMask = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };

            string variable = "MEF_06_T";

            if (args.Length < 3)
            {
                System.Console.WriteLine(@"The arguments shall be [1] '*.pcapng' [2] the name of the host and [3] the name of the SIO");
                return(1);
            }
            FSFB2Node     myFSFB2Node      = new FSFB2Node();
            FSFB2DataFlow myFSFB2_DataFlow = new FSFB2DataFlow();

            myFSFB2Node.NameHost = args[1];
            if (myFSFB2Node.InitListNotes() != ERRORS.NO_ERROR)
            {
                string[] listOfNodes = myFSFB2Node.getListNodes();
            }
            if (myFSFB2_DataFlow.InitFSFB2DataFlow(args[2], myFSFB2Node) == ERRORS.NO_ERROR)
            {
                Console.WriteLine("FSFB2 data structure initialised");
            }
            else
            {
                Console.WriteLine("Error encountered while attempting to initialised {0} FSFB2 data structure", myFSFB2Node.NameHost);
                return(-1);
            }

            pStr   = IntPtr.Zero; // Initialise pStr to NULL
            myPcap = LibCapNg.MngConstruct(args[0]);
            Console.WriteLine("Version of the LibPcapNGDLL is {0}", getVersion(myPcap, pStr));
            if (LibCapNg.MngLoad(myPcap) == false)
            {
                return(-5);
            }
            var parsePcapNgReturnCode = (LibCapNg.MngParsePcapNG(myPcap, myFSFB2_DataFlow.IPAddressRed, "*", 20000, 20000, 0, 0));

            if (parsePcapNgReturnCode != 0)
            {
                Console.WriteLine("Error during parsing of the pCapNg file"); return(parsePcapNgReturnCode);
            }

            if (LibCapNg.MngGetFilteredPacketNumber(myPcap) != 0)
            {
                int    offset          = myFSFB2_DataFlow.GetIndex(variable, "RX");
                int    BitOffset       = offset % 8;
                int    ByteOffset      = (int)offset / 8;
                string DstNodeID_BCtmp = Convert.ToString((UInt16)(0 - myFSFB2_DataFlow.Subnet), 16);    // Compute the subnet
                string DstNodeID_BC    = DstNodeID_BCtmp.Substring(2) + DstNodeID_BCtmp.Substring(0, 2); // Change it to correct endianness

                myBSD = getFirstPacket(myPcap, ref pStr);
                string DstNodeID_BSD = Convert.ToString(myBSD[DstID_offset], 16) + Convert.ToString(myBSD[DstID_offset + 1], 16);

                if (DstNodeID_BSD == DstNodeID_BC)
                {
                    Console.WriteLine("{0} - {1} : {2}", getTimeStamp(myPcap), variable, myBSD[BSD_offset + ByteOffset] & bitMask[BitOffset]);
                }
                while (myBSD != null)
                {
                    myBSD = getNextPacket(myPcap, ref pStr);
                    if (myBSD != null)
                    {
                        DstNodeID_BSD = Convert.ToString(myBSD[DstID_offset], 16) + Convert.ToString(myBSD[DstID_offset + 1], 16);
                        if (DstNodeID_BSD == DstNodeID_BC)
                        {
                            Console.WriteLine("{0} - {1} : {2}", getTimeStamp(myPcap), variable, myBSD[BSD_offset + ByteOffset] & bitMask[BitOffset]);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No packet detected");
            }
            LibCapNg.MngDispose(myPcap);
            Console.ReadKey();
            return(0);
        }