示例#1
0
        private static void Init()
        {
            // WiFi //
            WiFi       = new WiFiClient(Defines.HOST_IP, Defines.HOST_PORT);
            WiFiThread = new Thread(WiFi.Run);
            WiFiThread.Start();

            // Roomba //
            roomba = new RoombaSerial(SerialPorts.COM1, Pins.GPIO_PIN_D4);

            // SDCard //
            SDCard = new Logger(Defines.LOG_FILENAME);

            // Session ID //
            int    sid         = GetRandomNumber();
            string SessionID   = sid.ToString("X4");
            string new_session = "--- NEW SESSION {" + SessionID + "} VERSION {" + VERSION + "}---";

            FifoBuffer.Push(new_session);
            SDCard.Log(new_session);

            // Pushbutton //
            PushButton              = new InterruptPort(Pins.ONBOARD_BTN, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            PushButton.OnInterrupt += new NativeEventHandler(OnPushButton);
        }
示例#2
0
        private void SendData()
        {
            if (FifoBuffer.Count() == 0)
            {
                TRACE("SendData", "Buffer empty, skipping update.");
                return;
            }

            TRACE("SendData", "Attempting connection... {" + HostAddress.ToString() + "}");
            Led.Write(true);

            try
            {
                Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sender.Connect(HostAddress);
                TRACE("SendData", "Connected.");

                while (FifoBuffer.Count() > 0)
                {
                    byte[] outgoing_msg = Encoding.UTF8.GetBytes(FifoBuffer.Pop());
                    byte[] incoming_msg = new byte[RX_BUFFER_LENGTH];

                    int txbytes = sender.Send(outgoing_msg);
                    int rxbytes = sender.Receive(incoming_msg);

                    // ADD: OK/ERROR HANDLING IF NEEDED...

                    TRACE("SendData", "Received: {" + new string(Encoding.UTF8.GetChars(incoming_msg)) + "}");
                    //TRACE("SendData", "Bytes sent: {" + txbytes.ToString() + "}. Bytes received: {" + rxbytes.ToString() + "}.");
                }

                sender.Close();
                TRACE("SendData", "Connection terminated.");
            }
            catch (SocketException s)
            {
                TRACE("SendData", "SocketException: could not connect to server {" + s.ToString() + "}.");
            }
            catch (Exception e)
            {
                TRACE("SendData", "Exception: " + e.ToString());
            }
            Led.Write(false);
        }
示例#3
0
        public static void Main()
        {
            Thread.Sleep(STARTUP_DELAY);

            TRACE("Main", "-- RoombaMapper v" + VERSION + "--");
            string sensors;

            Init();

            while (true)
            {
                Thread.Sleep(POLLING_PERIOD_MS);

                if (ProgramHalted)
                {
                    continue;
                }

                if (DriveAround)
                {
                    DriveAround = false;
                    roomba.DriveAround();
                }

                sensors = roomba.ReadSensors(RoombaSerial.SensorData.All);

                if (null == sensors)
                {
                    continue;
                }

                if (!FifoBuffer.Push(sensors))      // Log to Server
                {
                    TRACE("FifoBuffer.Push", "Buffer is Full");
                }


                if (!SDCard.Log(sensors, true))   // Log to Storage
                {
                    TRACE("Main", "Logging to SD card failed.");
                }
            }
        }