| Forum: System Design |
03. Jul 2008, 08:45 CET | Link |
I just took a look at Christian's Roadmap and I'm most interested in discussing the Integration Of RS232 controlled Devices. I doubt there's much I can do on the IR front but programming hardware I have half a chance.
So what are the plans. I was thinking of a 'device driver' (I don't know what you call it under java, a controller?). This driver would accept on/off, numeric values (for things like frequency or analog output) or strings. I can't think of other data types just yet. Of course I not being a Java developer I may just be full of it. Any comments, ideas, pointer?
30 Replies: | |||
|---|---|---|---|
Frankly, for device drivers you might be better off with native C. Then just provide an API for Java services to use it through socket/file/other io
Juha Lindfors, OpenRemote |
|||
Juha Lindfors wrote on Jul 03, 2008 11:33: Actually I was thinking about having this handled by the Java server software but IO daemon works too. Alright a daemon it is then, it will be written in C. So how many C coders do we have? Also do you have any ideas for primitives to talk to the daemon? Example: A1 On, or maybe 02.01.53 dim 50%. I won't be keeping a database in the daemon (i.e.: A1 is the kitchen light) and I won't be keeping states of the device though I could poll some devices. What do you think? MarcF, what was the outcome of talking to Dan Lanciani and his daemon code. Can we use it or do I need to start writing a new daemon, which might not be a bad idea, threading this time. |
|||
Neil Cherry wrote on Jul 03, 2008 15:32: I have trust issues. I don't trust anything in the server to talk to hardware directly ;-) However, if writing a new daemon is a significant effort for you, I can reconsider. Neil Cherry wrote on Jul 03, 2008 15:32: You :-) I'm too lazy to go back to C. Neil Cherry wrote on Jul 03, 2008 15:32: I'm all ok as long as I can write simple strings to it. Neil Cherry wrote on Jul 03, 2008 15:32: Yes, state and mappings belong to the server (compiled by the user on the website - A1 is my kitchen light) and then downloaded to server (still assuming no offline mode yet). State of A1 as well on the server. A1 is ON, UI will reflect that state, physical state change (light switch manually off) we can update the state on the server with polling. Polling I suppose you can also leave for the server to initiate? Unless there's a benefit in having the driver do constant polling?
Juha Lindfors, OpenRemote |
|||
Neil Cherry wrote on Jul 03, 2008 15:32: MarkS is a great C coder as well :) I haven't talked to Dan here. He didn't really respond to my overture. if it is a bunch of work, maybe we can license the original work. He said he was open to CC re-licensing which may be good for our short term. Long term having a bunch of people hold copyright is not a problem, where it gets messy is on the re-licensing... |
|||
I can't help much on the programming serial port front, but I have played around with a few devices and what I've found is that old school telnet on window or kermit on linux can control any device and see feedback. To test I've configured the appropriate settings (usually 8-n-1) and connected with a cable and copied and pasted ASCII commands into the terminal screen. What I'm trying to say is that I'd be very surprised if the built in API for an OS wouldn't already have most of the functionality required. I think Juha might be on to something though, all that may be required is for a Java API to be written so you can access the OS level device (assuming one doesn't exist already). From a usability standpoint, I'd just like to point out (again) that however it is designed that a user should be able to edit a config file (xml maybe) that maps strings (hex, ascii or a combination of the two) to commands and maybe even pre-defined buttons for the UI. |
|||
Ben Drawbaugh wrote on Jul 03, 2008 14:29: It seems like not everyone as seen this. :) |
|||
Ben Drawbaugh wrote on Jul 03, 2008 14:29: It would be line oriented, basically what you do is type in an ASCII string: A1 on or 02.03.45 dim 50% or something similar and the daemon would send the command to the device. What I'm trying to say is that I'd be very surprised if the built in API for an OS wouldn't already have most of the functionality required. I'm not aware of any OS with this kind of API. This is something I've written in my daemons (based on Dan Lanciani code). I think Juha might be on to something though, all that may be required is for a Java API to be written so you can access the OS level device (assuming one doesn't exist already). From a usability standpoint, I'd just like to point out (again) that however it is designed that a user should be able to edit a config file (xml maybe) that maps strings (hex, ascii or a combination of the two) to commands and maybe even pre-defined buttons for the UI. Users do not speak to the daemons. The server speaks to the daemons. That way only standard commands can be issued. The standard is something we need to work on. I like to call these primitives, these primitive would be also used for status of the devices.
Hmm, this sounds like I need a daemon tool kit. I guess I'll rewrite the daemon to not use Dan's code. Thoughts, comments? I will need help coming up with some kind of standard language to have a conversation. I also think the Java code will need a way of asking what the capabilities (what makes up the language) of the daemon. |
|||
Neil Cherry wrote on Jul 03, 2008 16:01: I think you might be pushing too much logic into the driver. The language is needed only between the UI and server to translate a command like ON/OFF to whatever bits needs to be written to serial. What I was thinking about is basically Java Communications API but behind an IPC. So we can partition the java services from the native layers without having to run separate JVMs. so basically just this to write: outputStream = serialPort.getOutputStream(); serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); outputStream.write(messageString.getBytes()); Check out the Java Comms API, that's probably it, if it looks like too much work, we can just use it direct (but I still have trust issues with allowing native code to crash the VM)
Juha Lindfors, OpenRemote |
|||
Juha Lindfors wrote on Jul 03, 2008 23:52: Okay, I'm confused, when I was talking about a 'device driver' what I meant was software that talks to the hardware and translates and handles the protocols. The CM11A is relatively easy to deal with, the CM15A a little more complicated, the Insteon controllers a lot more complicated. Here's an example:
A lot of there seem stupid but they are useful also the format of the command depends on the device type (sorry this section is 35 pages long). The responses are dependent also on the device. According to the document (Dev Guide) there is supposed to be a response to manual changes (turn the lamp switch on or press the module button). Then there is the database linking. You can't control a device unless it's registered with the controllers and modules. These are the kinds of things that needs to be hidden in the daemon but some agreement between the server and daemon is needed (how does the server learn about a new module that the daemon has registered) |
|||
<blockquote> _Neil Cherry wrote on Jul 04, 2008 03:53:_<br/> Okay, I'm confused, when I was talking about a 'device driver' what I meant was software that talks to the hardware and translates and handles the protocols. </blockquote> Ok... translating and handling protocols is definitely better done in the server. Christian's working on the builder stuff and that is going to be sending simple "commands" like SWITCH ON to the server. The server then takes that commands and translates it to whatever bits needs to be pushed into serial for that particular device to understand it needs to be switched on. The controller is not just a gateway, once it talks to the native layer it already should know what bits the command translates to. Your daemon just pushes those through to serial. If we don't do this then we'd need to figure out a way for you to get your mappings from the server (coming from CB's builder) and I see little benefit in pushing this down to such a low layer. In fact, it just pushes trivial mapping code to C layer when we can handle it with much less effort in Java layers. So yes we were talking across about what a driver means. It just needs to allow me to push bytes through: byte in from socket, byte out to serial port. All the logic (what device is this, what command is being executed) should be in the server. So this is basically a replacement for the Java Comms API which does this using Java's native interface. <blockquote> _Neil Cherry wrote on Jul 04, 2008 03:53:_<br/> The CM11A is relatively easy to deal with, the CM15A a little more complicated, the Insteon controllers a lot more complicated. Here's an example: = Get INSTEON Engine Version = ping = ID Request = Light On = ... (there are hundreds more) A lot of there seem stupid but they are useful also the format of the command depends on the device type (sorry this section is 35 pages long). The responses are dependent also on the device. </blockquote> Right, and this is all in the device XML database... User chooses a device from the GUI, maps button X to command LIGHT ON. This configuration gets downloaded to home controller. It deploys this, pushes the GUI definition to open remote controller (or creates a web interface equivalent), and prepares to send a certain sequences of bytes to serial when a command comes in: e.g. A1 LIGHT ON translates to "A1 is connected to my serial, need to write there, command LIGHT ON for serial means bytes 0x03 0xAF 0xFF" or whatever the line protocol is. If A1 is connected to somewhere else, it does the same using whatever line protocol is needed there. Bottom line is we can get this done faster in the Java layers. <blockquote> _Neil Cherry wrote on Jul 04, 2008 03:53:_<br/> According to the document (Dev Guide) there is supposed to be a response to manual changes (turn the lamp switch on or press the module button). Then there is the database linking. You can't control a device unless it's registered with the controllers and modules. These are the kinds of things that needs to be hidden in the daemon but some agreement between the server and daemon is needed (how does the server learn about a new module that the daemon has registered) </blockquote> Again I don't follow why this needs to be in the daemon. It sounds like it makes the whole thing more complicated (your point about server needing to learn about new registered modules). We can do all this in the server. In addition to pushing bytes through, we need to have a listener mechanism to get back the responses (probably something similar to what the Java comms API does). So your original thought of doing this in Java was correct, I just misunderstood what you meant by a device driver. So yes Wade calls this a controller in his API terminology but we can do whatever Java class for this. Doesn't matter. The daemon part just exists to insulate the VM.
Juha Lindfors, OpenRemote |
|||
Okay so the daemon is then to receive bytes and transmit them to the port (it may not just be the serial port but USB also). So am I receiving bytes not lines (lines are terminated by <CR><LF>)? Juha, I do have one question. Why would the writeBytes hang on talking directly to the serial port and not to the daemon? MarcF, I'd say that this pretty much says no to the iPhone talking directly to the PODs as the heavy logic is in the server. I doubt you want to replicate that logic in the iPhone. |
|||
Neil Cherry wrote on Jul 04, 2008 16:38: Yes, or anything else we might come up with down the road. Neil Cherry wrote on Jul 04, 2008 16:38: Yep :-) Neil Cherry wrote on Jul 04, 2008 16:38: What I want to avoid is a bad implementation crashing the JVM, like this: # # An unexpected error has been detected by HotSpot Virtual Machine: # # SIGSEGV (0xb) at pc=0x4c94986c, pid=2673, tid=2979568528 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_12-b04 mixed mode, sharing) # Problematic frame: # C [libc.so.6+0x6886c] # There's no difference in this regard with libc crashing (what Java Comms uses via JNI to talk to serial) or your daemon crashing. Bad code is bad code. The difference is I am separating your daemon code to another process space, your daemon crashes, it won't bring down the server with it. If we use JNI direct from Java to serial then you can see what might happen above, ideally it wouldn't but there's no such thing as perfect code.
Juha Lindfors, OpenRemote |
|||
Juha, when you're doing the socket programming are you going to use ip:port (I don't remember the Java format)? Using this makes it easy to put the daemon code on the POD, though I could listen on a local socket and IP port. Also since the daemon code is much lighter in weight now, the POD can be 'smaller' (less MHz and ram/rom). One last advantage which is an odd one; I can setup a daemon and the person doing the server programming can use my devices here at home until they get their own device (we'll work out connectivity details). The last part is not a big deal but a cool side effect. I'll have 2 NSLU2s (RS232 for now, USB drivers a little later) setup as PODs here for whatever we need them for. Hmm, this simple daemon turns out to be a good thing. Sorry I was so obstinate about this subject (won't be the last I'm sure). I'm writing the daemon code right now and I'll let everyone know when it's done. I'm using the userver code (GPL2, so we have no license issues). I don't think MarcF will have a problem using GPL code here as it is isolated from the rest of the code (no cross license issues) and won't be a problem as it's a tiny part of the over all code. |
|||
Neil Cherry wrote on Jul 04, 2008 18:43: Yes. One last advantage which is an odd one; I can setup a daemon and the person doing the server programming can use my devices here at home until they get their own device (we'll work out connectivity details). Cool, remote test lab should be useful. Neil Cherry wrote on Jul 04, 2008 18:43: In the history of technical arguments on open source mailing lists you gave in easily, in a day. Had this gone on for two weeks, unresolved and then resurface every two months or so, now that gets frustrating ;-)
Juha Lindfors, OpenRemote |
|||
Juha Lindfors wrote on Jul 04, 2008 19:03: Let's face it I've got enough of this junk, might as well make use of it. :-) Neil Cherry wrote on Jul 04, 2008 18:43:In the history of technical arguments on open source mailing lists you gave in easily, in a day. Had this gone on for two weeks, unresolved and then resurface every two months or so, now that gets frustrating ;-) Technically it was two days, two days is long enough. This is internet time, but two weeks is intolerable. I'm not very patient (I want answers and I want them now. Where's that search engine? g answer to everything There were two things I could do, first was to continue to argue and eventually go off and create my own software (hard to do and I've made no progress with that so far) and the other was to listen to the arguments, follow along and see what progress we make. At some point a decision needs to be made to move forward. Even a bad decision (I'm not saying this was) is better than no decision. I need code and I need it now! The reason I 'gave' in was that I'm trying to be flexible. I tried it my way in the past (fancy daemon) and got nowhere. Time to try something else. I can't think of everything but as a team we can. I've written lots of software but it's only pieces. I'm tired of pieces I want a complete extensible system. This way seems more likely to succeed. |
|||
Neil Cherry wrote on Jul 04, 2008 18:43:
This thread is getting a little long in the tooth but I am glad you are liking the simplicity! There is nothing in it and it crashes less! How about that! I know juha had you at I'm writing the daemon code right now and I'll let everyone know when it's done. I'm using the userver code (GPL2, so we have no license issues). I don't think MarcF will have a problem using GPL code here as it is isolated from the rest of the code (no cross license issues) and won't be a problem as it's a tiny part of the over all code. OK. |
|||
Neil Cherry wrote on Jul 03, 2008 16:01: But this would mean that we'd need to push down the mappings of A1 -> command into your daemon. That's not what we need the daemon for. We already have the server for it. Daemon exists just to separate the server and native layers into different process spaces. Ben is correct, this should really be just pushing the commands through from the server to serial.
Juha Lindfors, OpenRemote |
|||
Juha Lindfors wrote on Jul 03, 2008 23:59:
Right, he should just be writing bytes as is without caring for mappings that is why we are All juha is really saying is that he doesn't want writeByte() to hang on him or crash on him. Also writing bytes should be an easier C implementation than dealing with mappings. Let java do what java does: mappings. Asynchronous calls, fire and callbacks and all interesting semantics may apply to different hardware devices. |
|||
marc fleury wrote on Jul 04, 2008 04:40:
Hmm, I understand what you are saying but I view the daemon as a layer of the OSI model, it should hide the interface details (as well as keeping things from hanging). You need to know the module details not the interface details. Unfortunately that includes translating string I'm not saying it can not be done, you can move the interface layer back to the server. As my friend likes to say, you can move complexity but you can not remove it. |
|||
Christian Bauer wrote on Jul 03, 2008 15:45: A User editing an XML file? No way, that has to be hidden by the Java server/UI. Christian, I'm not sure how that's going to apply to the daemon. Do we start another daemon? Does the daemon dynamically add the device and it manages all the devices? I'm not sure how to approach this yet. For now let me write a daemon to handle just one device and we'll go from there. |
|||
Neil Cherry wrote on Jul 03, 2008 16:06:
Of course, that's the Christian, I'm not sure how that's going to apply to the daemon. Uh, I don't think it is related at all? I was replying to Ben who was saying we need a UI that maps buttons to some commands that are then passed around and transformed until they end up on the destination device - through whatever protocols and layers and transports we create. |
|||
Christian Bauer wrote on Jul 03, 2008 16:45: Sorry I was thinking how a user goes about adding a new device to the system. There would have to be some kind of UI to add the device but the inner working become 'interesting'. That's the part where I wasn't sure how it would be applied to the daemon (DeviceManager?). This is why I try to stay away from the UI. I haven't a clue how to do it. Now the device interface that I can handle. |
|||
Neil Cherry wrote on Jul 03, 2008 16:06: No, not a user per se. But an integrator or smart DIY'er who wants to use the product but doesn't want to wait around for someone else to add support for their device. I have done this for every RS-232 device I have with the current HA software I'm using. There are a few reasons for this. 1. It is nearly impossible to add support for every device known. 2. Testing a new device without owning the device can be impossible and who wants to buy the latest $6k HDTV just to test to see if you got the protocols right. If everyone shares their XML config files then they will be there to use and to include with the software. |
|||
Ben Drawbaugh wrote on Jul 03, 2008 17:36: yep, you got it ben. This needs to be done once by someone who owns the device, after that it will go into our database and the rest of the users can choose it from the pretty web UI, never needing to see XML unless they want to fix it or learn from it.
Juha Lindfors, OpenRemote |
|||
Neil Cherry wrote on Jul 03, 2008 16:06: he he Neil has discovered java and already the idea of a user interacting with an XML file gives him the creeps. Good, good! For sure this is where a good internet app can help. |
|||
Ben Drawbaugh wrote on Jul 03, 2008 14:29: Right, which is why I don't want the daemon to be doing the mapping cause then we need to be pushing this stuff all the way down to native layers which seems unnecessary to me.
Juha Lindfors, OpenRemote |
|||
Author: Linux Smart Homes For Dummies