コード例 #1
0
        public void ProcessData(WMXMessage message)
        {
            if (message.Type == WMXMessage.MessageType.RxData) {
                string fileName = "";
                uint chunkNumber;
                int i;

                for(i = 0; i < 50; i++){
                    if (message.Data[i] == 0) {
                        // Found the null
                        fileName = Encoding.ASCII.GetString(message.Data, 0, i);
                        break;
                    }
                }
                if (fileName == "") {
                    // Something wrong
                    return;
                }

                i++; // Jump past the null terminator

                chunkNumber = BitConverter.ToUInt32(message.Data, i);
                if (chunkNumber > 3000) {
                    // Just some arbitrary limit. It's just a demo, afterall
                    return;
                }

                i+=4; // Jump past the chunk number

                string fullPath = Path.Combine(_saveLocation, fileName);

                fileMutex.WaitOne();
                try {
                    FileStream output;
                    if (!File.Exists(fullPath)) {
                        output = File.Create(fullPath);
                    } else {
                        output = File.OpenWrite(fullPath);
                    }

                    uint byteStart = chunkNumber * FileTransmitHandler.FileChunkSize;

                    if (!output.CanSeek) {
                        throw new Exception("Cannot receive file!");
                    }
                    output.Seek(byteStart, SeekOrigin.Begin);

                    output.Write(message.Data, i, message.Data.Length - i);

                    output.Flush();

                    output.Close();
                } finally {
                    fileMutex.ReleaseMutex();
                }
            }
        }
コード例 #2
0
 public void ProcessIncomingWMX(WMXMessage message)
 {
     switch (message.Type) {
         case WMXMessage.MessageType.RxData:
             // RX data is directed to the receive handler
             fileReceive.ProcessData(message);
             break;
         default:
             // All other data goes to the transmit handler
             if (fileTransfer != null) {
                 fileTransfer.addInboundMessage(message);
             }
             break;
     }
     incomingWMX.Add(message);
 }
コード例 #3
0
 public void sendWMX(WMXMessage wmxMessage)
 {
     if (shouldRun) {
         serialPort.Write(wmxMessage.Bytes, 0, wmxMessage.ByteCount);
     }
 }
コード例 #4
0
        public bool UpdateStatus(WMXMessage message)
        {
            switch (message.Type) {
                case WMXMessage.MessageType.OTAAck:
                    if (message.StatusSequence != WMXMessageSequence) {
                        // Not an update for this instance
                        break;
                    }
                    Status = OTAMessageStatus.OTAAcknowledged;
                    return true;
                case WMXMessage.MessageType.MessageStatus:
                    if (message.StatusSequence != WMXMessageSequence) {
                        // Not an update for this instance
                        break;
                    }
                    Status = OTAMessageHelpers.GetNewStatus(message.StatusValue, Status);
                    return true;
            }

            return false;
        }
コード例 #5
0
 public WMXMessage GetMessage(int destinationAddress)
 {
     WMXMessage message = new WMXMessage(0, destinationAddress, WMXMessage.MessageType.TxData, data);
     WMXMessageSequence = message.Sequence;
     return message;
 }
コード例 #6
0
        public bool UpdateStatus(WMXMessage message)
        {
            switch (message.Type){
                case WMXMessage.MessageType.CommandResponse:
                    string expectedResponse = parameter.ToUpperInvariant() + "=" + value.ToUpperInvariant();
                    if (message.ASCIIPayload.ToUpperInvariant().Trim() == expectedResponse) {
                        Status = OTAMessageStatus.OTAAcknowledged;
                        return true;
                    }
                    break;
                case WMXMessage.MessageType.MessageStatus:
                    if (message.StatusSequence != WMXMessageSequence) {
                        // Not an update for this instance
                        break;
                    }
                    Status = OTAMessageHelpers.GetNewStatus(message.StatusValue, Status);
                    return true;
            }

            return false;
        }
コード例 #7
0
 public WMXMessage GetMessage(int destinationAddress)
 {
     WMXMessage message = new WMXMessage(0, destinationAddress, WMXMessage.MessageType.Command, parameter + " " + value);
     WMXMessageSequence = message.Sequence;
     return message;
 }
コード例 #8
0
 public void addInboundMessage(WMXMessage message)
 {
     inboundWMXMutex.WaitOne();
     try {
         inboundWMX.Add(message);
     } finally {
         inboundWMXMutex.ReleaseMutex();
     }
 }