static private int HB_PUBLISH_RATE = 5; // in seconds static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage heartbeat_service.exe mw-id=<middleware ID>"); return(-1); } Config config = new Config(args); InitializeLogging(config); Log.Info("API version: " + ConnectionManager.GetAPIVersion()); try { ConnectionManager connManager = new ConnectionManager(config); Log.Info("Opening the connection to the middleware server"); connManager.Initialize(); Log.Info("Middleware version: " + connManager.GetLibraryVersion()); //o Create all of the GMSEC Message header Fields which will // be used by all GMSEC Messages FieldList headerFields = new FieldList(); uint version = connManager.GetSpecification().GetVersion(); StringField missionField = new StringField("MISSION-ID", "MY-MISSION"); StringField facilityField = new StringField("FACILITY", "MY-FACILITY"); StringField componentField = new StringField("COMPONENT", "HEARTBEAT-SERVICE"); StringField domain1Field = new StringField("DOMAIN1", "MY-DOMAIN-1"); StringField domain2Field = new StringField("DOMAIN2", "MY-DOMAIN-2"); StringField msgID = new StringField("MSG-ID", "MY-MSG-ID"); headerFields.Add(missionField); headerFields.Add(facilityField); headerFields.Add(componentField); if (version == 201400) { headerFields.Add(msgID); } else if (version >= 201800) { headerFields.Add(domain1Field); headerFields.Add(domain2Field); } //o Use setStandardFields to define a set of header fields for // all messages which are created or published on the // ConnectionManager using the following functions: // createLogMessage, publishLog, createHeartbeatMessage, // startHeartbeatService, createResourceMessage, // publishResourceMessage, or startResourceMessageService connManager.SetStandardFields(headerFields); // Note: Fields are immutable, so plan appropriately if you wish // to re-use variable names! { //o Create all of the GMSEC Message header Fields which // will be used by all GMSEC HB Messages FieldList hbStandardFields = new FieldList(); //o Determine which version of the GMSEC message specification // the ConnectionManager was initialized with and add // the correctly typed Fields to the Message if (version >= 201600) { hbStandardFields.Add(new U16Field("PUB-RATE", (UInt16)HB_PUBLISH_RATE)); hbStandardFields.Add(new U16Field("COUNTER", (UInt16)1)); } else if (version == 201400) { hbStandardFields.Add(new I16Field("PUB-RATE", (short)HB_PUBLISH_RATE)); hbStandardFields.Add(new I16Field("COUNTER", (short)1)); } //o Note: COMPONENT-STATUS is an optional field used to // denote the operating status of the component, the // values are as follows: // 0 - Debug // 1 - Normal / Green // 2 - Warning / Yellow // 3 - Orange // 4 - Error / Red I16Field componentStatusField = new I16Field("COMPONENT-STATUS", (short)0); hbStandardFields.Add(componentStatusField); //o Create and publish a Heartbeat message using // createLogMessage() and publish() // // Note: This is useful for applications which may need // to create proxy heartbeats on behalf of a subsystem, // as creating multiple ConnectionManagers can consume // more memory than necessary. In this case, extra // logic would need to be added to handle the timing of // the publications. Message hbMsg = connManager.CreateHeartbeatMessage(HB_MESSAGE_SUBJECT, hbStandardFields); Log.Info("Publishing the GMSEC C2CX HB message which was just created using createHeartbeatMessage():\n" + hbMsg.ToXML()); connManager.Publish(hbMsg); //o Kick off the Heartbeat Service -- This will publish // heartbeat messages automatically every X seconds, // where Xis the value which was provided for PUB-RATE // Note: If PUB-RATE was not provided, it will default // to 30 seconds per automatic Heartbeat publication Log.Info("Starting the Heartbeat service, a message will be published every " + hbStandardFields[0].GetStringValue() + " seconds"); connManager.StartHeartbeatService(HB_MESSAGE_SUBJECT, hbStandardFields); } { //o Use setHeartbeatServiceField to change the state of the // COMPONENT-STATUS Field to indicate that the component has // transitioned from a startup/debug state to a running/green // state. I16Field componentStatusField = new I16Field("COMPONENT-STATUS", (short)1); connManager.SetHeartbeatServiceField(componentStatusField); } //o Wait for user input to end the program Log.Info("Publishing C2CX Heartbeat Messages indefinitely, press <enter> to exit the program"); Console.ReadLine(); //o Stop the Heartbeat Service connManager.StopHeartbeatService(); connManager.Cleanup(); } catch (GmsecException e) { Log.Error(e.ToString()); return(-1); } return(0); }
static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage device_message.exe mw-id=<middleware ID>"); return(-1); } Config config = new Config(args); InitializeLogging(config); //o Enable Message validation. This parameter is "false" by default. config.AddValue("GMSEC-MSG-CONTENT-VALIDATE", "true"); // TODO: Once available, replace this statement with usage of // ConnectionManager::getAPIVersion (See RTC 4798) Log.Info(Connection.GetAPIVersion()); try { ConnectionManager connManager = new ConnectionManager(config); Log.Info("Opening the connection to the middleware server"); connManager.Initialize(); Log.Info(connManager.GetLibraryVersion()); //o Create all of the GMSEC Message header Fields which will // be used by all GMSEC Messages // // Note: Since these Fields contain variable values which are // based on the context in which they are used, they cannot be // automatically populated using MistMessage. List <Field> definedFields = new List <Field>(); StringField missionField = new StringField("MISSION-ID", "MISSION"); // Note: SAT-ID-PHYSICAL is an optional header Field, according // to the GMSEC ISD. StringField satIdField = new StringField("SAT-ID-PHYSICAL", "SPACECRAFT"); StringField facilityField = new StringField("FACILITY", "GMSEC Lab"); StringField componentField = new StringField("COMPONENT", "device_message"); definedFields.Add(missionField); definedFields.Add(satIdField); definedFields.Add(facilityField); definedFields.Add(componentField); //o Use setStandardFields to define a set of header fields for // all messages which are created or published on the // ConnectionManager using the following functions: // createLogMessage, publishLog, createHeartbeatMessage, // startHeartbeatService, createResourceMessage, // publishResourceMessage, or startResourceMessageService connManager.SetStandardFields(definedFields); I32Field paramVal = new I32Field("DEVICE.1.PARAM.1.VALUE", 79); DeviceParam param = new DeviceParam("DEV parameter 1", "parameter 1 timestamp", paramVal); Device device1 = new Device("device 1", Device.DeviceStatus.RED); device1.SetGroup("group"); device1.SetRole("role"); device1.SetModel("model"); device1.SetSerial("1138"); device1.SetVersion("1.4.5.2.3.4.5"); I16Field devInfo = new I16Field("info", 5); device1.SetInfo(devInfo); I16Field devNum = new I16Field("num", 5); device1.SetNumber(devNum); device1.AddParam(param); //o Construct an DEV Message and add the Device values to it using (GMSEC.API.MIST.MESSAGE.DeviceMessage devMessage = new GMSEC.API.MIST.MESSAGE.DeviceMessage(DEV_MESSAGE_SUBJECT, connManager.GetSpecification())) { devMessage.AddDevice(device1); connManager.AddStandardFields(devMessage); connManager.Publish(devMessage); Log.Info("Published DEV message:\n" + devMessage.ToXML()); } connManager.Cleanup(); } catch (GMSEC_Exception e) { Log.Error(e.ToString()); return(-1); } return(0); }
static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage mnemonic_message.exe mw-id=<middleware ID>"); return(-1); } Config config = new Config(args); InitializeLogging(config); //o Set the GMSEC message specification version to be used to determine // what the structure of messages is for verification and the // construction of MistMessages config.AddValue("GMSEC-SPECIFICATION-VERSION", GMSEC_SPEC_VERSION); //o Enable Message validation. This parameter is "false" by default. config.AddValue("GMSEC-MSG-CONTENT-VALIDATE", "true"); Log.Info("API version: " + ConnectionManager.GetAPIVersion()); try { ConnectionManager connManager = new ConnectionManager(config); Log.Info("Opening the connection to the middleware server"); connManager.Initialize(); Log.Info("Middleware version: " + connManager.GetLibraryVersion()); //o Create all of the GMSEC Message header Fields which will // be used by all GMSEC Messages // // Note: Since these Fields contain variable values which are // based on the context in which they are used, they cannot be // automatically populated using MistMessage. FieldList definedFields = new FieldList(); StringField missionField = new StringField("MISSION-ID", "MISSION"); // Note: SAT-ID-PHYSICAL is an optional header Field, according // to the GMSEC ISD. StringField satIdField = new StringField("SAT-ID-PHYSICAL", "SPACECRAFT"); StringField facilityField = new StringField("FACILITY", "GMSEC Lab"); StringField componentField = new StringField("COMPONENT", "device_message"); definedFields.Add(missionField); definedFields.Add(satIdField); definedFields.Add(facilityField); definedFields.Add(componentField); //o Use setStandardFields to define a set of header fields for // all messages which are created or published on the // ConnectionManager using the following functions: // createLogMessage, publishLog, createHeartbeatMessage, // startHeartbeatService, createResourceMessage, // publishResourceMessage, or startResourceMessageService connManager.SetStandardFields(definedFields); //o Populate the Mnemonic Sample(s) MnemonicSample mSample = new MnemonicSample("MS1", new I32Field("MS1", 15)); mSample.SetEUValue(new F32Field("My EU", (float)15.0)); mSample.SetFlags(1); mSample.SetLimit(MnemonicSample.LimitFlag.RED_HIGH); // Implicitly set limit enable/disable with setting of limit mSample.SetQuality(true); mSample.SetStalenessStatus(false); mSample.SetTextValue("15"); MnemonicSampleList mnemonic_samples = new MnemonicSampleList(); mnemonic_samples.Add(mSample); //o Add the Mnemonic values to a Mnemonic object Mnemonic mnemonic = new Mnemonic("M1", mnemonic_samples); I16Field statusField = new I16Field("status", 5); mnemonic.SetStatus(statusField); mnemonic.SetUnits("units"); //o Determine which version of the GMSEC message specification // the ConnectionManager was initialized with uint version = connManager.GetSpecification().GetVersion(); //o Construct an MVAL Message and add the Mnemonic values to it using (MnemonicMessage mvalMessage = new MnemonicMessage(MVAL_MESSAGE_SUBJECT, "MSG.MVAL", connManager.GetSpecification())) { mvalMessage.AddMnemonic(mnemonic); //o If validating with the 2014 spec, the MSG-ID field is // required if (version == 201400) { mvalMessage.SetValue("MSG-ID", "MVAL Request MSG-ID would go here"); } //o Add the header fields to the MVAL message connManager.AddStandardFields(mvalMessage); Log.Info("Publishing MVAL message:\n" + mvalMessage.ToXML()); connManager.Publish(mvalMessage); } connManager.Cleanup(); } catch (GmsecException e) { Log.Error(e.ToString()); return(-1); } return(0); }
/// <summary>Copy constructor</summary> /// <param name="other">The other I16Field object to copy</param> public I16Field(I16Field other) { }