Control6: Unterschied zwischen den Versionen

Aus Ethersex_Wiki
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: == Ein kleiner Einstieg in Control6 == === So fängt man an === der Skript Code der einkompiliert wird muss in die Datei control6/control6.src eingetragen werden. ...)
 
 
(6 dazwischenliegende Versionen von 5 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
==  Ein kleiner Einstieg in Control6 ==
+
'''Control6''' ist eine auf [http://de.wikipedia.org/wiki/Protothread Protothreads] fußende Art von Skriptsprache, die ein wenig von ''Basic'' inspiriert ist.
 +
Control6 soll insbesondere dazu dienen, dass man die einzelnen Komponenten von Ethersex schnell zusammenfügen kann.
 +
Beispielsweise können in einer Endlosschleife die Temperaturen von KTY-Sensoren ausgelesen werden und in Abhängigkeit der Werte dann Pins geschaltet, [[SYSLOG]]-Nachrichten abgesetzt oder [[ECMD]]-Befehle versendet werden.
  
===  So fängt man an ===
+
Die Skripte werden während des Kompiliervorgangs in C-Code übersetzt und letztlich mit in die Firmware einkompiliert.
 +
Sie sind somit ''statisch'' und nur durch Neuprogrammierung änderbar.
  
der Skript Code der einkompiliert wird muss in die Datei control6/control6.src eingetragen werden.  
+
==  So fängt man an ==
 +
Standardmäßig werden, wenn in Menuconfig die Funktion ''Control6'' aktiviert wurde, die Instruktionen aus der Datei '''control6/control6.src''' in die Firmware eingebunden.  Für Eigenentwicklungen, die nicht in die "Distribution" aufgenommen werden sollen, empfiehlt es sich separate Dateien in der Ethersex Ordnerstruktur anzulegen, sodass es zu keinen (oder zumindest seltener) zu Konflikten beim Update auf eine neuere offizielle Firmwareversion kommt.
  
=== Die Befehle ===
+
Dazu einfach eine beliebige Datei im Stile der o.g. ''control6.src'' anlegen, zum Beispiel eine ''control6/erste-schritte.src'' und diese dem Makesystem bekannt machen.  Letzteres durch folgenden Eintrag in der Datei [[config.mk]] im Hauptverzeichnis (wenn diese noch nicht existiert, einfach eine neue Datei anlegen und nur diese Zeile eintragen):
 +
  C6_SOURCE = $(TOPDIR)/control6/erste-schritte.src
  
===  Fallstricke ===
+
* [[:Kategorie:Control6 Examples|Control6 Beispielcode]]
 +
* [[PIN_Commands|Wie schreibe ich ein Control6 Skript]]
  
=== 6Control/Control6 ===
+
== Konzepte ==
Wir haben 6Control nach Control6 umbenannt, denn der C Compiler mag keine Nummer vor Zeichen bei Funktionnamen
+
* Ein Control6-Skript wird immer von den Tags '''CONTROL_START''' und '''CONTROL_END''' umschlossen.
 +
* Mit '''THREAD''' resp. '''THREAD_END''' können leicht quasi nebenläufige Programmabschnitte erstellt werden.  Dies ermöglicht mehrere Aufgaben, die miteinander nichts zu tun haben, auch getrennt voneinander im Control6-Code abzubilden.
  
==  Was ist Control6? ==
+
== Befehlssatz ==
 +
Control6 ist momentan schon relativ mächtig und stellt durchaus eine Alternative zum Verfassen von C-Code dar. Es werden aber nachwievor nicht alle Aspekte von Ethersex auch in Control6 abgebildet (und noch weniger werden hier im Wiki bislang thematisiert).  Wenn du möchtest, du bist herzlich willkommen beim Ausbau der Funktionalität mitzuhelfen :-)
  
Control6 ist eine art Skripting mit protothreads das eine art Basic für Ethersex
+
* übergreifende Funktionen
darstellen soll. Die Skripte werde in C Code übersetzt die dann wiederum Compiled werden.
+
** [[Globale Variablen]]
Die Skipte sind somit statisch und nur durch Neuprogrammierung veränderbar.
+
** [[PIN-Befehle]], Threading, Timer und Events
 +
** [[Bedingungen]]
 +
* Einzelaspekte, siehe
 +
** [[ADC-Werte abfragen]]
 +
** [[Zugriff auf die Systemuhr]]
 +
** [[Debug-Meldungen und SYSLOG]]
 +
** [[ECMD-Befehle absetzen]]
 +
** [[Jabber]]
 +
** [[eMail versenden]]
 +
** [[Dallas 1-wire Bus]]
 +
** [[KTY81]]
 +
** [[Einfaches Menüsystem|TTY und Menü-System]]
 +
** [[IRMP|IR-Empfänger abfragen]]
 +
** [[TCP-Client als FRITZ!Box Call Monitor]]
  
==  Wie schreibe ich ein Control6 Skript ==
+
[[Kategorie:Ethersex]]
 
+
[[Kategorie:Control6|!]]
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, &quot;Off\
 
&quot;);
 
      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, &quot;On\
 
