/// <summary> /// Send a queued code to the firmware /// </summary> /// <param name="queuedCode">Code to send</param> /// <param name="codeLength">Length of the binary code in bytes</param> /// <returns>Whether the code could be processed</returns> /// <remarks>The corresponding Channel is locked when this is called</remarks> public static bool BufferCode(QueuedCode queuedCode, out int codeLength) { codeLength = Consts.BufferedCodeHeaderSize + DataTransfer.GetCodeSize(queuedCode.Code); if (_bufferSpace > codeLength && _channels[queuedCode.Code.Channel].BytesBuffered + codeLength <= Settings.MaxBufferSpacePerChannel && DataTransfer.WriteCode(queuedCode.Code)) { _bytesReserved += codeLength; _bufferSpace -= codeLength; queuedCode.BinarySize = codeLength; return(true); } return(false); }
/// <summary> /// Send a queued code to the firmware /// </summary> /// <param name="queuedCode">Code to send</param> /// <param name="codeLength">Length of the binary code in bytes</param> /// <returns>Whether the code could be processed</returns> /// <remarks>The corresponding Channel is locked when this is called</remarks> public static bool BufferCode(QueuedCode queuedCode, out int codeLength) { codeLength = Consts.BufferedCodeHeaderSize + DataTransfer.GetCodeSize(queuedCode.Code); if (_bufferSpace > codeLength && _channels[queuedCode.Code.Channel].BytesBuffered + codeLength <= Settings.MaxBufferSpacePerChannel && DataTransfer.WriteCode(queuedCode.Code)) { _bytesReserved += codeLength; _bufferSpace -= codeLength; queuedCode.BinarySize = codeLength; Console.WriteLine($"[info] Sent {queuedCode.Code}, remaining space {Settings.MaxBufferSpacePerChannel - _channels[queuedCode.Code.Channel].BytesBuffered - codeLength} ({_bufferSpace} total), needed {codeLength}"); return(true); } return(false); }
/// <summary> /// Send a queued code to the firmware /// </summary> /// <param name="queuedCode">Code to send</param> /// <returns>Whether the code could be processed</returns> public static bool BufferCode(QueuedCode queuedCode) { try { int codeLength = Communication.Consts.BufferedCodeHeaderSize + DataTransfer.GetCodeSize(queuedCode.Code); if (_bufferSpace > codeLength && DataTransfer.WriteCode(queuedCode.Code)) { Console.WriteLine($"[info] Sent {queuedCode.Code}, remaining space {_bufferSpace}, need {codeLength}"); _bytesReserved += codeLength; _bufferSpace -= codeLength; Channels[queuedCode.Code.Channel].BufferedCodes.Add(queuedCode); return(true); } } catch (Exception e) { queuedCode.SetException(e); return(true); } return(false); }