public static void DecodeChannels(byte[] buf, int pos) { // номер среза // количество каналов // размер диапазона, всегда 1, кроме килогерцовых данных // каналы var packet_num = BitConverter.ToInt32(buf, pos + 0); var cur_channels_count = BitConverter.ToInt32(buf, pos + 4); if (cur_channels_count != SessionInfo.ChannelsNum) { throw new Exception("channel num mismatch"); } // var diap_dummy = BitConverter.ToInt32(buf, pos + 8); var data_arr = new short[cur_channels_count]; int data_pos = pos + 12; for (int i = 0; i < cur_channels_count; i++) { try { data_arr[i] = BitConverter.ToInt16(buf, data_pos + i * 2); } catch (Exception) { var s = pos + ": " + BitConverter.ToString(buf); File.AppendAllText("exception.log", s); throw; } } OnDataEvent?.Invoke(packet_num, data_arr); }
public static short[] EmulateAsync() { int packet_num = 0; while (true) { //data_arr[0] = (short)rnd.Next(-200, 200); //data_arr[0] = l[packet_num]; var data_arr = loaded_data[packet_num]; OnDataEvent?.Invoke(packet_num, data_arr); System.Threading.Thread.Sleep(1000 / Frequency); packet_num++; if (packet_num >= loaded_data.Count) { packet_num = 0; } } }