Exemple #1
0
        /// <summary>
        /// Gets a directory handle to a directory on the brick. Use with great care upon deleting!!
        /// </summary>
        /// <param name="brickDirectoryPath">The relative path, must start with ../ and end with /</param>
        /// <returns></returns>
        public static async Task <Directory> GetDirectory(string brickDirectoryPath)
        {
            brickDirectoryPath = Firmware.FileSystem.ToBrickDirectoryPath(brickDirectoryPath);
            if (brickDirectoryPath == ROOT_PATH)
            {
                return(new Directory(ROOT_PATH));
            }
            bool b = await MemoryMethods.Exists(Brick.Socket, brickDirectoryPath);

            if (b)
            {
                return(new Directory(brickDirectoryPath));
            }
            return(null);
        }
Exemple #2
0
 /// <summary>
 /// Gets memory information total and free.
 /// </summary>
 /// <returns></returns>
 public async Task <MemoryInfo> GetMemoryInfo()
 {
     return(await MemoryMethods.GetMemoryInfo(Brick.Socket));
 }
Exemple #3
0
        /// <summary>
        /// Connect the brick and start event monitor
        /// </summary>
        /// <returns></returns>
        public async Task <bool> Connect()
        {
            if (IsConnected)
            {
                throw new InvalidOperationException("brick is already connected");
            }

            switch (Options.Socket.Type)
            {
            case SocketType.Usb:
            {
                _socket = new Socket(new Sockets.UsbSocket());
                break;
            }

            case SocketType.Bluetooth:
            {
                _socket = new Socket(new Sockets.BlueToothSocket(Options.Socket.Address));
                break;
            }

            case SocketType.Network:
            {
                _socket = new Socket(new Sockets.NetworkSocket(Options.Socket.Address));
                break;
            }

            default: throw new NotImplementedException(nameof(Options.Socket.Type));
            }

            Logger.LogInformation($"Connecting to brick on {_socket.ConnectionInfo}");

            try
            {
                if (!_socket.IsConnected)
                {
                    await _socket.Connect();
                }

                //reset and stop all devices. Might be overkill but just to make sure nothing is running.
                await Stop();
                await Reset();

                Name = await Console.GetBrickName();

                //TODO Usb
                bool sdCardPresent = await MemoryMethods.Exists(Socket, BrickExplorer.SDCARD_PATH);

                if (sdCardPresent)
                {
                    SDCard = new SDCard();
                }


                if (Options.PowerUpSelfTest != null && Options.PowerUpSelfTest.Enabled)
                {
                    await PowerUpSelfTest();
                }
                else
                {
                    await InitializeDevices();
                }

                if (Options.EventMonitor.Enabled && IsConnected)
                {
                    Socket.StartEventMonitor(this);
                }
            }
            catch (Exception)
            {
                if (IsConnected)
                {
                    await _socket.Disconnect();
                }
            }

            if (IsConnected)
            {
                Logger.LogInformation("Connected to brick");
            }
            else
            {
                Logger.LogError($"Failed to connect to brick on {_socket.ConnectionInfo}");
            }

            return(IsConnected);
        }
Exemple #4
0
 /// <summary>
 /// Tests if path to file or folder exists on brick
 /// </summary>
 /// <param name="brickPath">The relative path, must start with ../</param>
 /// <returns><c>true</c> if exists otherwise <c>false</c></returns>
 public static async Task <bool> Exists(string brickPath)
 {
     return(await MemoryMethods.Exists(Brick.Socket, brickPath));
 }