public static Pacchetto RiceviPacchetto(EspBoard board) { Socket socket = board.getSocket(); if (!socket.Connected) { throw new Exception("Il socket non è connesso"); } byte[] mac_byte = new byte[6]; byte[] byte_ricevuti = new byte[512]; bool global = false; board.receiveBytes(mac_byte, 6); //Controlla che sia un mac reale if (CntrlGlobal(mac_byte)) { global = true; } PhysicalAddress mac = new PhysicalAddress(mac_byte); board.receiveBytes(byte_ricevuti, 2); short rssi = BitConverter.ToInt16(byte_ricevuti, 0); rssi = IPAddress.NetworkToHostOrder(rssi); board.receiveBytes(byte_ricevuti, 2); short lunghezza_ssid = BitConverter.ToInt16(byte_ricevuti, 0); lunghezza_ssid = IPAddress.NetworkToHostOrder(lunghezza_ssid); if (lunghezza_ssid < 0 || lunghezza_ssid > 32) { System.Diagnostics.Debug.WriteLine("Errore critico: la lunghezza del ssid è errata"); socket.Close(); throw new Exception("Lunghezza SSID non valida: " + lunghezza_ssid); } string ssid = ""; Debug.Assert(lunghezza_ssid >= 0); if (lunghezza_ssid > 0) { board.receiveBytes(byte_ricevuti, lunghezza_ssid); ssid = System.Text.Encoding.ASCII.GetString(byte_ricevuti, 0, lunghezza_ssid > 0 ? lunghezza_ssid : 0); } board.receiveBytes(byte_ricevuti, 4); int timestamp = BitConverter.ToInt32(byte_ricevuti, 0); timestamp = IPAddress.NetworkToHostOrder(timestamp); board.receiveBytes(byte_ricevuti, 4); string checksum = BitConverter.ToString(byte_ricevuti, 0, LUNGHEZZA_CHECKSUM).Replace("-", ""); Pacchetto pacchetto = new Pacchetto(mac, rssi, ssid, timestamp, checksum, board.getBoardID(), global); return(pacchetto); }
public void ConsoleStatusBoard(string infoTxt, EspBoard board) { Console.WriteLine(infoTxt); foreach (var pin in board.Pins) { Console.Write($"{board.Pins.IndexOf(pin)} => {pin.State}\n "); } }