|
|
Zeile 1: |
Zeile 1: |
− | == Ein kleiner Einstieg in Control6 ==
| + | #REDIRECT[[:Kategorie:Control6]] |
− | | |
− | === So fängt man an ===
| |
− | | |
− | der Skript Code der einkompiliert wird muss in die Datei control6/control6.src eingetragen werden.
| |
− | | |
− | === Die Befehle ===
| |
− | | |
− | === Fallstricke ===
| |
− | | |
− | === 6Control/Control6 ===
| |
− | Wir haben 6Control nach Control6 umbenannt, denn der C Compiler mag keine Nummer vor Zeichen bei Funktionnamen
| |
− | | |
− | == Was ist Control6? ==
| |
− | | |
− | Control6 ist eine art Skripting mit protothreads das eine art Basic für Ethersex
| |
− | darstellen soll. Die Skripte werde in C Code übersetzt die dann wiederum Compiled werden.
| |
− | Die Skipte sind somit statisch und nur durch Neuprogrammierung veränderbar.
| |
− | | |
− | == Wie schreibe ich ein Control6 Skript ==
| |
− | | |
− | Every 6control scipt must be started with `CONTROL_START' and ended with
| |
− | `CONTROL_END'. Within this body you can define various actions, which are
| |
− | started with ACTION($action_name) and ended with ACTION_END($action_name),
| |
− | here the $action_name must be replaced with an unique action identifier.
| |
− | | |
− | Inside the action "tags" you add the code for the specific action. Outside of
| |
− | all actions you can write down, how the 6control script should react on
| |
− | events. For example this piece of code, which is placed outside of all
| |
− | actions ( for this example you must enable clock support in your ethersex
| |
− | firmware )
| |
− | | |
− | <pre>ON CLOCK_MIN == 5 DO THREAD_START(nice_gaudi) END</pre>
| |
− | | |
− | Here you see how to write such an event handler, this starts the thread
| |
− | `nice_thread', if the minute field of the time is exactly 5 (e.g. 05:05 or
| |
− | 23:05). But be aware of the THREAD_START command. This starts the thread only
| |
− | if it isn't started already. So this piece of code starts the action only the
| |
− | first time after startup ( if the action isn't stopped somewhere with
| |
− | THREAD_STOP). There ist also the possibility to use THREAD_RESTART, which
| |
− | starts the thread always new, when THREAD_RESTART is called.
| |
− | | |
− | == Ein Beispiel für ein Control6 ==
| |
− | | |
− | An simple example, which may show you some features of Control6:
| |
− | <pre>
| |
− | CONTROL_START
| |
− |
| |
− | PIN_INPUT(KEY)
| |
− | PIN_PULLUP(KEY)
| |
− | PIN_OUTPUT(LED)
| |
− | | |
− | THREAD(nice_gaudi)
| |
− | TIMER_START(new)
| |
− | PIN_SET(LED);
| |
− | TIMER_WAIT(new, 20)
| |
− | PIN_CLEAR(LED);
| |
− | THREAD_END(nice_gaudi)
| |
− | | |
− | ON CLOCK_MIN == 5 DO THREAD_RESTART(nice_gaudi) END
| |
− | ON PIN_FALLING(KEY) DO THREAD_RESTART(nice_gaudi) END
| |
− | | |
− | CONTROL_END
| |
− | </pre>
| |
− | | |
− | * The typical CONTROL_START, CONTROL_END enclose the Control6 scripts
| |
− | * the pin commands:
| |
− | ** the names PIN_INPUT and the other PIN_* refers to are the same, which are defined in pinning/*.m4. You also may to add your pins there.
| |
− | ** PIN_INPUT defines the KEY pin as an input pin (DDRx is set correctly)
| |
− | ** PIN_PULLUP enabled the pullup for the KEY pin (PORTx is set correctly)
| |
− | ** PIN_OUTPUT defines the LED pin as an output pin (DDRx is set correctly)
| |
− | ** PIN_FALLING(KEY) is an event, which is always triggered if there is an falling edge on the pin KEY. Corresponding to PIN_FALLING, PIN_RISING does also exists.
| |
− | | |
− | * THREAD, THREAD_END define a new thread `nice_gaudi' within this thread there is a timer started ( the first call of TIMER_START creates this timer also, the creation of a timer can also be done with TIMER_NEW). After the timer is started the LED key is enabled.
| |
− | * The TIMER_WAIT waits, until the created timer has reaced 20 seconds. After that the LED is cleared again. Be aware of the ; at the end of PIN_SET, PIN_CLEAR. This is because this lines are not interpreted with m4, but are plain C code (CPP macros)
| |
− | * The two ON commands start the thread nice_gaudi either when the clock minute field is 5 ( be aware of the RESTART ) or the KEY pin has an falling edge.
| |
− | | |
− | Another example for a Atmega168 with only few memory:
| |
− | <pre>
| |
− | CONTROL_START
| |
− | | |
− | ECMD_GLOBAL(state,255);
| |
− | ECMD_GLOBAL(c,0);
| |
− | | |
− | PIN_INPUT(Key_green)
| |
− | PIN_INPUT(Key_red)
| |
− | PIN_OUTPUT(LED_green)
| |
− | PIN_OUTPUT(LED_red)
| |
− | PIN_OUTPUT(Pulserelais_on)
| |
− | PIN_OUTPUT(Pulserelais_off)
| |
− | | |
− | THREAD(states)
| |
− | ON state==0 DO
| |
− | PIN_SET(LED_red);
| |
− | PIN_CLEAR(LED_green);
| |
− | PIN_SET(Pulserelais_off);
| |
− | ESEND(192.168.28.1, "Off\");
| |
− | state=10;
| |
− | c=0;
| |
− | END
| |
− | ON state==10 DO
| |
− | c=c+1;
| |
− | ON c==20 DO
| |
− | c=0;
| |
− | PIN_CLEAR(Pulserelais_on);
| |
− | PIN_CLEAR(Pulserelais_off);
| |
− | state=100;
| |
− | END
| |
− | END
| |
− | | |
− | ON state==1 DO
| |
− | PIN_SET(LED_green);
| |
− | PIN_CLEAR(LED_red);
| |
− | PIN_SET(Pulserelais_on);
| |
− | ESEND(192.168.28.1, "On\");
| |
− | state=11;
| |
− | c=0;
| |
− | END
| |
− | ON state==11 DO
| |
− | c=c+1;
| |
− | ON c==20 DO
| |
− | c=0;
| |
− | PIN_CLEAR(Pulserelais_on);
| |
− | PIN_CLEAR(Pulserelais_off);
| |
− | state=101;
| |
− | END
| |
− | END
| |
− | | |
− | ON state==2 DO
| |
− | PIN_CLEAR(LED_red);
| |
− | PIN_CLEAR(LED_green);
| |
− | ESEND(192.168.28.1, "Cleaning\");
| |
− | state=20;
| |
− | END
| |
− | ON state==20 DO
| |
− | c=c+1;
| |
− | ON c==15 DO
| |
− | PIN_SET(LED_green);
| |
− | END
| |
− | ON c==30 DO
| |
− | PIN_CLEAR(LED_green);
| |
− | c=0;
| |
− | END
| |
− | END
| |
− | THREAD_END(states)
| |
− | | |
− | ON PIN_FALLING(Key_green) DO
| |
− | state=1;
| |
− | END
| |
− | | |
− | ON PIN_FALLING(Key_red) DO
| |
− | ON state==101 DO
| |
− | state=2;
| |
− | END
| |
− | ON state==20 DO
| |
− | state=0;
| |
− | END
| |
− | END
| |
− | | |
− | ON STARTUP DO
| |
− | ESEND(192.168.28.1, "Start\");
| |
− | state=0;
| |
− | THREAD_RESTART(states);
| |
− | END
| |
− | | |
− | CONTROL_END
| |
− | </pre>
| |
− | It is a state mashine to control a pulse relais with two coils for a
| |
− | coffeemashine. If you press the green button the mashine is switched
| |
− | on and the green LED light up. At the same time the server gets the
| |
− | message "On". If you press the red button it sends a message "Cleaning"
| |
− | to the server and starts to flash the green LED. If you press it again
| |
− | it sends "Off" and switches the relais off. Then the red LED lights up.
| |
− | The server can control the circuit by sending a message like this:
| |
− | <pre>
| |
− | echo "c6 set state 1" | netcat -q1 coffeemashine 2701
| |
− | </pre>
| |
− | To check the status it should send something like:
| |
− | <pre>
| |
− | echo "c6 get state" | netcat -q1 coffeemashine 2701
| |
− | </pre>
| |
− | Is the answer e.g. "state 100" the mashine is off.
| |
− | The job is done without timers because there was no space left in the device.
| |
− | It took with tcp, control6, named pins and rfm12 nearly 16K.
| |
− | | |
− | [[Category:Ethersex]]
| |