Beispiel #1
0
        public MultiplexerConfig(string hiFamily, string hiModel)
        {
            StorageCfgs.Hi.Family = hiFamily;
            StorageCfgs.Hi.Model  = hiModel;

            XPinConfig xPinConfig = HiXmlParser.getMultiplexerConfig(hiFamily, hiModel);
            YPinConfig yPinConfig = new YPinConfig();

            _x_pin_to_value_map = xPinConfig._x_pin_to_value_map;
            gpio_To_YPin_Map    = yPinConfig.gpio_To_YPin_Map;

            Debug.WriteLine("\n====================================\n " +
                            "===== Multiplexer Configuration ====\n ");

            RaspberryPi.Instance.Control.Multiplexer.current_multiplexer_state.Clear();

            foreach (int value_x in _x_pin_to_value_map.Keys)
            {
                foreach (string y_value in gpio_To_YPin_Map.Keys)
                {
                    if (y_value.Equals(_x_pin_to_value_map[value_x]))
                    {
                        x_to_y_map.Add(value_x, gpio_To_YPin_Map[y_value]);

                        Debug.WriteLine("Pin {0} is connected to : {1} \n", value_x, y_value);
                        RaspberryPi.Instance.Control.Multiplexer.current_multiplexer_state.Add(value_x, new Tuple <int, string>(gpio_To_YPin_Map[y_value], y_value));
                    }
                }
            }

            Debug.WriteLine("====================================\n ");

            saveConfig();
        }
