Beispiel #1
0
        public String MakeDrvString(Device dev)
        {
            List <String> res = new List <string>();

            for (int i = 0; i < lenInit; i++)
            {
                res.Add("0");
            }
            foreach (Init ini in inits.Values)
            {
                res[ini.address] = ini.value;
            }

            foreach (InitAss ia in dev.inits)
            {
                Init a = inits[ia.nameSig];
                res[a.address] = ia.value;
            }
            string rez = "#include \"" + header + "\"\n";

            rez += "static char buf_" + dev.name + "[" + lenData + "];\t//" + dev.description + "\n";
            rez += "static " + type + " ini_" + dev.name + "={";
            foreach (String s in res)
            {
                rez += s + ",";
            }
            rez += "};\n";
            rez += "#pragma pack(push,1)\n";
            rez += "static table_drv table_" + dev.name + "={0,0,&ini_" + dev.name + ",buf_" + dev.name + ",0,0};\n";
            rez += "#pragma pop\n";
            rez += "#pragma pack(push,1)\n";
            rez += "static DriverRegister def_buf_" + dev.name + "[]={\n";
            foreach (Assign asig in dev.signals)
            {
                rez += "\t{&" + asig.nameVar + "," + sigs[asig.nameSig].format + "," + sigs[asig.nameSig].address + "},\n";
            }
            rez += "\t{NULL,0,0},\n};\n";
            rez += "#pragma pop";
            return(rez);
        }
Beispiel #2
0
        public static Driver LoadDriver(String file)
        {
            Driver drv = new Driver();

            file = DefultDrv + "/" + file + ".xml";
            XmlDocument drvxml = new XmlDocument();

            drvxml.Load(file);
            XmlNode n = drvxml.SelectSingleNode("driver");

            drv.name        = n.Attributes["name"].Value;
            drv.description = n.Attributes["description"].Value;
            drv.code        = n.Attributes["code"].Value;
            drv.lenData     = int.Parse(n.Attributes["lenData"].Value);
            drv.lenInit     = int.Parse(n.Attributes["lenInit"].Value);
            drv.header      = n.Attributes["header"].Value;
            foreach (XmlNode sig in drvxml.SelectNodes("driver/signals/signal"))
            {
                Signal sg = new Signal();
                sg.name    = sig.Attributes["name"].Value;
                sg.format  = (byte)int.Parse(sig.Attributes["format"].Value);
                sg.need    = sig.Attributes["need"].Value.Equals("y") ? true : false;
                sg.address = int.Parse(sig.Attributes["address"].Value);
                drv.sigs.Add(sg.name, sg);
            }
            XmlNode ni = drvxml.SelectSingleNode("driver/init");

            drv.type = ni.Attributes["type"].Value;
            foreach (XmlNode init in drvxml.SelectNodes("driver/init/signal"))
            {
                Init isg = new Init();
                isg.name    = init.Attributes["name"].Value;
                isg.value   = init.Attributes["value"].Value;
                isg.address = int.Parse(init.Attributes["address"].Value);
                drv.inits.Add(isg.name, isg);
            }
            return(drv);
        }