Ejemplo n.º 1
0
        /// <summary>
        /// Build RelayData objects to send to clients.  Show the on/off status of indivudal relays.  Also the on/off masks associated with them.
        /// </summary>
        /// <param name="binaryOnOffStatus">The string representation of the on/off status of all 8 relays in reverse order.  (ex. 11010011)</param>
        /// <param name="binaryMaskOnStatuses">The string representation of the Mask On status of all 8 relays in reverse order.  (ex. 11010011)</param>
        /// <param name="binaryMaskOffStatuses">The string representation of the Mask Off status of all 8 relays in reverse order.  (ex. 11010011)</param>
        private void BuildRelayStatuses(string binaryOnOffStatus,string binaryMaskOnStatuses, string binaryMaskOffStatuses)
        {
            currentRelayData = new ReefAngelRelayData();
            string orderedBinaryRelayData, orderedBinaryMaskOnData, orderedBinaryMaskOffData;
            char[] arr = binaryOnOffStatus.ToCharArray();
            Array.Reverse(arr);
            orderedBinaryRelayData = new string(arr);

            currentRelayData.Relay1On = orderedBinaryRelayData[0] == '0' ? false : true;
            currentRelayData.Relay2On = orderedBinaryRelayData[1] == '0' ? false : true;
            currentRelayData.Relay3On = orderedBinaryRelayData[2] == '0' ? false : true;
            currentRelayData.Relay4On = orderedBinaryRelayData[3] == '0' ? false : true;
            currentRelayData.Relay5On = orderedBinaryRelayData[4] == '0' ? false : true;
            currentRelayData.Relay6On = orderedBinaryRelayData[5] == '0' ? false : true;
            currentRelayData.Relay7On = orderedBinaryRelayData[6] == '0' ? false : true;
            currentRelayData.Relay8On = orderedBinaryRelayData[7] == '0' ? false : true;

            //TODO: Incomplete binary data for the On/Off masks is coming back from ReefAngel Controller.  Need to identify how the data
            //is sent from controller - parse it and populte the following code belowing.

            //arr = binaryMaskOnStatuses.ToCharArray();
            //Array.Reverse(arr);
            //orderedBinaryMaskOnData = new string(arr);
            //currentRelayData.Relay1MaskOn = orderedBinaryMaskOnData[0] == '0' ? false : true;
            //currentRelayData.Relay2MaskOn = orderedBinaryMaskOnData[1] == '0' ? false : true;
            //currentRelayData.Relay3MaskOn = orderedBinaryMaskOnData[2] == '0' ? false : true;
            //currentRelayData.Relay4MaskOn = orderedBinaryMaskOnData[3] == '0' ? false : true;
            //currentRelayData.Relay5MaskOn = orderedBinaryMaskOnData[4] == '0' ? false : true;
            //currentRelayData.Relay6MaskOn = orderedBinaryMaskOnData[5] == '0' ? false : true;
            //currentRelayData.Relay7MaskOn = orderedBinaryMaskOnData[6] == '0' ? false : true;
            //currentRelayData.Relay8MaskOn = orderedBinaryMaskOnData[7] == '0' ? false : true;

            //arr = binaryMaskOffStatuses.ToCharArray();
            //Array.Reverse(arr);
            //orderedBinaryMaskOffData = new string(arr);
            //currentRelayData.Relay1MaskOff = orderedBinaryMaskOffData[0] == '0' ? false : true;
            //currentRelayData.Relay2MaskOff = orderedBinaryMaskOffData[1] == '0' ? false : true;
            //currentRelayData.Relay3MaskOff = orderedBinaryMaskOffData[2] == '0' ? false : true;
            //currentRelayData.Relay4MaskOff = orderedBinaryMaskOffData[3] == '0' ? false : true;
            //currentRelayData.Relay5MaskOff = orderedBinaryMaskOffData[4] == '0' ? false : true;
            //currentRelayData.Relay6MaskOff = orderedBinaryMaskOffData[5] == '0' ? false : true;
            //currentRelayData.Relay7MaskOff = orderedBinaryMaskOffData[6] == '0' ? false : true;
            //currentRelayData.Relay8MaskOff = orderedBinaryMaskOffData[7] == '0' ? false : true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Iterate through current client list and invoke their HandleRelayData with latest relay parameters.
        /// </summary>
        /// <param name="relayData">The current relay data params</param>
        public void SendRelayData(ReefAngelRelayData relayData)
        {
            ThreadPool.QueueUserWorkItem
            (
                delegate
                {
                    lock (clients)
                    {
                        List<Guid> disconnectedClientGuids = new List<Guid>();

                        foreach (KeyValuePair<Guid, IReefAngelCallback> client in clients)
                        {
                            try
                            {
                                client.Value.HandleRelayData(relayData);
                            }
                            catch (Exception)
                            {
                                // There is a number of reasons an exception can occur here.
                                // The server might not be able to connect to client b/c of network error,
                                // early client terminiation w/out being able to unsubscribe first or comms object is killed.
                                // No matter the case - mark the client key for removal.
                                disconnectedClientGuids.Add(client.Key);
                            }
                        }

                        foreach (Guid clientGuid in disconnectedClientGuids)
                        {
                            clients.Remove(clientGuid);
                        }
                    }
                }
            );
        }