Beispiel #2
0
        /// <summary>
        /// Reads the current configuration of the Raspberry and updates the LCD status information <see cref="updateLCD"/>
        /// </summary>
        /// <param name="i">not used</param>
        /// <returns>The current configuration as human readable string</returns>
        public string GetRaspiConfig(int i)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("IPAddress: " + this.GetIpAddressAsync() + "\n");
            sb.Append("Initialized: " + RasPi.isInitialized() + "\n");
            sb.Append("TestMode: " + RasPi.isTestMode() + "\n");
            sb.Append("LCD: \n");
            sb.Append("\t Initialized: " + this.LCD.isInitialized() + "\n");
            sb.Append("\t Text: " + this.LCD.CurrentTextPlainString + "\n");
            sb.Append("Potentiometer: \n");
            sb.Append("\t Initialized: " + this.Potentiometer.isInitialized() + "\n");
            sb.Append("HI: \n");
            sb.Append("\t Family: " + StorageCfgs.Hi.Family + "\n");
            sb.Append("\t Model: " + StorageCfgs.Hi.Model + "\n");
            sb.Append("\t Available Usercontrols: \n");
            XPinConfig mux_config = HiXmlParser.getMultiplexerConfig(StorageCfgs.Hi.Family, StorageCfgs.Hi.Model);

            foreach (var pair in mux_config.X_Pin_To_Value_Map)
            {
                if (!pair.Value.Equals(""))
                {
                    sb.Append("\t\t X-Pin:" + pair.Key + ", UserControl: " + pair.Value + "\n");
                }
            }

            sb.Append("Status of Usercontrols: \n");
            sb.Append("\t Telecoil detected: " + getTeleCoilStatus() + "\n");
            sb.Append("\t Audio Shoe detected: " + getAudioShoeStatus() + "\n");
            sb.Append("\t LED is On: " + CheckLEDStatus(0) + "\n");

            this.updateLCD();

            return(sb.ToString());
        }
        /// <summary>
        /// Get the multiplexer configuation of a specific HI
        /// </summary>
        /// <param name="family">family name of the HI, e.g.: "Pure"</param>
        /// <param name="model_name">model name of the HI: e.g: "312 702 S (DN)"</param>
        /// <returns>
        /// Returns a HiType Object
        /// Returns null if the specified HI is not found
        /// </returns>
        public static XPinConfig getMultiplexerConfig(string family, string model_name)
        {
            if (hi_dictionary.ContainsKey(family))
            {
                Dictionary <List <string>, XPinConfig> family_dic = hi_dictionary[family];

                XPinConfig multiplex_config = null;
                bool       model_found      = false;

                foreach (List <string> model_names in family_dic.Keys)
                {
                    if (model_names.Contains(model_name))
                    {
                        multiplex_config = family_dic[model_names];
                        model_found      = true;
                        break;
                    }
                }

                if (model_found)
                {
                    return(multiplex_config);
                }
            }
            return(null);
        }
        /// <summary>
        /// Creates a human readable string of the XML configuration file.
        /// </summary>
        /// <returns>
        /// Returns a string containing multiplexer configurations for all possible HIs
        /// </returns>
        public static string getXMLConfigAsString()
        {
            StringBuilder sb = new StringBuilder();

            foreach (string familyName in hi_dictionary.Keys)
            {
                sb.Append("Family " + familyName + ":");
                sb.Append("\n");

                Dictionary <List <string>, XPinConfig> model_dic = hi_dictionary[familyName];

                foreach (List <string> model_names in model_dic.Keys)
                {
                    sb.Append("\tModels: ");
                    sb.Append("\n");
                    foreach (string model_name in model_names)
                    {
                        sb.Append("\t\t[" + model_name + "]");
                        sb.Append("\n");
                    }

                    sb.Append("\n");

                    XPinConfig config_obj = model_dic[model_names];
                    Dictionary <int, string> config_map = config_obj.X_Pin_To_Value_Map;

                    sb.Append("\tConfig: ");
                    sb.Append("\n");
                    foreach (int key in config_map.Keys)
                    {
                        string value = config_map[key];

                        sb.Append("\t\t PinID: " + key + ", Value: " + value);
                        sb.Append("\n");
                    }
                }
                sb.Append("------------------------------------------------------------");
                sb.Append("\n");
            }

            return(sb.ToString());
        }
        private static void buildDictionary()
        {
            IEnumerable <XNode> familyNodes = config.Element("PinOutInfo").Nodes();

            foreach (XElement familyElement in familyNodes)
            {
                string family_name = familyElement.Attribute("name").Value;

                Dictionary <List <string>, XPinConfig> tmp = new Dictionary <List <string>, XPinConfig>();

                IEnumerable <XNode> modelNodes = familyElement.Nodes();
                foreach (XElement modelElement in modelNodes)
                {
                    string model_names_string = modelElement.Attribute("name").Value;

                    List <string> model_names_list = new List <string>();

                    Char     delimiter   = ',';
                    String[] model_names = model_names_string.Split(delimiter);

                    model_names_list.AddRange(model_names);

                    List <string> pin_value_list = new List <string>();

                    IEnumerable <XNode> pinNodes = modelElement.Nodes();
                    foreach (XElement pinElement in pinNodes)
                    {
                        string pin_value = pinElement.Attribute("value").Value;
                        pin_value_list.Add(pin_value);
                    }

                    XPinConfig pin_config = new XPinConfig(family_name, model_names_string, pin_value_list);

                    tmp.Add(model_names_list, pin_config);
                }
                hi_dictionary.Add(family_name, tmp);
            }
        }
        private static int statusMessageCount = 0; // count messages generated by this method (currently for arbitrary reasons)

        /// <summary>
        /// Executes the Command getStatusXML()
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns>
        /// The current state of the Raspberry Pi: Status of user controls, available features, hardware information.
        /// This method returns an XML-file.
        /// </returns>
        public XDocument getStatusXML()
        {
            XElement xml = new XElement("Operation",
                                        new XAttribute("Timestamp", DateTime.Now.ToString("hh:mm:ss")),
                                        new XAttribute("Message", 1),
                                        new XElement("IPAddress", this.GetIpAddressAsync()),
                                        new XElement("Initialized", RasPi.isInitialized()),
                                        new XElement("TestMode", RasPi.isTestMode())
                                        );

            /* TODO if possible: read & return currently displayed text.
             * Depending whether or not LCD is connected, status information differs. */
            if (this.LCD.isInitialized())
            {
                xml.Add(new XElement("LCD",
                                     new XElement("Initialized", true),
                                     new XElement("Text", this.LCD.CurrentText.ToString())));
            }
            else
            {
                xml.Add(new XElement("LCD",
                                     new XElement("Initialized", false)));
            }
            if (this.Potentiometer.isInitialized())
            {
                xml.Add(new XElement("Potentiometer",
                                     new XElement("Initialized", true),
                                     new XElement("Text", this.Potentiometer.WiperState)));
            }
            else
            {
                xml.Add(new XElement("Potentiometer",
                                     new XElement("Initialized", false)));
            }
            xml.Add(new XElement("LED",
                                 new XElement("Initialized", "?"),                    // possible to update this later on to better reflect whether or not an LED is even attached
                                 new XElement("Status", GPIOinterface.readPin(24)))); // gpio interface read pin led pin 24
            if (this.Multiplexer.isInitialized())
            {
                xml.Add(new XElement("Multiplexer",
                                     new XElement("Initialized", true),
                                     new XElement("Family", StorageCfgs.Hi.Family),
                                     new XElement("ModelName", StorageCfgs.Hi.Model)
                                     ));
                /* Read config from XML and based on that return supported controls of current HI*/
                XPinConfig mux_config = HiXmlParser.getMultiplexerConfig(StorageCfgs.Hi.Family, StorageCfgs.Hi.Model);
                xml.Add(new XElement("HI",
                                     new XElement(YPinConfig.ROCKERSWITCH_STRING, string.Join(",", mux_config.ValueToPins(YPinConfig.ROCKERSWITCH_STRING))),
                                     new XElement(YPinConfig.GROUND, string.Join(",", mux_config.ValueToPins(YPinConfig.GROUND))),
                                     new XElement(YPinConfig.PUSHBUTTON_STRING, string.Join(",", mux_config.ValueToPins(YPinConfig.PUSHBUTTON_STRING))),
                                     new XElement(YPinConfig.AMR, string.Join(",", mux_config.ValueToPins(YPinConfig.AMR))),
                                     new XElement(YPinConfig.AUDIOINPUT, string.Join(",", mux_config.ValueToPins(YPinConfig.AUDIOINPUT))),
                                     new XElement(YPinConfig.REC_DET, string.Join(",", mux_config.ValueToPins(YPinConfig.REC_DET))),
                                     new XElement(YPinConfig.LED, string.Join(",", mux_config.ValueToPins(YPinConfig.LED))),
                                     new XElement(YPinConfig.M, string.Join(",", mux_config.ValueToPins(YPinConfig.M))),
                                     new XElement(YPinConfig.STOP_END, string.Join(",", mux_config.ValueToPins(YPinConfig.STOP_END))),
                                     new XElement(YPinConfig.ENDLESS_VC, string.Join(",", mux_config.ValueToPins(YPinConfig.ENDLESS_VC))),
                                     new XElement(YPinConfig.ARD, string.Join(",", mux_config.ValueToPins(YPinConfig.ARD))),
                                     new XElement(YPinConfig.DET_AUDIO, string.Join(",", mux_config.ValueToPins(YPinConfig.DET_AUDIO))),
                                     new XElement(YPinConfig.DET_TELE, string.Join(",", mux_config.ValueToPins(YPinConfig.DET_TELE)))
                                     ));
            }
            else
            {
                xml.Add(new XElement("Multiplexer",
                                     new XElement("Initialized", false)
                                     ));
            }
            if (this.ADConverter.isInitialized())
            {
                xml.Add(new XElement("ADConverter",
                                     new XElement("Initialized", true),
                                     new XElement("Connected", this.ADConverter.isConnected()),
                                     new XElement("Channel1", this.ADConverter.CurrentDACVoltage1),
                                     new XElement("Channel2", this.ADConverter.CurrentDACVoltage2)
                                     ));
            }
            else
            {
                xml.Add(new XElement("ADConverter",
                                     new XElement("Initialized", false)
                                     ));
            }
            statusMessageCount++; // count send results for no particular reason other than ensuring order of status updates
            return(new XDocument(new XElement(xml)));
        }