LinuxMCE Forums

General => Developers => Topic started by: deathbellstar on January 27, 2010, 01:04:32 am

Title: noob wants to know a b c's of building divers for hardware
Post by: deathbellstar on January 27, 2010, 01:04:32 am
hi i wanted to know the what are the steps required to build a drivers to work with linux mce.
thank you
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: deathbellstar on February 18, 2010, 03:18:25 am
just kinda an outline dose not have to go into huge amount of detail . even a link so somewhere else if need be.thank you 
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on February 18, 2010, 03:41:02 am
Start with the Developers Guide in the wiki.

There are two ways to do this:

Do a checkout of the source tree, then.
(1) do a C++ based driver by creating a device template, and using DCEGen to create a project skeleton in your source tree
(2) do a GSD based device using Ruby snippets when creating a device template.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on March 29, 2010, 10:10:11 am
I got myself a Proliphix thermostat (IP thermostat with a web-server) and I thought it would be a nice first LinuxMCE project for me to develop a driver for it.

Are there any pro's or con's to the two options above for developing a driver? I gather the GSD based ruby scripting the easiest.
But setting up a build environment might be a good exercise for me any way, since I'll probably want to do more development in the future.

How will the choice between 1 and 2 affect the possibility to share the driver with other LinuxMCE users, or have LinuxMCE auto-detect the hardware?
I'm guessing it doesn't matter, but I thought I'd check before starting.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on March 29, 2010, 10:47:16 pm
The decision to go C++ or Ruby hinges on basically the fact that GSD assumes a singular communication channel, that is either serial or TCP.

If your device has for example a UDP port which it sends status messages, then you'd need to do a C++ driver, or if there are multiple sockets and things that need to be dealt with.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on March 30, 2010, 02:46:35 pm
It's a simple protocol; HTTP based requests over a TCP connection. So I'll give the ruby scripting a go.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on March 30, 2010, 06:53:56 pm
I suggest then, to look at the Panasonic IP Camera device template.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 01, 2010, 10:37:25 pm
Thanks, it helped quite a bit.

