The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

xFx Technical Note: Configuring the Vendor name in messages and heartbeats


  • Subject: xFx Technical Note: Configuring the Vendor name in messages and heartbeats
  • From: Stuart Booth
  • Date: Fri, 26 Dec 2003 12:32:00 +0000

I thought I could start a series of, well, technical notes I suppose.
So if you have any xFx + xAP coding queryettes, do let me know and
I'll make up a specific example. I'll upload these to the web site
soon too.

#1 - Configuring the Vendor name in messages and heartbeats

I was recently asked how the Vendor name appears in messages and
heartbeats when using xFx, and how this can be configured to suit the
application, overriding any defaults related to me.

There are quite a few things you can do here, starting with the
app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>

<!-- Configures a header source value with this Vendor name if not
otherwise
supplied in the code -->
<add key="xAPHeaderSourceVendor" value="KCSoft"
/>

<!-- Configures a header source value with this Device name if not
otherwise
supplied in the code -->
<add key="xAPHeaderSourceDevice" value="Application"
/>

</appSettings>
</configuration>

That should override most other settings - although there is a
significant exception to that which I'll mention later.

Below is a test source file I knocked up which references xFx and
sends out regular heartbeats and a test message. It will handle the
Hub protocol if required or connect to a Hub as a Client as necessary.

using System;

using KCS.xAP.Framework.Message;
using KCS.xAP.Framework.Transport;

namespace VendorTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
xAPHeartbeatListener listener =
xAPListenerPortDetector.CreateConfiguredListener();

listener.Start();

xAPMessage msg = new xAPMessage ();
msg.Header = new xAPHeader ();
msg.AddMessageBlock(new xAPMessageBlock ("Block",
"Name"));

xAPSender.ApplicationSender.Send(msg);

Console.ReadLine();
listener.Dispose();
}
}
}

I set the Vendor in the .config file to Vendor22:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="xAPHeaderSourceVendor" value="Vendor22"
/>
</appSettings>
</configuration>

The code then starts a proper listener which pumps out heartbeats, so
it'll link with a Hub. I also send a basic message. All these appear
in Hub/Viewer as I'd expect:

Message received at Tuesday, December 23 2003 - 20:47:54.80
xap-hbeat
{
v=12
hop=1
uid=FFABCD00
class=xap-hbeat.alive
source=Vendor22.VendorTest.anya
interval=60
port=3644
pid=580
}

Message received at Tuesday, December 23 2003 - 20:50:51.34
xap-header
{
v=12
hop=1
uid=FFABCD00
class=Class.Type
source=Vendor22.VendorTest.anya
}
Block.Name
{
}

So, how do I go about configuring the Vendor? Well the absolute
default if none other is given ANYWHERE is, of course!, KCSoft. But
you can override that in the .config file as I've done in this
project.

However I provide a deeper setting in the xAPConfig class that I can
set which itself overrides the .config file. xFx goes to this location
to get the Vendor and Device that it is to use, and this is how I
hardwire "KCSoft" as the Vendor and, say, "Hub" or
"Viewer" as the
Device into *my* applications, so that they cannot be overridden in
the .config file. If you take the application source and rebuild it
then that's different.

I do this in Main:

static void Main()
{
// Fix the Vendor &amp; Device values to use wherever the values would
otherwise
be retrieved from the app.config file
xAPConfig.HeaderSourceVendor = xAPHeaderSource.DefaultSourceVendor;
xAPConfig.HeaderSourceDevice = "Hub";

Application.Run(new MainForm());
}

After that I don't think I ever manually create a source address. I
might tweak bits of it, usually the instance value or subaddress value
depending on the app. I haven't had the need to do that yet, as far as
I can remember anyway.

The next thing you probably should know about is changing the Vendor
at runtime. It's easy to setup a xAPMessage and twiddle with the
Source address as required. Altering the heartbeat being pumping out
by the application is a bit more finicky.

There's a copy of the Heartbeat that is being pumped out regularly
held in the xAPListener derived class created in the above code. The
message listener class can update the heartbeat pump with a new h/b,
but it won't let you just change little bits of it, as the h/b pump
works on a separate thread. The technique to update the
listener/heartbeat source address is as follows:

xAPHeartbeat hb = Listener.Heartbeat;
hb.Source.Vendor = "MyVendor";
hb.Source.Instance = "MyInstance";
Listener.Heartbeat = hb; // Force a deep copy into the heartbeat pump

If you set things up early enough, this isn't necessary. This code
originally came from the Hub/Viewer apps that allow you to alter the
instance component of the address at runtime on the toolbar.

Doing the xAPConfig trick in Main works around the need to do this
though, unless you need to change the Instance or DeviceID as I allow
in the GUI apps.

S
--
Stuart Booth <<a
href="/group/xAP_developer/post?postID=_vZgcScY7Vhpe-sz3_m2kgUZJm-bCO_Foet9ImQLMiFvYEa-f0J5eYsUpShytAg83sooGY3NqR0QADKemPSShacY">stuart@x...</a>>
xAPFramework.net - a xAP software development framework for .net

<a href="http://www.xapautomation.org/";>http://www.xapautomation.org/</a>
<a href="http://www.xapframework.net/";>http://www.xapframework.net/</a>





xAP_Development Main Index | xAP_Development Thread Index | xAP_Development Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.