private void SendComplete(uint send_size) { var next_data = (byte[])null; if (send_data_.Length > send_size) { send_data_ = ClassUtil.CloneCopy(send_data_, (int)send_size); next_data = ClassUtil.CloneCopy(send_data_, (int)send_size, int.MaxValue); } /* 送信が完了したデータのみを通知 */ NotifySendComplete("", "", "", send_data_); /* 未送信データを送信データにセット */ send_data_ = next_data; /* 送信遅延を設定 */ send_wait_time_ = (uint)((send_data_ != null) ? (prop_.SendByteWaitTimer.Value) : (prop_.SendPacketWaitTimer.Value)); if (send_wait_time_ > 0) { send_wait_timer_.Restart(); } }
private void SendTaskComplete(IAsyncResult ar) { if (!debug_flag) { var i = 0; } try { if (ar.AsyncState is System.Net.Sockets.UdpClient udp_client) { /* 送信処理完了 */ var send_complete_size = udp_client.EndSend(ar); var send_complete_data = send_data_; if (send_complete_size >= send_data_.Length) { /* 要求した送信データの全送信完了 */ send_data_ = null; } else { /* 要求した送信データの一部のみ送信完了 */ send_complete_data = ClassUtil.CloneCopy(send_data_, send_complete_size); send_data_ = ClassUtil.CloneCopy(send_data_, send_complete_size, send_data_.Length); } /* 送信完了通知(バッファへのセットアップが完了したときに通知する場合) */ // NotifySendComplete("", local_ep_text_, remote_ep_text_, send_complete_data); } } catch { } debug_flag = false; send_task_busy_ = false; }
private void DataOutputExec() { var read_size = 0; while ((!play_complete_) && (read_size < sampling_buffer_.Length)) { read_size += resampler_.Read(sampling_buffer_, read_size, sampling_buffer_.Length - read_size); /* データバッファが一杯にならないときは最初から読み込む */ if (read_size < sampling_buffer_.Length) { if ((devp_.RepeatCount.Value == 0) || ((repeat_count_ + 1) < devp_.RepeatCount.Value)) { /* 繰り返し設定が有効かつ繰り返しが可能のとき */ reader_.Position = 0; repeat_count_++; } else { /* 再生終了 */ play_complete_ = true; } } } if (read_size > 0) { /* データ出力 */ NotifyRecvComplete( "", "", "", (read_size < sampling_buffer_.Length) ? (ClassUtil.CloneCopy(sampling_buffer_, 0, read_size)) : (sampling_buffer_)); } }
protected byte[] GetSendData() { /* 送信データ準備 */ LoadSendBuffer(); lock (send_data_sync_) { /* 送信データが存在しないときは終了 */ if (send_data_busy_ == null) { return(null); } var send_data = (byte[])null; if (send_data_offset_ == 0) { /* 送信バッファを全てセットするのでオブジェクトをそのまま流用 */ send_data = send_data_busy_; } else { /* 送信バッファの途中から適用するのでバッファを用意 */ send_data = ClassUtil.CloneCopy(send_data_busy_, send_data_offset_, send_data_busy_.Length); } /* 送信バッファをクリア */ send_data_busy_ = null; send_data_offset_ = 0; DebugManager.MessageOut(DebugMessageSender.Device, DebugMessageType.SendEvent, "DeviceInstance.GetSendData"); return(send_data); } }
public byte[] GetBytes() { if (data_buffer_.Length == data_size_) { return(data_buffer_); } else { return(ClassUtil.CloneCopy(data_buffer_, data_size_)); } }
private void RecvComplete(byte[] recv_data, uint recv_size) { /* 受信バッファの空きを詰める */ if (recv_data.Length > recv_size) { recv_data = ClassUtil.CloneCopy(recv_data, (int)recv_size); } /* 受信したデータを通知 */ NotifyRecvComplete("", "", "", recv_data); /* 受信ホールドタイマー */ if (prop_.RecvHoldTimer.Value > 0) { recv_hold_timer_.Restart(); } }
private void RecvTaskComplete(IAsyncResult ar) { try { if (ar.AsyncState is System.Net.Sockets.TcpClient tcp_client) { /* 受信完了 */ var recv_size = tcp_client.GetStream().EndRead(ar); if (recv_size > 0) { /* 受信完了通知 */ NotifyClientRecvComplete(ClassUtil.CloneCopy(recv_data_, recv_size)); } else { /* 切断イベント */ Dispose(); } } } catch { } }
private void Parse(byte[] data, bool little_endian) { using (var reader = new BinaryReader(new MemoryStream(data))) { /* * typedef struct * { * USHORT headerLen; // This header length * UINT64 irpId; // I/O Request packet ID * USBD_STATUS status; // USB status code * (on return from host controller) * USHORT function; // URB Function * UCHAR info; // I/O Request info * * USHORT bus; // bus (RootHub) number * USHORT device; // device address * UCHAR endpoint; // endpoint number and transfer direction * UCHAR transfer; // transfer type * * UINT32 dataLength;/* Data length * } USBPCAP_BUFFER_PACKET_HEADER, *PUSBPCAP_BUFFER_PACKET_HEADER; */ var headerLen_raw = reader.ReadBytes(2); var irpId_raw = reader.ReadBytes(8); var status_raw = reader.ReadBytes(4); var function_raw = reader.ReadBytes(2); var info_raw = reader.ReadBytes(1); var bus_raw = reader.ReadBytes(2); var device_raw = reader.ReadBytes(2); var endpoint_raw = reader.ReadBytes(1); var transfer_raw = reader.ReadBytes(1); var dataLength_raw = reader.ReadBytes(4); if (little_endian != BitConverter.IsLittleEndian) { headerLen_raw = headerLen_raw.Reverse().ToArray(); irpId_raw = irpId_raw.Reverse().ToArray(); status_raw = status_raw.Reverse().ToArray(); function_raw = function_raw.Reverse().ToArray(); info_raw = info_raw.Reverse().ToArray(); bus_raw = bus_raw.Reverse().ToArray(); device_raw = device_raw.Reverse().ToArray(); endpoint_raw = endpoint_raw.Reverse().ToArray(); transfer_raw = transfer_raw.Reverse().ToArray(); dataLength_raw = dataLength_raw.Reverse().ToArray(); } PacketHeader = new USBPCAP_BUFFER_PACKET_HEADER(); PacketHeader.headerLen = BitConverter.ToUInt16(headerLen_raw, 0); PacketHeader.irpId = BitConverter.ToUInt64(irpId_raw, 0); PacketHeader.status = BitConverter.ToUInt32(status_raw, 0); PacketHeader.function = BitConverter.ToUInt16(function_raw, 0); PacketHeader.info = info_raw[0]; PacketHeader.bus = BitConverter.ToUInt16(bus_raw, 0); PacketHeader.device = BitConverter.ToUInt16(device_raw, 0); PacketHeader.endpoint = endpoint_raw[0]; PacketHeader.transfer = (USBPCAP_TRANSFER)transfer_raw[0]; PacketHeader.dataLength = BitConverter.ToUInt32(dataLength_raw, 0); Payload = ClassUtil.CloneCopy(data, PacketHeader.headerLen, data.Length - PacketHeader.headerLen); switch (PacketHeader.transfer) { case USBPCAP_TRANSFER.USBPCAP_TRANSFER_ISOCHRONOUS: ParseIsochronousHeader(reader, little_endian); break; case USBPCAP_TRANSFER.USBPCAP_TRANSFER_CONTROL: ParseControlHeader(reader, little_endian); break; } } }
private void OnWaveIn_DataAvailable(object sender, WaveInEventArgs e) { NotifyRecvComplete("", "", "", ClassUtil.CloneCopy(e.Buffer)); }