Ejemplo n.º 1
0
        public void Start(int port = 80, bool DhcpEnable = true, string ipAddress = "", string subnetMask = "", string gatewayAddress = "", string networkName = "NETDUINOPLUS")
        {
            Debug.Print("THANKS FOR USING INEX LIDAR TRIGGER");

            // Configure Network Settings
            NetworkConfig.NetworkConfig nc = new NetworkConfig.NetworkConfig(@"\SD\config.txt");
            nc.configNetworkSystem();
            this.Port = Int32.Parse(nc.getWebPort());

            // Start Lidar
            TriggerConfig.TriggerConfig tc = new TriggerConfig.TriggerConfig(@"\SD\trigger.txt");
            tc.configTrigger();
            _lidar_reader = new LidarReader.LidarReader(tc.SetNoVehicle, 10, 15);
            _lidar_reader.setDistanceValueLocation(_distanceValue);
            _lidar_reader.setTTLTriger(tc.TTLLength, tc.TTLTrigger);
            _lidar_reader.setIPTrigger(tc.CameraIP, tc.CameraPort, tc.CameraTrigger);
            _lidar_reader.setStopTrigger(tc.StopTime, tc.StopTrigger);
            _lidar_reader.setStatusLED(_statusLED);
            // _inport = _lidar_reader.getInterruptPort();


            // print the settings
            var interf = NetworkInterface.GetAllNetworkInterfaces()[0];

            Debug.Print("\n\n---------------------------");
            Debug.Print("Network is set up!\nIP: " + interf.IPAddress + " (DHCP: " + interf.IsDhcpEnabled + ")");
            Debug.Print("---------------------------");

            // StartLedThread(ledPort);
            ResponseListInitialize();
            SocketSetup();

            var webserverThread = new Thread(WaitingForRequest);

            webserverThread.Start();

            Debug.Print("\n\n---------------------------");
            Debug.Print("Webserver is now up and running");

            // start Lidar
            _lidar_reader.Start();
        }
            public void SaveJsonFile(Request e, JsonObject result)
            {
                string filePath = "\\SD\\config.txt";
                // string fileTmp = "\\SD\\tmp.txt";
                Hashtable reqOnSave = e.GetArguments;

                try
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    using (var fl = File.Create(filePath))
                    {
                        using (StreamWriter jsonFile = new StreamWriter(fl))
                        {
                            foreach (DictionaryEntry entry in reqOnSave)
                            {
                                var str = entry.Key.ToString() + "=" + entry.Value.ToString();
                                jsonFile.WriteLine(str);
                            }
                        }
                    }
                    Debug.Print("Network Saved");
                    // Configure Network Settings
                    NetworkConfig.NetworkConfig nc = new NetworkConfig.NetworkConfig(filePath);
                    nc.configNetworkSystem();
                }
                catch (Exception ex)
                {
                    // log error, turn status LED red and reboot
                    Debug.Print("Failed to save: " + ex.ToString());
                    // reboot
                    PowerState.RebootDevice(false);
                }
            }