יום חמישי, 30 במאי 2013

UPNP

In order to mimic an hardware device sending a UPNP message we use the windows UPNP Api.
The device simulator that send UPNP messages is build from the UPNPSampleDimmerDevice sample.
The sample is build from 2 parts :
Capture 
The RegDevice is used to send the device registration notification, and the UPNPSampleDimmerDevice is used in order to implement a service that the client could query for the device state .

The UPNP device registration request is done using the following code :

  1: #include <upnphost.h>
  2: 
  3:  IUPnPRegistrar *pReg = NULL;
  4: 
  5:  hr = CoCreateInstance(
  6:       CLSID_UPnPRegistrar,
  7:       NULL,
  8:       CLSCTX_LOCAL_SERVER,
  9:       IID_IUPnPRegistrar,
 10:       (LPVOID *) &pReg
 11:       );
 12: 
 13:    hr = pReg->RegisterRunningDevice(desDoc,punk,initBSTR,resourcePathBSTR,lifeTime,&DeviceID);

The request main parameters are :
desDoc :The device description data .


punk – The device control com interface .


resourcePathBSTR – Path of the directory containing the device description file and the icons


lifetime – The announcements sending cycles in seconds.


The method returns the generated DeviceID


The demo description data :

  1: <?xml version="1.0"?>
  2: <root xmlns="urn:schemas-upnp-org:device-1-0">
  3: <specVersion>
  4:     <major>1</major>
  5:     <minor>0</minor>
  6: </specVersion>
  7: 
  8: <device>
  9:     <pnpx:X_deviceCategory xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">HomeAutomation</pnpx:X_deviceCategory>
 10:     <pnpx:X_hardwareId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">Microsoft/SampleDevice/10000/urn:microsoft-com:device:SampleDimmerDevice:1</pnpx:X_hardwareId> 
 11:     <df:X_containerId xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation">{8C7B310D-90F8-40D4-B5EA-71D81821DEA6}</df:X_containerId>
 12:     <deviceType>urn:microsoft-com:device:DimmerDevice:1</deviceType>
 13:     <friendlyName>UPNP SDK Dimmer Device Hosted by Windows</friendlyName>
 14:     <manufacturer>Microsoft</manufacturer>
 15:     <manufacturerURL>http://www.microsoft.com/</manufacturerURL>
 16:     <modelDescription>UPnP SDK Device Host Dimmer Device 1.0 </modelDescription>  
 17:     <modelName>Dimmer1.0</modelName>
 18:     <modelNumber>1-00-00</modelNumber>
 19:     <modelURL>http://www.microsoft.com/</modelURL>
 20:     <serialNumber>0000001</serialNumber>
 21:     <UDN>uuid:RootDevice</UDN>
 22:     <UPC>00000-00001</UPC>
 23: 
 24:     <serviceList>
 25:         <service>
 26:             <serviceType>urn:microsoft-com:service:DimmerService:1</serviceType>
 27:             <serviceId>urn:microsoft-com:serviceId:DimmerService1.0</serviceId>
 28:             <controlURL></controlURL>
 29:             <eventSubURL></eventSubURL>
 30:             <SCPDURL>DimmingService_SCPD.xml</SCPDURL>
 31:         </service>
 32:     </serviceList>  
 33: 
 34:     <presentationURL>DimmerPresentation.htm</presentationURL>
 35: </device>
 36: </root>
 37: 

The upnp service send 4  multicast messgases :
Capture1


Capture2


 Capture3


Capture4


 Capture5


Creating a device description here

אין תגובות:

הוסף רשומת תגובה