public void Test_packFileInfo() { byte[] test = new byte[] { 0x03, 0x00, 0x00, 0x00 }; RemoteFile.File file1 = new RemoteFile.File(); file1.name = "test.txt"; file1.length = 100; file1.address = 10000; List <byte> data = RemoteFileUtil.packFileInfo(file1, "<"); Assert.AreEqual(data.Count, RemoteFile.Constants.RMF_FILEINFO_BASE_LEN + file1.name.Length + 1); // +1 null termination Assert.IsTrue(data.GetRange(0, 4).SequenceEqual(new List <byte> { 0x03, 0x00, 0x00, 0x00 })); Assert.IsTrue(data.GetRange(4, 4).SequenceEqual(new List <byte> { 0x10, 0x27, 0x00, 0x00 })); Assert.IsTrue(data.GetRange(8, 4).SequenceEqual(new List <byte> { 0x64, 0x00, 0x00, 0x00 })); Assert.IsTrue(data.GetRange(12, 4).SequenceEqual(new List <byte> { 0x00, 0x00, 0x00, 0x00 })); foreach (byte b in data.GetRange(16, 32)) { Assert.IsTrue(b == 0); } byte[] bname = data.GetRange(48, data.Count - 48 - 1).ToArray(); // -1 for null termination string fileName = System.Text.Encoding.ASCII.GetString(bname); Assert.AreEqual("test.txt", fileName); Assert.IsTrue(data[data.Count - 1] == 0); }
protected override void processMessage(Msg msg) { if (msg.msgType == RemoteFile.Constants.RMF_MSG_CONNECT) { throw new System.ArgumentException("Not applicable for c# version (handled in onConnected)"); } else if (msg.msgType == RemoteFile.Constants.RMF_MSG_FILEINFO) { Apx.File file = (Apx.File)msg.msgData3; Console.WriteLine("processMessage, Name of file: " + file.name); List <byte> data = RemoteFileUtil.packHeader(RemoteFile.Constants.RMF_CMD_START_ADDR, false); List <byte> payload = RemoteFileUtil.packFileInfo(file, "<"); data.AddRange(payload); if (transmitHandler != null) { transmitHandler.send(data); } } else if (msg.msgType == RemoteFile.Constants.RMF_MSG_WRITE_DATA) { uint address = msg.msgData1; List <byte> data = RemoteFileUtil.packHeader(address); List <byte> payload = (List <byte>)msg.msgData3; data.AddRange(payload); if (transmitHandler != null) { transmitHandler.send(data); } } else if (msg.msgType == RemoteFile.Constants.RMF_MSG_FILEOPEN) { List <byte> data = RemoteFileUtil.packHeader(RemoteFile.Constants.RMF_CMD_START_ADDR); List <byte> payload = RemoteFileUtil.packFileOpen(msg.msgData1); data.AddRange(payload); if (transmitHandler != null) { transmitHandler.send(data); } } else { throw new System.ArgumentException("Unknown msgType"); } }