Ejemplo n.º 1
0
        //Takes response to poll command as a byte array, parses out individual responses and returns
        //a string containing the response names
        public string GetPollResponse(byte[] response)
        {
            string          ReturnString = "";
            int             ResponseCode = 0;
            int             Increment    = 0;
            SspPollResponse SspPolResp   = new SspPollResponse();

            try
            {
                //Start at first byte
                int ByteCounter = 1;
                //Loop until end of byte array is reached
                while (ByteCounter < response.Length)
                {
                    //Add the ResponseName for the ResponseCode to the return string.
                    ResponseCode  = response[ByteCounter];
                    SspPolResp    = pollResponsesDictionary[ResponseCode];
                    ReturnString += SspPolResp.ResponseName;

                    //If response is fixed length
                    if (SspPolResp.Length != 0)
                    {
                        //Increment byte counter by fixed amount
                        Increment = SspPolResp.Length;
                    }
                    else
                    {
                        //Else calculate length of response from data and increment byte counter
                        Increment  = response[(ByteCounter + SspPolResp.LengthByte)];
                        Increment *= SspPolResp.Multiply;
                        Increment += SspPolResp.Add;
                        Increment += 1;
                    }

                    ByteCounter += Increment;

                    if (ByteCounter < response.Length)
                    {
                        ReturnString += ", ";
                    }
                }
            }
            catch (Exception e)
            {
                ReturnString = e.Message;
            }
            ReturnString += "\r\n";
            return(ReturnString);
        }
Ejemplo n.º 2
0
        //Reads data from Resources/PollResponses.xml.
        private void CSspReadPollResponsesData()
        {
            pollResponsesDictionary = new Dictionary <int, SspPollResponse>();
            XmlDocument     document = new XmlDocument();
            SspPollResponse SspPoll  = new SspPollResponse();
            int             i        = 0;

            document.Load("Resources/PollResponses.xml");

            XmlNodeList nodeList = document.DocumentElement.SelectNodes("/Root/PollResponseInfo");

            //Loop through all PollResponseInfo nodes in /Root.
            foreach (XmlNode node in nodeList)
            {
                if (node.SelectSingleNode("PollResponseName") != null)
                {
                    i = Int32.Parse(node.SelectSingleNode("PollResponseCode").InnerText);

                    //Put PollResponseName into struct
                    SspPoll.ResponseName = node.SelectSingleNode("PollResponseName").InnerText;

                    //Add any other elements, if present in xml
                    if (node.SelectSingleNode("Length") != null)
                    {
                        SspPoll.Length = Int32.Parse(node.SelectSingleNode("Length").InnerText);
                    }
                    else
                    {
                        SspPoll.Length = 0;
                    }

                    if (node.SelectSingleNode("LengthByte") != null)
                    {
                        SspPoll.LengthByte = Int32.Parse(node.SelectSingleNode("LengthByte").InnerText);
                    }
                    else
                    {
                        SspPoll.LengthByte = 0;
                    }

                    if (node.SelectSingleNode("Multiply") != null)
                    {
                        SspPoll.Multiply = Int32.Parse(node.SelectSingleNode("Multiply").InnerText);
                    }
                    else
                    {
                        SspPoll.Multiply = 0;
                    }

                    if (node.SelectSingleNode("Add") != null)
                    {
                        SspPoll.Add = Int32.Parse(node.SelectSingleNode("Add").InnerText);
                    }
                    else
                    {
                        SspPoll.Add = 0;
                    }
                    //Add entry to dictionary
                    pollResponsesDictionary.Add(i, SspPoll);
                }
            }
        }