Author Topic: noob wants to know a b c's of building divers for hardware  (Read 19070 times)

deathbellstar

  • Making baby steps
  • Posts: 2
    • View Profile
noob wants to know a b c's of building divers for hardware
« 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

deathbellstar

  • Making baby steps
  • Posts: 2
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #1 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 
« Last Edit: February 18, 2010, 03:20:42 am by deathbellstar »

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #2 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

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #3 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.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #4 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

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #5 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.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #6 on: March 30, 2010, 06:53:56 pm »
I suggest then, to look at the Panasonic IP Camera device template.

-Thom

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #7 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), 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). 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.

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #8 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

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #9 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.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #10 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

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #11 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.)

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #12 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 and http://wiki.linuxmce.org/index.php/Floorplan_texts). So I'll leave that alone for now, though it might be an interesting next project.

mhorst

  • Veteran
  • ***
  • Posts: 72
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #13 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/Proliphix_NT_series_thermostat

What's the next step in sharing this driver with the rest of the LinuxMCE community?

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: noob wants to know a b c's of building divers for hardware
« Reply #14 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