&quot;);
 
      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, &quot;Cleaning\
 
&quot;);
 
      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, &quot;Start\
 
&quot;);
 
  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 &quot;On&quot;. If you press the red button it sends a message &quot;Cleaning&quot;
 
to the server and starts to flash the green LED. If you press it again
 
it sends &quot;Off&quot; 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 &quot;c6 set state 1&quot; | netcat -q1 coffeemashine 2701
 
</pre>
 
To check the status it should send something like:
 
<pre>
 
echo &quot;c6 get state&quot; | netcat -q1 coffeemashine 2701
 
</pre>
 
Is the answer e.g. &quot;state 100&quot; 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.
 

Aktuelle Version vom 29. August 2011, 00:12 Uhr

Control6 ist eine auf Protothreads fußende Art von Skriptsprache, die ein wenig von Basic inspiriert ist. Control6 soll insbesondere dazu dienen, dass man die einzelnen Komponenten von Ethersex schnell zusammenfügen kann. Beispielsweise können in einer Endlosschleife die Temperaturen von KTY-Sensoren ausgelesen werden und in Abhängigkeit der Werte dann Pins geschaltet, SYSLOG-Nachrichten abgesetzt oder ECMD-Befehle versendet werden.

Die Skripte werden während des Kompiliervorgangs in C-Code übersetzt und letztlich mit in die Firmware einkompiliert. Sie sind somit statisch und nur durch Neuprogrammierung änderbar.

So fängt man an

Standardmäßig werden, wenn in Menuconfig die Funktion Control6 aktiviert wurde, die Instruktionen aus der Datei control6/control6.src in die Firmware eingebunden. Für Eigenentwicklungen, die nicht in die "Distribution" aufgenommen werden sollen, empfiehlt es sich separate Dateien in der Ethersex Ordnerstruktur anzulegen, sodass es zu keinen (oder zumindest seltener) zu Konflikten beim Update auf eine neuere offizielle Firmwareversion kommt.

Dazu einfach eine beliebige Datei im Stile der o.g. control6.src anlegen, zum Beispiel eine control6/erste-schritte.src und diese dem Makesystem bekannt machen. Letzteres durch folgenden Eintrag in der Datei config.mk im Hauptverzeichnis (wenn diese noch nicht existiert, einfach eine neue Datei anlegen und nur diese Zeile eintragen):

C6_SOURCE = $(TOPDIR)/control6/erste-schritte.src

Konzepte

  • Ein Control6-Skript wird immer von den Tags CONTROL_START und CONTROL_END umschlossen.
  • Mit THREAD resp. THREAD_END können leicht quasi nebenläufige Programmabschnitte erstellt werden. Dies ermöglicht mehrere Aufgaben, die miteinander nichts zu tun haben, auch getrennt voneinander im Control6-Code abzubilden.

Befehlssatz

Control6 ist momentan schon relativ mächtig und stellt durchaus eine Alternative zum Verfassen von C-Code dar. Es werden aber nachwievor nicht alle Aspekte von Ethersex auch in Control6 abgebildet (und noch weniger werden hier im Wiki bislang thematisiert). Wenn du möchtest, du bist herzlich willkommen beim Ausbau der Funktionalität mitzuhelfen :-)