示例#1
0
        internal static void GenerateModel_cpp(ModelContainer mc)
        {
            HC_MODEL_CPP file = new HC_MODEL_CPP()
            {
                version        = "1.0",
                ModelReference = mc.Model.Name + " created from GIT Head SHA " + GeneratedConstants.ConfigSHA,
            };

            file.ApplicationNames = new string[mc.NextFreeIndex];
            foreach (var kv in mc.predefinedIndices)
            {
                file.ApplicationNames[kv.Value] = kv.Key;
            }
            foreach (Node node in mc.Model.Nodes)
            {
                ModelCppItem item = new ModelCppItem()
                {
                    version   = "1.0",
                    NodeId    = node.Id,
                    ModelInfo = "NodeId " + node.Id + " created on " + DateTime.Now + " using model " + mc.Model.Name + " from git hash " + GeneratedConstants.ConfigSHA,
                };

                string[] Glo2LocPointers = new string[mc.NextFreeIndex];
                for (int i = 0; i < Glo2LocPointers.Length; i++)
                {
                    Glo2LocPointers[i] = "    0,";
                }
                //Static initializers
                foreach (SensactApplication app in node.Applications)
                {
                    item.StaticApplicationInitializers.Append(app.GenerateInitializer(mc));
                    SensactApplicationContainer appCont = mc.id2app[app.ApplicationId];
                    Glo2LocPointers[appCont.Index] = "    &" + app.ApplicationId + ",";
                }
                for (int i = 0; i < Glo2LocPointers.Length; i++)
                {
                    item.Glo2LocPointers.AppendLine(Glo2LocPointers[i]);
                }
                string[] Glo2LocEvents = new string[mc.NextFreeIndex];
                for (int i = 0; i < Glo2LocEvents.Length; i++)
                {
                    Glo2LocEvents[i] = "    0,";
                }
                for (int i = 0; i < Glo2LocPointers.Length; i++)
                {
                    item.Glo2LocEvents.AppendLine(Glo2LocEvents[i]);
                }

                file.Items.Add(item);
            }


            string pageContent = file.TransformText();
            string filename    = "cModel.cpp";

            File.WriteAllText(GetGeneratedPathForFile(filename), pageContent);
            LOG.InfoFormat("Successfully created {0}", filename);
            return;
        }
示例#2
0
        internal void GenerateNodeSpecificFiles(ModelContainer mc)
        {
            foreach (Node node in mc.Model.Nodes)
            {
                StringBuilder sb = new StringBuilder();

                //const eApplicationID MODEL::NodeMasterApplication = eApplicationID::SNSCT_L0_TECH_HS_1;
                sb.AFL("const sensact::eApplicationID applications::NodeMasterApplication = sensact::eApplicationID::{0};", node.NodeName);
                WriteFileInSubdirectory(node.NodeName, "nodeMasterApplicationId", sb);
                sb.Clear();

                //const char MODEL::ModelString[] ="NodeId SNSCT_L0_TECH_HS_1 created on 02.02.2021 22:29:40 using model Sattlerstraße 16 from git hash ea29f6371a5d33c7621cecf1e6bda050edf38681";
                sb.AFL("const char* const node::NodeDescription =\"NodeId {0} created on {1} using model {2}\";", node.NodeName, DateTime.Now, mc.Model.Name);
                //const eNodeID MODEL::NodeID = eNodeID::SNSCT_L0_TECH_HS_1;
                sb.AFL("const sensact::eNodeID node::NodeID = sensact::eNodeID::{0};", node.NodeName);
                WriteFileInSubdirectory(node.NodeName, "nodeDescription", sb);
                sb.Clear();

                string[] Glo2LocCmd = new string[mc.NextFreeIndex];
                for (int i = 0; i < mc.NextFreeIndex; i++)
                {
                    Glo2LocCmd[i] = "\tnullptr,";
                }
                //Static initializers
                foreach (SensactApplication app in node.Applications)
                {
                    sb.Append(app.GenerateInitializer(mc));
                    SensactApplicationContainer appCont = mc.id2app[app.ApplicationId];
                    Glo2LocCmd[appCont.Application.ApplicationId] = "    &" + app.ApplicationId + ",";
                }
                WriteFileInSubdirectory(node.NodeName, "applicationInitializers", sb);
                sb.Clear();
                for (int i = 0; i < Glo2LocCmd.Length; i++)
                {
                    sb.AppendLine(Glo2LocCmd[i]);
                }
                WriteFileInSubdirectory(node.NodeName, "glo2LocCmd", sb);
                sb.Clear();
                string[] Glo2LocEvents = new string[mc.NextFreeIndex];
                for (int i = 0; i < Glo2LocEvents.Length; i++)
                {
                    Glo2LocEvents[i] = "\tnullptr,";
                }
                for (int i = 0; i < Glo2LocCmd.Length; i++)
                {
                    sb.AppendLine(Glo2LocEvents[i]);
                }

                WriteFileInSubdirectory(node.NodeName, "glo2LocEvt", sb);
                sb.Clear();
            }
            LOG.LogInformation("Successfully created all node specific .inc files");
            return;
        }
