Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="config">Configuration structure</param>
 public ApplicationLayer(Configuration config)
 {
     IsServer       = config.IsServer;
     UpdateInterval = config.AppUpdateInterval;
     // Init link layer
     link = new LinkLayer(config);
     if (IsServer)
     {
         // Init sync timer if instance is server
         UpdateTimer.Interval = UpdateInterval;
         UpdateTimer.Elapsed += Update_timer_Elapsed;
     }
     else
     {
         // Register event handler if instance is client
         link.OnMessageReceived += Link_OnMessageReceived;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Event handler for OnMessageReceived event of link
 /// </summary>
 /// <param name="sender">Link layer instance</param>
 /// <param name="msg">Event parameters</param>
 private void Link_OnMessageReceived(LinkLayer sender, LinkMessage msg)
 {
     if (!IsServer)
     {
         char addr = msg.Data[0];
         if (value_tracker.Keys.Contains(addr))
         {
             ApplicationPdu pdu = new ApplicationPdu()
             {
                 Address = addr,
                 Value   = Convert.ToInt32(msg.Data.Substring(1))
             };
             value_tracker[pdu.Address] = pdu.Value;
             Debug.WriteLine("APP-ADDR:" + pdu.Address + "-VAL:" + msg.Data.Substring(1));
             TriggerApplicationUpdate(pdu);
         }
     }
 }