Beispiel #1
0
        void ReceiverOmap_MsgReceived(DspMessage msg)
        {
            switch (msg.Type)
            {
            case MsgType.MsgType_Data_VectorData:
                var vector = msg.GetDataAsStruct <DSPMsg_VectorData>();
                if ((DataSaveType)vector.SaveType != DataSaveType.TimeSave)
                {
                    var vectors = new VectorData[8];
                    foreach (var vec in VectorsQueue)
                    {
                        vectors[vec.ChannelId - 4] = vec;
                    }
                    DatasReceived(vectors);
                    VectorsQueue.Clear();
                }
                break;

            case MsgType.MsgType_Data_WaveData:
                WavesQueue.Enqueue(DSPMsg_WaveData.ParseWave(msg));
                if (WavesQueue.Count >= ChannelCount)
                {
                    var waves = new WaveData[8];
                    foreach (var wave in WavesQueue)
                    {
                        waves[wave.ChannelId - 4] = wave;
                    }
                    DatasReceived(waves);
                    WavesQueue.Clear();
                }
                break;
            }
        }
Beispiel #2
0
        public static DspMessage FromStruct <T>(T obj) where T : struct
        {
            var msg = new DspMessage();

            msg.SetData(obj);
            return(msg);
        }
Beispiel #3
0
        public void Send <T>(T body) where T : struct
        {
            var msg = new DspMessage();

            msg.SetData <T>(body);
            Send(msg);
        }
Beispiel #4
0
        public static void SendAsDspMessage <T>(this TcpSocket s, T body) where T : struct
        {
            var msg = new DspMessage();

            msg.SetData <T>(body);
            //s.Send(msg.ToBytes());
            s.Send(msg);
        }
Beispiel #5
0
        public void Send(MsgType type)
        {
            var msg = new DspMessage {
                Type = type, Size = 0
            };

            Send(msg);
        }
Beispiel #6
0
        public static void SendAsDspMessage <T>(this NetworkStream s, T body) where T : struct
        {
            var msg = new DspMessage();

            msg.SetData <T>(body);
            var bytes = msg.ToBytes();

            s.Write(bytes, 0, bytes.Length);
        }
Beispiel #7
0
        private void SendMsg <MsgType>(ref MsgType obj) where MsgType : struct
        {
            var msg = new DspMessage();

            msg.SetData <MsgType>(obj);
            TcpConnection conn = this;

            conn.Send(msg);
        }
Beispiel #8
0
        public static DSPMsg_WaveData ParseHeader(DspMessage msg)
        {
            var data = new DSPMsg_WaveData();
            int i    = 0;
            var buff = msg.Data;

            ReadHeader(ref data, i, buff);

            return(data);
        }
Beispiel #9
0
        /// <summary>
        /// OnIdle이 호출됨에 주의
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static DspMessage ReadDspMessage(this TcpSocket s)
        {
            var headerBuffer = s.Read(DspMessage.HeaderSize);

            int i       = 0;
            int prefix1 = ByteUtil.ReadInt32(headerBuffer, i);

            i += 4;
            int prefix2 = ByteUtil.ReadInt32(headerBuffer, i);

            i += 4;

            if (prefix1 != DspMessage.Prefix1 || prefix2 != DspMessage.Prefix2)
            {
                throw new Exception("Wrong Prefix - " + prefix1 + ", " + prefix2);
            }

            var msgType = (MsgType)ByteUtil.ReadInt32(headerBuffer, i);

            i += 4;

            int msgSize = ByteUtil.ReadInt32(headerBuffer, i);

            i += 4;

            //Debug.WriteLine("DspMsg Read - type:" + msgType + ", size:" + msgSize);

            DspMessage msg;

            if (msgSize <= 0)
            {
                msg = new DspMessage {
                    Type = msgType, Size = msgSize
                };
            }
            else
            {
                var payload = new byte[msgSize];
                s.Read(payload, payload.Length);
                msg = new DspMessage {
                    Type = msgType, Size = msgSize, Data = payload
                };
            }

            return(msg);
        }
Beispiel #10
0
        public static WaveData ParseWave(DspMessage msg)
        {
            var oMapWave = Parse(msg);
            var wave     = new WaveData();

            wave.Idx            = oMapWave.Idx;
            wave.DateTime       = oMapWave.DateTime.ToLocalDateTime();
            wave.ChannelId      = oMapWave.ChannelId;
            wave.AsyncData      = oMapWave.AsyncData;
            wave.AsyncDataCount = oMapWave.AsyncDataCount;
            wave.Rpm            = oMapWave.Rpm;
            wave.SaveType       = oMapWave.SaveType;
            wave.SyncData       = oMapWave.SyncData;
            wave.SyncDataCount  = oMapWave.SyncDataCount;

            return(wave);
        }
Beispiel #11
0
        public void Send(DspMessage msg)
        {
            try
            {
                //WriteLog("Send - Type:" + msg.Type + ", Size:" + msg.Size, LogLevel.Debug);
                //Debug.WriteLine("Send - Type:" + msg.Type + ", Size:" + msg.Size, LogLevel.Debug);
                tcp.Send(msg);
                //WriteLog("Sended - Type:" + msg.Type + ", Size:" + msg.Size);
                //Debug.WriteLine("Sended - Type:" + msg.Type + ", Size:" + msg.Size);
#if false
                //WriteLog("Send - Type:" + msg.Type + ", Size:" + msg.Size, LogLevel.Debug);
                //var buff = msg.ToBytes();
                //stream.Send(msg);
                if (socket.Poll(1000 * 100, SelectMode.SelectWrite))
                {
                    int sended = socket.Send(msg.ToBytes());
                    if (sended == 0)
                    {
                        //WriteLog("Send Fail. Disconnect");
                        Disconnect();
                    }
                }
                else
                {
                    Disconnect();
                }
                //WriteLog("Sended - Type:" + msg.Type + ", Size:" + msg.Size);
#endif
            }
            catch (Exception ex)
            {
                //WriteLog("Send Error - " + ex);
                Debug.WriteLine("Send Error - " + ex);
                //trace.Send("Error - " + ex);

                if (!IsConnected && Disconnected != null)
                {
                    Disconnected(this, null);
                }
            }
        }