public static DataFrame FromBytes(Byte[] input) { var bytesList = new List<Byte> (input); var frame = new DataFrame (Convert.ToInt16 (bytesList [0])); bytesList.RemoveAt (0); //frame.Date = Convert.ToInt16(bytesList[0]); //bytesList.RemoveAt(0); frame.Timeout = Convert.ToInt16 (bytesList [0]); bytesList.RemoveAt (0); frame.Lng = Convert.ToInt16 (bytesList [0]); bytesList.RemoveAt (0); frame.Protocol = (Program.Protocols)Convert.ToInt16 (bytesList [0]); bytesList.RemoveAt (0); frame.Data = bytesList.ToArray (); bytesList.RemoveAt (0); Console.WriteLine (frame.ID); return frame; }
private void readFile() { byte[] readData; bool hasInsertedPacket; FileStream myFile = new FileStream (_sourceFile, FileMode.Open); if (myFile.CanRead) { BinaryReader fileReader = new BinaryReader (myFile); Console.WriteLine ("Reading file - Started"); if (!buffer.IsFull) { while (fileReader.PeekChar () != -1) { try { readData = fileReader.ReadBytes (PACKETSIZE); DataFrame frame = new DataFrame (this.GetNextPacketID); frame.Data = readData; frame.Lng = PACKETSIZE; frame.Protocol = Program.Protocols.Protocole1; frame.Timeout = Convert.ToByte (69); hasInsertedPacket = buffer.Push (frame); if (hasInsertedPacket) Console.WriteLine ("Set the following packet in the CircularBuffer: {0}", frame.ID); else Console.WriteLine ("Unable to set the following packet in the CircularBuffer: {0}, the buffer might be full?", frame.ID); this.sendPackets (); } catch (Exception e) { Console.WriteLine ("Error ! penis : {0}", e.Message); } } Console.WriteLine ("Reading file - Stopped (There is nothing more to read in the file)"); } else { // JP - SUBSCRIBE TO EVENT "NOT FULL ANYMORE" or w/e } } }