Adding support for floorplan devices

From LinuxMCE
Jump to: navigation, search


I needed support for brightness sensors - particularly to display them on floorplan with current values. Since this procedure probably resembles adding support for other devices too, I'm posting my notes...

Major steps :

1. create proper template for device (watch proper category and parent settings)
2. create coresponding event, that will be used to report current values for floorplan device' state
3. add proper icon and other data in database


Since steps 1.-3. were already made for brightness sensors, I did only steps that follow below. I guess Dan can describe steps 1. to 3. much better...

First I wanted to discover how this feature already works for temperature sensors...

It goes like this :

First there is event called "Temperature changed" that reporting device (home automation controller for instance) creates with parameter of current temperature value. Message gets through DCERouter to Climate Plugin that does this

else if( pMessage->m_dwMessage_Type==MESSAGETYPE_EVENT && pMessage->m_dwID==EVENT_Temperature_Changed_CONST )
{
 // Replace the current temp
      string sLevel = pMessage->m_mapParameters[EVENTPARAMETER_Value_CONST];
      string sCurrentState = pDevice->m_sState_get();
      string::size_type pos = sCurrentState.find('(');
      if( pos!=string::npos )
             sCurrentState = sCurrentState.substr(0,pos-1); // Get rid of the current temp
      pDevice->m_sState_set(sCurrentState + " (" + sLevel + ")");
}

in

void Climate_Plugin::PreprocessClimateMessage(DeviceData_Router *pDevice,Message *pMessage)

and sets state of device to reported value.

Then Orbiter plugin at line 1367 and procedure

void Orbiter_Plugin::CMD_Get_Current_Floorplan(string sID,int iPK_FloorplanType,string *sValue_To_Assign,string &sCMD_Result,Message *pMessage)

does this (line 1429) :

pFloorplanInfoProvider->GetFloorplanDeviceInfo(pDeviceData_Router,fpObj->m_pEntertainArea,fpObj->Type,iPK_FloorplanObjectType_Color,iColor,sDescription,OSD,PK_DesignObj_Toolbar);

FloorplanInfoProvider is actually coresponding plugin that provides more info about floorplan object. In Climate plugin there is this procedure :

void Climate_Plugin::GetFloorplanDeviceInfo(DeviceData_Router *pDeviceData_Router,EntertainArea *pEntertainArea,int iFloorplanObjectType,int &iPK_FloorplanObjectType_Color,int &Color,string &sDescription,string &OSD,int &PK_DesignObj_Toolbar)
{
switch(iFloorplanObjectType)
{
case FLOORPLANOBJECTTYPE_CLIMATE_THERMOSTAT_CONST:
         PK_DesignObj_Toolbar=DESIGNOBJ_grpThermostatControls_CONST;
         break;
case FLOORPLANOBJECTTYPE_CLIMATE_THERMOMETER_CONST:
         PK_DesignObj_Toolbar=0;
         break;
case FLOORPLANOBJECTTYPE_CLIMATE_WEATHER_STATION_CONST:
         PK_DesignObj_Toolbar=0;
         break;
case FLOORPLANOBJECTTYPE_CLIMATE_DAMPER_CONST:
         PK_DesignObj_Toolbar=0;
         break;
case FLOORPLANOBJECTTYPE_CLIMATE_POOL_CONST:
         PK_DesignObj_Toolbar=DESIGNOBJ_grpPoolControls_CONST;
         break;
case FLOORPLANOBJECTTYPE_CLIMATE_SPRINKLER_CONST:
         PK_DesignObj_Toolbar=DESIGNOBJ_grpSprinklerControls_CONST;
         break;
};
if( (OSD=pDeviceData_Router->m_sState_get())=="OFF" )
         iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_OFF_CONST;
else
         iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_COOLING_CONST;
}

and most important is this line (near bottom) :

OSD=pDeviceData_Router->m_sState_get()

It basically reads state of device and puts it into OSD. OSD is string that will get displayed beside icon.

Now I'll try to replicate everything similar to Lighting Plugin and brightness sensors :

4. Lighting Plugin

Added this line

       case FLOORPLANOBJECTTYPE_BRIGHTNESS_SENSOR_CONST:
               OSD = pDeviceData_Router->m_sState_get();

to

void Lighting_Plugin::GetFloorplanDeviceInfo(DeviceData_Router *pDeviceData_Router,EntertainArea *pEntertainArea,int iFloorplanObjectType,int &iPK_FloorplanObjectType_Color,int &Color,string &sDescription,string &OSD,int &PK_DesignObj_Toolbar)


and adding those lines

       else if( pMessage->m_dwMessage_Type==MESSAGETYPE_EVENT && pMessage->m_dwID==EVENT_Brightness_Changed_CONST )
       {
       	// Replace the current level
       	string sLevel = pMessage->m_mapParameters[EVENTPARAMETER_Value_CONST];
       	string sCurrentState = pDevice->m_sState_get();
       	string::size_type pos = sCurrentState.find('(');
       	if( pos!=string::npos )
       		sCurrentState = sCurrentState.substr(0,pos-1); // Get rid of the current level
       	pDevice->m_sState_set(sCurrentState + " (" + sLevel + ")");
       }

to the bottom of

void Lighting_Plugin::PreprocessLightingMessage(DeviceData_Router *pDevice,Message *pMessage) 


Compiling Lighting and Climate plugin :

Versions after 0810

1. Read the Developing a DCE Device page for proper documentation on checking out the source tree, then make the appropriate changes from above.

2. Compile the Climate Plugin.

cd src/Climate_Plugin
make so

3. Copy the Climate Plugin to /usr/pluto/bin to test. Then reload the router.

cp Climate_Plugin.so /usr/pluto/bin

4. Make a Diff.

svn diff > describe-the-changes-in-the-filename.diff

5. Go to trac: http://svn.linuxmce.org/ and create a bug ticket, and submit the resulting patch diff file.

Versions of LinuxMCE before 0810

SVN checkout of 710 stable release (it's more convenient to work on currently released version of LinuxMCE)...
The minimal routine:
1) take the latest stable branch - e.g. 710

 svn co http://svn.linuxmce.org/svn/branches/LinuxMCE-0710/

2) build it - actually you don't need to build every package- just cd to the desired folder and try to run make there. if you will get missing libs, then you should go to the corresponding library folder and build it. For Lighting and Climate plugins following is needed.


cd LinuxMCE-0710/
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;


cd pluto_main
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;
make

cd ../SerializeClass/
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;
make 
cd ../DCE/
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;
make
cd ../PlutoUtils
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;
make

cd ../Lighting_Plugin/
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;
make so


cp  /usr/pluto/bin/Lighting_Plugin.so  /usr/pluto/bin/Lighting_Plugin.orig.so
cp -f ./Lighting_Plugin.so /usr/pluto/bin/Lighting_Plugin.so

cd ../Climate_Plugin/
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_defines->/-DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES -I\/opt\/libxine1-pluto\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include -I\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/include\/SD/' -i '{}' \;
find . -iname Makefile -exec sed -e 's/<-mkr_t_compile_libs->/-L\/opt\/libxine1-pluto\/lib -L\/opt\/libsdl1.2-1.2.7+1.2.8cvs20041007\/lib/' -i '{}' \;
make so

cp  /usr/pluto/bin/Climate_Plugin.so  /usr/pluto/bin/Climate_Plugin.orig.so
cp -f ./Climate_Plugin.so /usr/pluto/bin/Climate_Plugin.so


Problems !!!!

If you need any new DCE Event or DCE Command added, then you have to work with developers, cause it must be entered into main database first, so you can get right inlude files to use your addition.