Esempio n. 1
0
 protected override void _processCmd(List <byte> data)
 {
     if (data.Count >= 4)
     {
         uint cmd = BitConverter.ToUInt32(data.GetRange(0, 4).ToArray(), 0);
         if (cmd == RemoteFile.Constants.RMF_CMD_FILE_INFO)
         {
             RemoteFile.File remoteFile = RemoteFileUtil.unPackFileInfo(data);
             for (int i = 0; i < requestedFiles.Count; i++)
             {
                 if (requestedFiles[i].name == remoteFile.name)
                 {
                     requestedFiles[i].address    = remoteFile.address;
                     requestedFiles[i].fileType   = remoteFile.fileType;
                     requestedFiles[i].digestType = remoteFile.digestType;
                     requestedFiles[i].digestData = remoteFile.digestData;
                     requestedFiles[i].open();
                     remoteFileMap.insert(requestedFiles[i]);
                     Msg msg = new Msg(RemoteFile.Constants.RMF_MSG_FILEOPEN, 0, 0, requestedFiles[i].address);
                     requestedFiles.RemoveAt(i);
                     msgQueue.Add(msg);
                 }
                 else
                 {
                     remoteFileMap.insert(remoteFile);
                 }
             }
         }
         else if (cmd == RemoteFile.Constants.RMF_CMD_FILE_OPEN)
         {
             uint address = RemoteFileUtil.unPackFileOpen(data, "<");
             Console.WriteLine("received open command, address: " + address);
             Apx.File file = localFileMap.findByAddress(address);
             if (file != null)
             {
                 Console.WriteLine("received open command, name: " + file.name);
                 file.open();
                 List <byte> fileContent = file.read(0, (int)file.length);
                 if (fileContent.Count > 0)
                 {
                     Msg msg = new Msg(RemoteFile.Constants.RMF_MSG_WRITE_DATA, file.address, 0, fileContent);
                     msgQueue.Add(msg);
                 }
             }
         }
         else if (cmd == RemoteFile.Constants.RMF_CMD_FILE_CLOSE)
         {
             throw new NotImplementedException();
         }
         else
         {
             throw new ArgumentException("Unknown command, cannot process");
         }
     }
     else
     {
         throw new ArgumentException("too short command to proccess");
     }
 }
Esempio n. 2
0
        protected override void _processFileWrite(uint address, bool more_bit, List <byte> data)
        {
            File remoteFile = remoteFileMap.findByAddress(address);

            if ((remoteFile != null) && (remoteFile.isOpen == true))
            {
                int offset = (int)address - (int)remoteFile.address;
                if ((offset >= 0) && (offset + data.Count <= remoteFile.length))
                {
                    remoteFile.write((uint)offset, data, more_bit);
                }
                else
                {
                    throw new ArgumentException("_processFileWrite couldn't write (outside of memory)");
                }
            }
            else
            {
                Console.WriteLine("_processFileWrite: Nothing written");
            }
        }