|
Axon microserver
InterplayMedium Hardware |
Codex of synaptic interfaces creation Let me point to several rules that important for keeping in frames of project concept and style:
How to create Synapse and integrate it with AXON microserver In general, the creation of synapse can be divided into two stages:
Let's consider creation of synapses in example of the 'RFID monitor', available in standard AXON microserver package. Don't forget to set the local environment as explained in this article and download and untar templates. 1. Directories structure As you already know from architecture article, all synapses placed in /synapses/{synaptic group}/ sub-folder. So for beginning
2. CSS layout Open /sensor.html form templates. There are two fragment market as <!-- this is a custom bottom interface begin --> <!-- this is a custom bottom interface end --> and <!-- this is a custom synapse interface begin --> <!-- this is a custom synapse interface end --> This is a fragments, which refers to main and bottom standard interfaces of the synapse. Best idea is to start mould your html interface right there and copy that in corresponding file (maininterface.tmpl and bottominterface.tmpl) when you finished with layout. Please pay attention that you need to change paths in CSS on absolute relatively to the root of AXON package after finishing. For example:
open result it in 'http://localhost' and check it out whether you have everything displaying fine in your new synaptic interface. 3. Server-side scripts API You synapse.lua micro-engine should have obligatory functions: startsynapse, stopsynapse and redrawinterface if arg[1] == "startsynapse" or arg[1] == "" or arg[1] == nil then end if arg[1] == "stopsynapse" then end if arg[1] == "redrawinterface" then end
in first lines of the synapse.lua script define all common variables which may be necessary to change in case of porting. In case of RFID monitor that was: deviceString = "_NewRoad_System_PS2_Interface-event" -- this is RFID reader indentifier. check it out by "ls -l /dev/input/by-id/" event="event1" -- this is a event file of HID device As you see, functions should calls by arguments. So it's easy to test whether everything works fine.
Thus, your sunapse.lua should works independently. All other functionality of microengine could be done in the same way. Handling the errors All errors could be printed to standard output. Do not be misled with stdout files in each synapse. Thous files are produced by core engine and contains the same output which synapse has been normally printed. It's have two reasons:
Except of that, Lua doesn't produce any debug messages in html format as php does. So, core engine does it by handling this outputs. JavaScript and client side integration After debugging your synapse.lua micro-engine and getting it works fine you need to integrate it into the html interface. Core engine has common JS which just caring about synaptic bottom pop-up menu. But it has own copy of jQuery library. So you can easly use jQuery methods in your synapse JS handler too. Create your handlers. Just keep in mind this several recomendations:
This is an example of call of the rfidoutput file, which could be created with RFID daemon each time, when sensor detects new token:
Couple of words about error handling: As you see, I use this sentence to check for error:
var res = getData ( 'synapse.lua', href );
if ( res.indexOf("Success") == -1 ) alert (res);
Core synapse.lua output all errors or "Success" after all calls. So would be good to handle it with alert(...) message. in the case of RFID monitor it was used on synapse start to message the error of devise detection. That's all. Last thing: add README file with short instructon if necessary, description of the synapse and don't hesitate to prepare .deb and .ipk packages! (keep the current paths for it "/var/axon/....". Most probably it will not changed in the future) (needs to be documented!). Write here about your synapse and announce it in mailing list. |