Can you tell me how can I determine the name of the input and output parameters of a command?
The "View Parameters" button of a command makes it easy to see the parameters, but it does not show what their name in the ruby scripting would be.
(I thought that it is always the parameter name in lower case, but what would be the name of the "On/Off" parameter of the "Set Fan" command of the thermostat then? I'm pretty sure the slash is a special character in ruby :) )

I was attempting to experiment to find out, but apparently the device isn't registering:
Code: [Select]
01      04/01/10 22:12:19.186           Climate_Plugin: COMMAND_Set_Fan_CONST ! <0x75947b90>
08      04/01/10 22:12:19.187           Received Message from 0 (unknown / ) to 75 (Proliphix NT series thermostat / Living Room), type 1 id 279 Command:Set Fan, retry none, parameters: <0x75947b90>
08      04/01/10 22:12:19.187             Parameter 8(On/Off): 1 <0x75947b90>
05      04/01/10 22:12:19.196           The target device 75 (routed to 75) has not registered. <0xb6d33b90>
05      04/01/10 22:12:19.237           Socket::ReceiveData 0x94e96b0 failed, bytes left 0 start: 1010000 1: 0 1b: 0 2: 0 2b: 0 m_Socket: 151 Incoming_Conn Socket 151 127.0.0.1 <0x75947b90>
05      04/01/10 22:12:19.237           Socket::ReceiveString2 ReceiveData failed m_Socket: -1 Incoming_Conn Socket 151 127.0.0.1 <0x75947b90>
05      04/01/10 22:12:19.237           TCPIP: Closing connection to -1003 (Router Dev #0) 0x94e96b0 m_Socket: -1 <0x75947b90>
05      04/01/10 22:12:19.237           Router::RemoveAndDeleteSocket 0x94e96b0 -1003 <0x75947b90>

I found on the forum that a reboot of the core might help (http://forum.linuxmce.org/index.php?topic=8746.0 (http://forum.linuxmce.org/index.php?topic=8746.0)), but after a reboot there are still not processes containing "Generic_Serial_Device" (as per http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device (http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device)). Is there something more I need to do to make the device register?
There's probably an error in a log somewhere describing what went wrong, but I can't find any mention of the device in the Spawn_Device.log or the DCErouter.log (until the above error that is), and I don't know where else to look. Any directions would be appreciated.

The auto-detection seems to work perfectly though. I filled in the appropriate data in the template and the thermostat was detected and added automatically.

Anyway, it's getting late. I'll take another look at it tomorrow.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 02, 2010, 04:37:53 pm
Hi, I managed to figure out what went wrong;
I forgot to add the Core to the "This device is controlled via category" field in the template. After that I removed the device and reinstalled it, and now it seems to work.
Also, it now generates logging in which I see the full Ruby code, and this logging also contains the name of the parameters, so that covers my other question.

I'll see how far I can get now
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 05, 2010, 02:58:49 pm
I got the driver working. The only thing missing is event generation.
I have a question about that; I can use the Command class to generate commands and events, but what should I fill in for the devidto_ parameter?
I found an example on the wiki that says "-1001", but I would like to know why that particular number, since I would expect that the event should be send to the DCERouter (devid 1).

Also, is there an easy way to add logging to the log file of the device? Currently I'm creating my own log file for debugging purposes, but I would like to have the logging of the final version appear in the file where it belongs, i.e. <DevId>_Generic_Serial_Device.log.
I can, of course, format my logging appropriately and append it to that file, but I suspect there may be an existing library function for that.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on April 05, 2010, 04:33:58 pm
Fantastic Progress!

If you look in Define_DeviceTemplate.h in src/pluto_main, you'll see that -1001 is the virtual device ID for the Event Device. This device # is intercepted by the DCE Router and is meant specifically for handling messages of type 2.

As for your second question, no. There is no specialized log function, look at the GSD code for Insteon PLM, and you can see the log function that ddamron wrote for his driver.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 06, 2010, 07:53:26 pm
Bit by bit I'm getting a functional driver :)
The event generation is now in, so my floorplan shows the current status of the thermostat.

The only problem is that the current status should, I think, be something like
ON/HEAT/HEAT/20
(19)
With the (19) on the second line indicating the current temperature, and the 20 at the end of the first line the current setpoint.
Only, the last part of the first line is missing somehow. I get the first half of the second "H", but the rest is not there.
I suspect this has nothing to do with my driver, but more with some other settings I have, but I thought I'd check.

Also, from some forum posts I gathered that the temperature can actually contain a period for more precision, to report temperatures like 19.5 degrees. But I'm wondering if anything breaks if I put a string containing a fractional value in the "Temperature Changed" event, since the specification of that event's parameter states that it should be an integer. Any thoughts on that?

Anyway, I still have some stuff to do. I have to clean up the logging it generates, and I want it to synchronize the thermostat's time with the DCERouter (to facilitate automatic summer-/wintertime changes).
After that I'll start updating the wiki on how to write a GSD driver in Ruby, gathering all the things I've had to look up in one location. (It turned out that the "plutoID" from the event generation example on the wiki does not exist, I had to check the code to find out that it had to be device_.devid_ instead.)
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 07, 2010, 09:50:20 pm
Ok, I think the driver's finished now. I'll test it for the next few days, and start updating the wiki.

I found out that the problem with the status on the floorplan is a known issue (http://svn.linuxmce.org/trac.cgi/ticket/133 (http://svn.linuxmce.org/trac.cgi/ticket/133) and http://wiki.linuxmce.org/index.php/Floorplan_texts (http://wiki.linuxmce.org/index.php/Floorplan_texts)). So I'll leave that alone for now, though it might be an interesting next project.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 11, 2010, 04:54:01 pm
Ok, I've been testing the driver and it seems to work OK.

Furthermore, I've updated the documentation:
http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device (http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device)
http://wiki.linuxmce.org/index.php/Proliphix_NT_series_thermostat (http://wiki.linuxmce.org/index.php/Proliphix_NT_series_thermostat)

What's the next step in sharing this driver with the rest of the LinuxMCE community?
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on April 11, 2010, 05:21:38 pm
first, do an sqlCVS update from the web admin, to make sure your database is up to date.
then,

create a trac ticket, describing your device.

check in the ir and dce repositories to check in your device, using the sqlCVS diff feature. use the anonymous checkin.

Please reference the trac ticket # in the comments section of the diff checkin.

We will then verify this, and check it into the database.

If this is a GSD device, this is all that needs to happen.

If this is a C++ device, then we need to do some additional work.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 11, 2010, 07:32:12 pm
Ok, done.

Trac Ticket number is #671 (http://svn.linuxmce.org/trac.cgi/ticket/671).
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on April 11, 2010, 07:43:24 pm
did you do an sqlCVS checkin of DCE and IR referencing the trac ticket?

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 11, 2010, 07:53:28 pm
Yep. Did something go wrong?
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on April 11, 2010, 08:13:17 pm
Everything was checked in, and I have verified that it is in the master database. This has been added as device template #2127

Thank you so much for your contribution :)

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 12, 2010, 10:14:34 am
You're welcome :)

It was actually quite fun, I'm planning on contributing more in the future.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: Kooma on April 12, 2010, 03:14:44 pm
Now that you succeeded so well and fast with the driver, would it be possible to document the whole process in wiki?

I know there are pages referenced already in this thread, but still, that would be a mega contribution.

I'm sure there a bunch of others like me that would like to compose some drivers or support for new devices, yet, it's too complicated (at least to me) with diffused and distributed information.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: grind on April 12, 2010, 10:19:38 pm
Kooma is totally right. A short How-To to create new Templates would be very usefull.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on April 13, 2010, 09:25:46 am
I've already updated the http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device (http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device) page, but the http://wiki.linuxmce.org/index.php/Edit_Device_Template (http://wiki.linuxmce.org/index.php/Edit_Device_Template) page I reference there can still use some work.
I'll see what I can do.

BTW: I've only made an ethernet based driver, and have only added ethernet based examples to the wiki page. If somebody has experience with writing drivers for the other communication methods (RS232, USB, etc.), feel free to add the drivers you wrote to the examples section of the page, and note any differences in creation. (For RS232 drivers the device data probably has to contain the COM port to be used by the core, instead of the TCP port, but I have no idea which id that field has.)
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on April 13, 2010, 04:15:52 pm
TCP is used when the TCP Port device data is specified. Serial Port is used when COM Port on PC device data is specified.
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: gonesurfing on April 18, 2010, 06:05:48 am
hi
can you point me in the right direction of a c++ interface driver using udp as an example
steve
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on April 18, 2010, 06:31:48 am
Look at the VistaICM2 driver in src/VistaICM2 of the source tree. Los93sol and I wrote it.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on May 17, 2010, 07:29:55 pm
I updated my system yesterday and it stopped working.

Took me a while to track it down; the id of the device template for my Proliphix driver had changed, during the update, but the template id referenced by already installed devices was not updated. Is this supposed to happen?

I had to do a manual mysql query to fix it, because according to the web-admin there was no such device (despite the fact that my thermostat was there in the list of devices :) ).
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: tschak909 on May 17, 2010, 08:53:01 pm
AIGH!

DO NOT DO MANUAL QUERIES TO MODIFY PRIMARY KEYS!

Put it back, and change your code to reference the new template #.

-Thom
Title: Re: noob wants to know a b c's of building divers for hardware
Post by: mhorst on May 17, 2010, 11:05:03 pm
No, I did NOT change the primary key. Upon re-reading my previous post, however, I can see how you can interpret it that way :)

I changed the foreign key in the Device table of the pluto_main database. My device with PK_Device=78 now has FK_DeviceTemplate=2127 (instead of FK_DeviceTemplate=2190). That's the only thing I changed, and I kinda considered that the obvious thing to do (I'll try express myself better next time :))

I was just surprised that the foreign keys in other tables do not change automatically when the primary key is changed.