Command handling
----------------

Data format sent is (bit pattern):

1AAAAAAA 0DDDDDDD 1AAAAAAA 0DDDDDDD

where A = address bit, MSB=1 indicates address
      D = data bit, MSB=0 indicates data

I.e. address and data are repeated twice.
They must be equal for the receiver to react on it.

The data is interpreted by the slave as a command:
0 = all OFF
1 = relay one ON
2 = relay one OFF
3 = relay two ON
4 = relay two OFF
5 = LV1 switch ON
6 = LV1 switch OFF
7 = all ON
8 = LV3 switch ON
9 = LV3 switch OFF


Receiver
--------
;; VERSION.RELEASE 0.1
;; ===================
;; 20061223 First released BETA version with all first features available
;;
;; VERSION.RELEASE 0.2
;; ===================
;; 20070101 Clear counters with AA00
;; 20070111 Convert LV1 ADC to decimal -> LED
;; 20070114 RC5 LV3 and command 8&9 to reset/set the switch - SIMULATED/NOT TESTED
;;
;; VERSION.RELEASE 0.3
;; ===================
;; 20070118 Display of LV3,RE1,RE2 status on /oFF
;; 20070118 Toggle button - action depends on LED switch setting
;;     button 1 : toggle switch/relay
;; 20070119:
;; Change keyboard scan interval when toggle active
;; i.e. LED_SETTING= 4 to 8 from 256 * 5 ms to 16 * 5ms
;;
;; VERSION.RELEASE 0.4
;; ===================
;; 20070228
;; LV3_SWITCH RC5 -> RA5 active low
;; RB7 = zerocrossing
;; RC4,5 = SPI datain/out
;; RC0 shortmonitor - always shown if 'Shrt'


Each receiver has an individudal address set with dip switches.
The dipswitches is scanned each 1.28 second = (256 * 5ms tick).
The address is displayed on the LED at startup, and when it is
being changed.


LED settings
switch
    00 display off
    01 1&2 Hex address, 3&4 Hex data : AADD
    02 1&2 Slave address, 3='U', 4=BaudRate (shoulde be 5)
    03 = 3.123 RF analog voltage
    04 = 4.123 LV1 analog value
    05 = 5.123 LV2 analog value
    06 = 6.on/oFF LV3 status/toggle
    07 = 7.on/OFF relay1 status/toggle
    08 = 8.on/OFF relay2 status/toggle
    13 = VV.RR Version + Release
    14 = CC.EE Number of Commands + Errors found
    15 = 55.AA Number of 55 + AA commands recognised

if there is short then it is written 'Shrt' on the display,
the switch setting is ignored in this case.

Sender
------

It scans continously the keyboard. It takes some time to scan it(= ? ms).
A change of a switch (on->off/off->on) is recognised when the key has been
stable for 4 * 5ms in  the new position.

The sender sends the address and data for each receiver sequentilly
in the order they are entered. It will take roughly

(4*0.3 + 14 + 4*1.2) ms = 20ms for each packet sent.
The first part is writing to the sender module, the second
(14ms) is the transfer time from sender to receiver, the last one (4*1.2) the receiving time.
This means that at most 50 packets can be sent per second,
and there is at least 20 + 20 = 40ms delay from the key switch
until the receiver has performed the action.

The master has a buffer for 256 packets, if it gets full new packets are
ignored.

Due to the buffering is there no exact delay from the time the switch
is changed  and when the action is done (the minimum delay is 40ms)



commands from host recognised by the sender module:
 !AADD = Send Data DD to RF address AA
 L1234 = Set LED display to '1234'
 Sx = Select what to display on LED
  x = 0: What is being sent
  x = 1: Number of commands sent
 TAADD = Send test data to address AA, DD = 55, 4A 255 times.
 Gx = Get from command flash memory,store in RAM and send code for buffer x
 gx = Get from command RAM storage and send to host
 RxSSAAD1D2EE = Receive code for buffer x
                switch SS,address AA; data D1 & D2 & EE
  x = 0 : only valid buffer
 PROG = Program the FlashBuf space to flashmemory
 FRST = Factory reset of command flash memory. (NOT YET IMPLEMENTED!!!)
 V = Verbose mode ON, things are written back to host
 v = Verbose mode OFF, nothing is written back to host
 DAADD = test loop ON, send data DD to address AA in infinite loop
 d = test loop OFF
 C = clear some counters for test loops

Ths host port is set to:
9600 baud
8 bit data
1 stop bit
no parity


Version4
========
*KKS = Set Keynumber KK (0-127) to S (0,1)
P0 = user RAM as command source
P1 = use flashmemory as command source