示例#3
0
        public bool CheckAndPrepare(ModelContainer mc)
        {
            HashSet <ushort> predefinedAppIds = Enum.GetValues <Nodes.ApplicationId>().Select(x => (ushort)x).ToHashSet();

            mc.NextFreeIndex = predefinedAppIds.Where(x => x != (ushort)Nodes.ApplicationId.NO_APPLICATION).Max();
            mc.NextFreeIndex++;
            SensactApplicationContainer masterApp = new SensactApplicationContainer(null, new Applications.MasterApplication());

            mc.id2app[masterApp.Application.ApplicationId] = masterApp;

            foreach (Node n in mc.Model.Nodes)
            {
                HashSet <string> usedInputPins  = new HashSet <string>();
                HashSet <string> usedOutputPins = new HashSet <string>();

                foreach (SensactApplication app in n.Applications)
                {
                    if (app.ApplicationName == null)
                    {
                        LOG.LogError("An App in Node {0} has no name", n.NodeName);
                        return(false);
                    }
                    if (app.ApplicationId == 0 && app.ApplicationName != null)
                    {
                        app.SetApplicationId_BeCareful(mc.NextFreeIndex++);
                    }

                    if (mc.id2app.ContainsKey(app.ApplicationId))
                    {
                        LOG.LogError("AppId {0} is defined at least two times in node applications", app.ApplicationId);
                        return(false);
                    }
                    if (!app.HasValidAppId())
                    {
                        LOG.LogWarning("AppId {0} with name {1} in node {2} does not fulfill the regex pattern {3} for application name. This is ok, but maybe it is an error...", app.ApplicationId, app.ApplicationName, n.NodeName, app.AppNameRegex);
                        app.HasValidAppId();
                    }
                    string errorMessage = app.CheckAndAddUsedPins(usedInputPins, usedOutputPins);
                    if (errorMessage != null)
                    {
                        LOG.LogError("AppId {0} uses pins that have been reserved by another app:\n{1}", app.ApplicationId, errorMessage);
                        return(false);
                    }
                    SensactApplicationContainer cont = new SensactApplicationContainer(n, app);
                    mc.id2app[cont.Application.ApplicationId] = cont;
                }

                //Sanity: Check, whether node application has already been added
                if (mc.id2app.ContainsKey(n.NodeId))
                {
                    //Es wurde eine Application mit der ID der Node angelegt
                    if (!mc.id2app[n.NodeId].Application.ApplicationName.Equals(n.NodeName))
                    {
                        //mit dem Namen gibt es ein Problem
                        LOG.LogError("There is a predefined node app for node {0}, but its name is not correct:", n.NodeName);
                        return(false);
                    }
                }
                else
                {
                    SensactApplicationContainer nodeAppContainer = new SensactApplicationContainer(n, new SensactNodeApplication(n.NodeId, n.NodeName));
                    n.Applications.Add(nodeAppContainer.Application);
                    mc.id2app.Add(nodeAppContainer.Application.ApplicationId, nodeAppContainer);
                }
            }

            //Find out which events should be fired by each application because there is a listener for the event
            //distinguish between local events and bus events
            foreach (Node n in mc.Model.Nodes)
            {
                foreach (SensactApplication app in n.Applications)
                {
                    HashSet <Event>             evts    = app.IReactOnTheseEvents();
                    SensactApplicationContainer appCont = mc.id2app[app.ApplicationId];
                    foreach (Event evt in evts)
                    {
                        //Kann die SourceApp dieses Event überhaupt erzeugen?
                        SensactApplicationContainer source;
                        if (!mc.id2app.TryGetValue(evt.SourceAppId, out source))
                        {
                            LOG.LogError("AppId {0} listens to event from AppId {1}, but this app does not exist.", app.ApplicationId, evt.SourceAppId);
                            return(false);
                        }
                        else
                        {
                            if (!source.Application.ICanSendTheseEvents().Contains(evt.EventType))
                            {
                                LOG.LogError("AppId {0} listens to event {1} from AppId {2}, but this app cannot produce such events.", app.ApplicationId, evt.EventType, evt.SourceAppId);
                                return(false);
                            }
                        }
                        if (appCont.Node == source.Node)
                        {
                            //source und destination leben in der selben node
                            HashSet <EventType> set = null;
                            if (!mc.id2localEvents.TryGetValue(evt.SourceAppId, out set))
                            {
                                set = new HashSet <EventType>();
                                mc.id2localEvents[evt.SourceAppId] = set;
                            }
                            set.Add(evt.EventType);
                        }
                        else
                        {
                            HashSet <EventType> set = null;
                            if (!mc.id2busEvents.TryGetValue(evt.SourceAppId, out set))
                            {
                                set = new HashSet <EventType>();
                                mc.id2busEvents[evt.SourceAppId] = set;
                            }
                            set.Add(evt.EventType);
                        }
                    }
                    HashSet <Command> cmds = app.ISendTheseCommands();
                    foreach (Command cmd in cmds)
                    {
                        SensactApplicationContainer target;
                        if (!mc.id2app.TryGetValue(cmd.TargetAppId, out target))
                        {
                            if (cmd.TargetAppId != (ushort)Nodes.ApplicationId.NO_APPLICATION)
                            {
                                LOG.LogError("AppId {0} sends command to AppId {1}, but this app does not exist.", app.ApplicationId, cmd.TargetAppId);
                                return(false);
                            }
                        }
                        else
                        {
                            if (!target.Application.ICanReactOnTheseCommands().Contains(cmd.CommandType))
                            {
                                LOG.LogError("AppId {0} sends command {1} to AppId {2}, but this app cannot react on this command.", app.ApplicationId, cmd.CommandType, cmd.TargetAppId);
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
示例#4
0
        public static bool CheckAndPrepare(ModelContainer mc)
        {
            //preFill predefined indices
            mc.PrefillPredefinedIndices(Enum.GetValues(typeof(ID)));

            HashSet <string>            alreadyDefinedAppIds = new HashSet <string>();
            SensactApplicationContainer masterApp            = new SensactApplicationContainer()
            {
                Application = new Applications.MasterApplication(), Index = mc.GetIndex("MASTER"), Node = null
            };

            mc.id2app[masterApp.Application.ApplicationId] = masterApp;
            mc.index2app[0] = masterApp;
            foreach (Node n in mc.Model.Nodes)
            {
                n.Applications.Add(new SensactNodeApplication
                {
                    ApplicationId = n.Id,
                });
                HashSet <string> usedInputPins  = new HashSet <string>();
                HashSet <string> usedOutputPins = new HashSet <string>();
                foreach (SensactApplication app in n.Applications)
                {
                    if (alreadyDefinedAppIds.Contains(app.ApplicationId))
                    {
                        LOG.ErrorFormat("AppId {0} is defined at least two times in node applications", app.ApplicationId);
                        return(false);
                    }
                    if (!app.HasValidAppId())
                    {
                        LOG.WarnFormat("AppId {0} does not fulfill the recommendations for application name. This is ok, but maybe it is an error...", app.ApplicationId, n.Id);
                        app.HasValidAppId();
                    }
                    string errorMessage = app.CheckAndAddUsedPins(usedInputPins, usedOutputPins);
                    if (errorMessage != null)
                    {
                        LOG.ErrorFormat("AppId {0} uses pins that have been reserved by another app:\n{1}", app.ApplicationId, errorMessage);
                        return(false);
                    }
                    alreadyDefinedAppIds.Add(app.ApplicationId);
                    SensactApplicationContainer cont = new SensactApplicationContainer
                    {
                        Application = app,
                        Index       = mc.GetIndex(app.ApplicationId),
                        Node        = n,
                    };

                    mc.id2app[cont.Application.ApplicationId] = cont;
                    mc.index2app[cont.Index] = cont;
                }
            }

            //Find out which events should be fired by each application because there is a listener for the event
            //distinguish between local events and bus events
            foreach (Node n in mc.Model.Nodes)
            {
                foreach (SensactApplication app in n.Applications)
                {
                    HashSet <Event>             evts    = app.IReactOnTheseEvents();
                    SensactApplicationContainer appCont = mc.id2app[app.ApplicationId];
                    foreach (Event evt in evts)
                    {
                        //Kann die SourceApp dieses Event überhaupt erzeugen?
                        SensactApplicationContainer source;
                        if (!mc.id2app.TryGetValue(evt.SourceAppId, out source))
                        {
                            LOG.ErrorFormat("AppId {0} listens to event from AppId {1}, but this app does not exist.", app.ApplicationId, evt.SourceAppId);
                            return(false);
                        }
                        else
                        {
                            if (!source.Application.ICanSendTheseEvents().Contains(evt.EventType))
                            {
                                LOG.ErrorFormat("AppId {0} listens to event {1} from AppId {2}, but this app cannot produce such events.", app.ApplicationId, evt.EventType, evt.SourceAppId);
                                return(false);
                            }
                        }
                        if (appCont.Node == source.Node)
                        {
                            //source und destination leben in der selben node
                            HashSet <EventType> set = null;
                            if (!mc.id2localEvents.TryGetValue(evt.SourceAppId, out set))
                            {
                                set = new HashSet <EventType>();
                                mc.id2localEvents[evt.SourceAppId] = set;
                            }
                            set.Add(evt.EventType);
                        }
                        else
                        {
                            HashSet <EventType> set = null;
                            if (!mc.id2busEvents.TryGetValue(evt.SourceAppId, out set))
                            {
                                set = new HashSet <EventType>();
                                mc.id2busEvents[evt.SourceAppId] = set;
                            }
                            set.Add(evt.EventType);
                        }
                    }
                    HashSet <Command> cmds = app.ISendTheseCommands();
                    foreach (Command cmd in cmds)
                    {
                        SensactApplicationContainer target;
                        if (!mc.id2app.TryGetValue(cmd.TargetAppId, out target))
                        {
                            if (cmd.TargetAppId != ID.NO_APPLICATION.ToString())
                            {
                                LOG.ErrorFormat("AppId {0} sends command to AppId {1}, but this app does not exist.", app.ApplicationId, cmd.TargetAppId);
                                return(false);
                            }
                        }
                        else
                        {
                            if (!target.Application.ICanReactOnTheseCommands().Contains(cmd.CommandType))
                            {
                                LOG.ErrorFormat("AppId {0} sends command {1} to AppId {2}, but this app cannot react on this command.", app.ApplicationId, cmd.CommandType, cmd.TargetAppId);
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }