Пример #1
0
        public void sendFrame(CommunicationFrame frame)
        {
            if (frame != null && !frame.isFrameEmpty())
            {
                char[] end = { CONST_CHAR.CR, CONST_CHAR.LF };

                IOComunic.putRxData(frame.str().ToCharArray());
                IOComunic.putRxData(end);
            }
        }
Пример #2
0
        /*
         *
         * Decodifica uma resposta completa cabeçalho+payload
         *
         */
        public bool decode(out AnsCmd ans, CommunicationFrame frame)
        {
            bool ret = false;

            ans = new AnsCmd();

            string[] list = frame.Data.Split(CONST_CHAR.SEPARATOR);

            if (list != null && list.Length >= 8)
            {
                // Exclui CheckSum
                frame.Data = frame.Data.Substring(0, frame.Data.Length - 2);
                byte cheksumRx = (byte)Convert.ToInt16(list[list.Length - 1], 16);

                if (frame.checkSum() == cheksumRx)
                {
                    ans.Header = decoderHeader(list);

                    if (ans.Header.Resource.Equals(RESOURCE.TLM) &&
                        ans.Header.Operation.Equals(Operation.AN) && list.Length >= 9)
                    {
                        ans.Telemetria = decoderTLM(list);

                        ret = true;
                    }
                    else if (ans.Header.Resource.Equals(RESOURCE.LCK) &&
                             ans.Header.Operation.Equals(Operation.AN) && list.Length >= 8)
                    {
                        ret = true;
                    }
                    else
                    {
                        ret = false;
                        throw new Exception("Payload(Resource =" + ans.Header.Resource + ") não reconhecido");
                    }
                }
                else
                {
                    ret = false;
                    throw new Exception("Erro de CheckSum");
                }
            }
            else
            {
                ret = false;
                throw new ArgumentException("Error ao fazer o split do payload: " + frame.Data, "frame");
            }

            return(ret);
        }
Пример #3
0
        public bool writeTx(CommunicationFrame frame)
        {
            bool flag = false;

            if (frame != null && !frame.isFrameEmpty())
            {
                char[] end = { CONST_CHAR.CR, CONST_CHAR.LF };

                IOComunic.putTxData(frame.ToCharArray());
                IOComunic.putTxData(end);

                flag = true;
            }

            return(flag);
        }
Пример #4
0
        public bool publishFrame(string exchange, string route, CommunicationFrame frame)
        {
            bool flag = true;

            try
            {
                var body = Encoding.UTF8.GetBytes(frame.Data);

                channel.BasicPublish(exchange:           exchange,
                                     routingKey:         route,
                                     basicProperties:    null,
                                     body:               body);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Erro ao publicar o frame no server");
                Debug.WriteLine(e);
                flag = false;
            }

            return(flag);
        }
Пример #5
0
 public bool publishAns(CommunicationFrame frame)
 {
     return(publishFrame(exchange:   RABBITMQ.ANS_EXCHANGE,
                         route:      "ans." + frame.Header.Address.ToString("D5"),
                         frame:      frame));
 }
Пример #6
0
 public bool publishCMD(CommunicationFrame frame)
 {
     return(publishFrame(exchange:   RABBITMQ.CMD_EXCHANGE,
                         route:      "cmd." + frame.Header.Dest.ToString("D5"),
                         frame:      frame));
 }
Пример #7
0
 void clearRxFrame()
 {
     rxFrame = new CommunicationFrame();
 }