From ae5cef79cc8d9f42bef16f29a47d59027cf7f244 Mon Sep 17 00:00:00 2001 From: qqqlab <46283638+qqqlab@users.noreply.github.com> Date: Sat, 14 Nov 2020 03:55:30 +0100 Subject: [PATCH] . --- examples/Commissioning/Commissioning.ino | 318 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ examples/Dimmer/Dimmer.ino | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ examples/Monitor/Monitor.ino | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qqqDALI.cpp | 722 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qqqDALI.h | 643 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1867 insertions(+), 0 deletions(-) create mode 100644 examples/Commissioning/Commissioning.ino create mode 100644 examples/Dimmer/Dimmer.ino create mode 100644 examples/Monitor/Monitor.ino create mode 100644 qqqDALI.cpp create mode 100644 qqqDALI.h diff --git a/examples/Commissioning/Commissioning.ino b/examples/Commissioning/Commissioning.ino new file mode 100644 index 0000000..ae7a83a --- /dev/null +++ b/examples/Commissioning/Commissioning.ino @@ -0,0 +1,318 @@ +/*########################################################################### + copyright qqqlab.com / github.com/qqqlab + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +###########################################################################*/ +#include "qqqDALI.h" + +Dali dali; + +//ATMEGA328 specific +#define TX_PIN 3 +#define RX_PIN 4 + +//is bus asserted +uint8_t bus_is_high() { + return digitalRead(RX_PIN); //slow version + //return PIND & (1 << 4); //fast version +} + +//assert bus +void bus_set_low() { + digitalWrite(TX_PIN,HIGH); //opto slow version + //PORTD |= (1 << 3); //opto fast version + + //digitalWrite(TX_PIN,LOW); //diy slow version + //PORTD &= ~(1 << 3); //diy fast version +} + +//release bus +void bus_set_high() { + digitalWrite(TX_PIN,LOW); //opto slow version + //PORTD &= ~(1 << 3); //opto fast version + + //digitalWrite(TX_PIN,HIGH); //diy slow version + //PORTD |= (1 << 3); //diy fast version +} + +void bus_init() { + //setup rx pin + pinMode(4, INPUT); + + //setup tx pin + pinMode(3, OUTPUT); + + //setup tx timer interrupt + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + OCR1A = (F_CPU + 8 * DALI_BAUD / 2) / (8 * DALI_BAUD); // compare match register at baud rate * 8 + TCCR1B |= (1 << WGM12); // CTC mode + TCCR1B |= (1 << CS10); // 1:1 prescaler + TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt +} + +ISR(TIMER1_COMPA_vect) { + dali.timer(); +} + +void setup() { + Serial.begin(115200); + Serial.println("DALI Commissioning Demo"); + + dali.begin(bus_is_high, bus_set_high, bus_set_low); + bus_init(); + + menu(); +} + +void loop() { + while (Serial.available() > 0) { + int incomingByte = Serial.read(); + switch(incomingByte) { + case '1': menu_blink(); menu(); break; + case '2': menu_scan_short_addr(); menu(); break; + case '3': menu_commission(); menu(); break; + case '4': menu_commission_debug(); menu(); break; + case '5': menu_delete_short_addr(); menu(); break; + case '6': menu_read_memory(); menu(); break; + } + } +} + +void menu() { + Serial.println("----------------------------"); + Serial.println("1 Blink all lamps"); + Serial.println("2 Scan short addresses"); + Serial.println("3 Commission short addresses"); + Serial.println("4 Commission short addresses (VERBOSE)"); + Serial.println("5 Delete short addresses"); + Serial.println("6 Read memory bank"); + Serial.println("----------------------------"); +} + +void menu_blink() { + Serial.println("Running: Blinking all lamps"); + for(uint8_t i=0;i<5;i++) { + dali.set_level(254); + Serial.print("."); + delay(500); + dali.set_level(0); + Serial.print("."); + delay(500); + } + Serial.println(); +} + +void menu_scan_short_addr() { + Serial.println("Running: Scan all short addresses"); + uint8_t sa; + uint8_t cnt = 0; + for(sa = 0; sa<64; sa++) { + int16_t rv = dali.cmd(DALI_QUERY_STATUS,sa); + if(rv>=0) { + cnt++; + Serial.print("short address="); + Serial.print(sa); + Serial.print(" status=0x"); + Serial.print(rv,HEX); + Serial.print(" minLevel="); + Serial.print(dali.cmd(DALI_QUERY_MIN_LEVEL,sa)); + Serial.print(" flashing"); + for(uint8_t i=0;i<5;i++) { + dali.set_level(254,sa); + Serial.print("."); + delay(500); + dali.set_level(0,sa); + Serial.print("."); + delay(500); + } + Serial.println(); + }else if (-rv != DALI_RESULT_NO_REPLY) { + Serial.print("short address="); + Serial.print(sa); + Serial.print(" ERROR="); + Serial.println(-rv); + } + } + Serial.print("DONE, found ");Serial.print(cnt);Serial.println(" short addresses"); +} + +//might need a couple of calls to find everything... +void menu_commission(){ + Serial.println("Running: Commission"); + Serial.println("Might need a couple of runs to find all lamps ..."); + Serial.println("Be patient, this takes a while ..."); + uint8_t cnt = dali.commission(0xff); //init_arg=0b11111111 : all without short address + Serial.print("DONE, assigned ");Serial.print(cnt);Serial.println(" new short addresses"); +} + +//might need a couple of calls to find everything... +void menu_commission_debug(){ + Serial.println("Running: Commission (VERBOSE)"); + Serial.println("Might need a couple of runs to find all lamps ..."); + Serial.println("Be patient, this takes a while ..."); + uint8_t cnt = debug_commission(0xff); //init_arg=0b11111111 : all without short address + Serial.print("DONE, assigned ");Serial.print(cnt);Serial.println(" new short addresses"); +} + +void menu_delete_short_addr() { + Serial.println("Running: Delete all short addresses"); + //remove all short addresses + dali.cmd(DALI_DATA_TRANSFER_REGISTER0,0xFF); + dali.cmd(DALI_SET_SHORT_ADDRESS, 0xFF); + Serial.println("DONE delete"); +} + +//init_arg=11111111 : all without short address +//init_arg=00000000 : all +//init_arg=0AAAAAA1 : only for this shortadr +//returns number of new short addresses assigned +uint8_t debug_commission(uint8_t init_arg) { + uint8_t cnt = 0; + uint8_t arr[64]; + uint8_t sa; + for(sa=0; sa<64; sa++) arr[sa]=0; + + dali.cmd(DALI_INITIALISE,init_arg); + dali.cmd(DALI_RANDOMISE,0x00); + //need 100ms pause after RANDOMISE, scan takes care of this... + + //find used short addresses (run always, seems to work better than without...) + Serial.println("Find existing short adr"); + for(sa = 0; sa<64; sa++) { + int16_t rv = dali.cmd(DALI_QUERY_STATUS,sa); + if(rv>=0) { + if(init_arg!=0b00000000) arr[sa]=1; //remove address from list if not in "all" mode + Serial.print("sortadr="); + Serial.print(sa); + Serial.print(" status=0x"); + Serial.print(rv,HEX); + Serial.print(" minLevel="); + Serial.println(dali.cmd(DALI_QUERY_MIN_LEVEL,sa)); + } + } + +// dali.set_searchaddr(0x000000); +// dali.set_searchaddr(0xFFFFFF); +//while(1) { +// dali.compare(); +// delay(200); +//} + + + + Serial.println("Find random adr"); + while(1) { + uint32_t adr = dali.find_addr(); + if(adr>0xffffff) break; + Serial.print("found="); + Serial.println(adr,HEX); + + //find available address + for(sa=0; sa<64; sa++) { + if(arr[sa]==0) break; + } + if(sa>=64) break; + arr[sa] = 1; + cnt++; + + Serial.print("program short adr="); + Serial.println(sa); + dali.program_short_address(sa); + Serial.print("read short adr="); + Serial.println(dali.query_short_address()); + + dali.cmd(DALI_WITHDRAW,0x00); + } + + dali.cmd(DALI_TERMINATE,0x00); + return cnt; +} + +void menu_read_memory() { +/* + uint8_t v = 123; + uint8_t adr = 0xff; + + while(1) { + int16_t rv = dali.cmd(DALI_DATA_TRANSFER_REGISTER0, v); //store value in DTR + Serial.print("rv="); + Serial.print(rv); + + int16_t dtr = dali.cmd(DALI_QUERY_CONTENT_DTR0, adr); //get DTR value + Serial.print(" dtr="); + Serial.println(dtr); + delay(13); + } +*/ + + Serial.println("Running: Scan all short addresses"); + uint8_t sa; + uint8_t cnt = 0; + for(sa = 0; sa<64; sa++) { + int16_t rv = dali.cmd(DALI_QUERY_STATUS,sa); + if(rv>=0) { + cnt++; + Serial.print("\nshort address "); + Serial.println(sa); + Serial.print("status=0x"); + Serial.println(rv,HEX); + Serial.print("minLevel="); + Serial.println(dali.cmd(DALI_QUERY_MIN_LEVEL,sa)); + + dali_read_memory_bank_verbose(0,sa); + + }else if (-rv != DALI_RESULT_NO_REPLY) { + Serial.print("short address="); + Serial.print(sa); + Serial.print(" ERROR="); + Serial.println(-rv); + } + } + Serial.print("DONE, found ");Serial.print(cnt);Serial.println(" short addresses"); +} + +uint8_t dali_read_memory_bank_verbose(uint8_t bank, uint8_t adr) { + uint16_t rv; + + if(dali.set_dtr0(0, adr)) return 1; + if(dali.set_dtr1(bank, adr)) return 2; + + //uint8_t data[255]; + uint16_t len = dali.cmd(DALI_READ_MEMORY_LOCATION, adr); + Serial.print("memlen="); + Serial.println(len); + for(uint8_t i=0;i=0) { + //data[i] = mem; + Serial.print(i,HEX); + Serial.print(":"); + Serial.print(mem); + Serial.print(" 0x"); + Serial.print(mem,HEX); + Serial.print(" "); + if(mem>=32 && mem <127) Serial.print((char)mem); + Serial.println(); + }else if(mem!=-DALI_RESULT_NO_REPLY) { + Serial.print(i,HEX); + Serial.print(":err="); + Serial.println(mem); + } + } + + uint16_t dtr0 = dali.cmd(DALI_QUERY_CONTENT_DTR0,adr); //get DTR value + if(dtr0 != 255) return 4; +} \ No newline at end of file diff --git a/examples/Dimmer/Dimmer.ino b/examples/Dimmer/Dimmer.ino new file mode 100644 index 0000000..ed0089a --- /dev/null +++ b/examples/Dimmer/Dimmer.ino @@ -0,0 +1,96 @@ +/*########################################################################### + copyright qqqlab.com / github.com/qqqlab + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +###########################################################################*/ +#include "qqqDALI.h" + +Dali dali; + +//ATMEGA328 specific +#define TX_PIN 3 +#define RX_PIN 4 + +//is bus asserted +uint8_t bus_is_high() { + return digitalRead(RX_PIN); //slow version + //return PIND & (1 << 4); //fast version +} + +//assert bus +void bus_set_low() { + digitalWrite(TX_PIN,HIGH); //opto slow version + //PORTD |= (1 << 3); //opto fast version + + //digitalWrite(TX_PIN,LOW); //diy slow version + //PORTD &= ~(1 << 3); //diy fast version +} + +//release bus +void bus_set_high() { + digitalWrite(TX_PIN,LOW); //opto slow version + //PORTD &= ~(1 << 3); //opto fast version + + //digitalWrite(TX_PIN,HIGH); //diy slow version + //PORTD |= (1 << 3); //diy fast version +} + +void bus_init() { + //setup rx pin + pinMode(4, INPUT); + + //setup tx pin + pinMode(3, OUTPUT); + + //setup tx timer interrupt + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + OCR1A = (F_CPU + 8 * DALI_BAUD / 2) / (8 * DALI_BAUD); // compare match register at baud rate * 8 + TCCR1B |= (1 << WGM12); // CTC mode + TCCR1B |= (1 << CS10); // 1:1 prescaler + TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt +} + +ISR(TIMER1_COMPA_vect) { + dali.timer(); +} + +void setup() { + Serial.begin(115200); + Serial.println("DALI Dimmer Demo"); + + dali.begin(bus_is_high, bus_set_high, bus_set_low); + bus_init(); +} + +#define MIN_LEVEL 100 //most LED Drivers do not get much lower than this +int16_t level = 254; //254 is max level, 1 is min level (if driver supports it), 0 is off +int8_t level_step = 4; + +void loop() { + Serial.print("set level: "); + Serial.println(level); + dali.set_level(level); + + level+=level_step; + if(level>=254) { + level = 254; + level_step = -level_step; + } + if(level. +###########################################################################*/ +#include "qqqDALI.h" + +Dali dali; + +//ATMEGA328 specific +#define TX_PIN 3 +#define RX_PIN 4 + +//is bus asserted +uint8_t bus_is_high() { + return digitalRead(RX_PIN); //slow version + //return PIND & (1 << 4); //fast version +} + +//assert bus +void bus_set_low() { + digitalWrite(TX_PIN,HIGH); //opto slow version + //PORTD |= (1 << 3); //opto fast version + + //digitalWrite(TX_PIN,LOW); //diy slow version + //PORTD &= ~(1 << 3); //diy fast version +} + +//release bus +void bus_set_high() { + digitalWrite(TX_PIN,LOW); //opto slow version + //PORTD &= ~(1 << 3); //opto fast version + + //digitalWrite(TX_PIN,HIGH); //diy slow version + //PORTD |= (1 << 3); //diy fast version +} + +void bus_init() { + //setup rx pin + pinMode(4, INPUT); + + //setup tx pin + pinMode(3, OUTPUT); + + //setup tx timer interrupt + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + OCR1A = (F_CPU + 8 * DALI_BAUD / 2) / (8 * DALI_BAUD); // compare match register at baud rate * 8 + TCCR1B |= (1 << WGM12); // CTC mode + TCCR1B |= (1 << CS10); // 1:1 prescaler + TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt +} + +ISR(TIMER1_COMPA_vect) { + dali.timer(); +} + +void setup() { + Serial.begin(115200); + Serial.println("DALI Monitor Demo"); + + dali.begin(bus_is_high, bus_set_high, bus_set_low); + bus_init(); +} + +void loop() { + uint8_t data[4]; + uint8_t bitcnt = dali.rx(data); + if(bitcnt>=8) { + for(uint8_t i=0;i<=(bitcnt-1)>>3;i++) { + Serial.print(data[i],HEX); + Serial.print(' '); + } + Serial.println(); + } +} \ No newline at end of file diff --git a/qqqDALI.cpp b/qqqDALI.cpp new file mode 100644 index 0000000..00be78e --- /dev/null +++ b/qqqDALI.cpp @@ -0,0 +1,722 @@ +/*########################################################################### + copyright qqqlab.com / github.com/qqqlab + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Changelog: +2020-11-14 Rewrite with sampling instead of pinchange +2020-11-10 Split off hardware specific code into separate class +2020-11-08 Created & tested on ATMega328 @ 8Mhz +###########################################################################*/ + +//#define DALI_DEBUG + +//================================================================= +// LOW LEVEL DRIVER +//================================================================= +#include "qqqDALI.h" + +#ifdef DALI_DEBUG +#include "arduino.h" +#endif + +//timing +#define BEFORE_CMD_IDLE_MS 13 //require 13ms idle time before sending a cmd() + +//busstate +#define IDLE 0 +#define RX 1 +#define COLLISION_RX 2 +#define TX 3 +#define COLLISION_TX 4 + +void Dali::begin(uint8_t (*bus_is_high)(), void (*bus_set_low)(), void (*bus_set_high)()) +{ + this->bus_is_high = bus_is_high; + this->bus_set_low = bus_set_low; + this->bus_set_high = bus_set_high; + _init(); +} + +void Dali::_set_busstate_idle() { + bus_set_high(); + idlecnt = 0; + busstate = IDLE; +} + +void Dali::_init() { + _set_busstate_idle(); + rxstate = EMPTY; + txcollision = 0; +} + +uint16_t Dali::milli() { + while(ticks==0xFF); //wait for _millis update to finish + return _milli; +} + +// timer interrupt service routine, called 9600 times per second +void Dali::timer() { + //get bus sample + uint8_t busishigh = (bus_is_high() ? 1 : 0); //bus_high is 1 on high (non-asserted), 0 on low (asserted) + + //millis update + ticks++; + if(ticks==10) { + ticks = 0xff; //signal _millis is updating + _milli++; + ticks = 0; + } + + switch(busstate) { + case IDLE: + if(busishigh) { + if(idlecnt != 0xff) idlecnt++; + break; + } + //set busstate = RX + rxpos = 0; + rxbitcnt = 0; + rxidle = 0; + rxstate = RECEIVING; + busstate = RX; + //fall-thru to RX + case RX: + //store sample + rxbyte = (rxbyte << 1) | busishigh; + rxbitcnt++; + if(rxbitcnt == 8) { + rxdata[rxpos] = rxbyte; + rxpos++; + if(rxpos > DALI_RX_BUF_SIZE - 1) rxpos = DALI_RX_BUF_SIZE - 1; + rxbitcnt = 0; + } + //check for reception of 2 stop bits + if(busishigh) { + rxidle++; + if(rxidle >= 16) { + rxdata[rxpos] = 0xFF; + rxpos++; + rxstate = COMPLETED; + _set_busstate_idle(); + break; + } + }else{ + rxidle = 0; + } + break; + case TX: + if(txhbcnt >= txhblen) { + //all bits transmitted, go back to IDLE + _set_busstate_idle(); + }else{ + //check for collisions (transmitting high but bus is low) + if( ( + txcollisionhandling == DALI_TX_COLLISSION_ON //handle all + || (txcollisionhandling == DALI_TX_COLLISSION_AUTO && txhblen != 2+8+4) //handle only if not transmitting 8 bits (2+8+4 half bits) + ) && (txhigh && !busishigh) //transmitting high, but bus is low + && (txspcnt==1 || txspcnt==2) ) // in middle of transmitting low period + { + if(txcollision != 0xFF) txcollision++; + txspcnt = 0; + busstate = COLLISION_TX; + return; + } + + //send data bits (MSB first) to bus every 4th sample time + if(txspcnt == 0) { + //send bit + uint8_t pos = txhbcnt >> 3; + uint8_t bitmask = 1 << (7 - (txhbcnt & 0x7)); + if( txhbdata[pos] & bitmask ) { + bus_set_low(); + txhigh = 0; + }else{ + bus_set_high(); + txhigh = 1; + } + //update half bit counter + txhbcnt++; + //next transmit in 4 sample times + txspcnt = 4; + } + txspcnt--; + } + break; + case COLLISION_TX: + //keep bus low for 16 samples = 4 TE + bus_set_low(); + txspcnt++; + if(txspcnt >= 16) _set_busstate_idle(); + break; + } +} + +//push 2 half bits into the half bit transmit buffer, MSB first, 0x0=stop, 0x1= bit value 0, 0x2= bit value 1/start +void Dali::_tx_push_2hb(uint8_t hb) { + uint8_t pos = txhblen>>3; + uint8_t shift = 6 - (txhblen & 0x7); + txhbdata[pos] |= hb << shift; + txhblen += 2; +} + +//non-blocking transmit +//transmit if bus is IDLE, without checking hold off times, sends start+stop bits +uint8_t Dali::tx(uint8_t *data, uint8_t bitlen) { + if(bitlen > 32) return DALI_RESULT_FRAME_TOO_LONG; + if(busstate != IDLE) return DALI_RESULT_BUS_NOT_IDLE; + + //clear data + for(uint8_t i=0; i<9; i++) txhbdata[i]=0; + + //push data in transmit buffer + txhblen = 0; + _tx_push_2hb(0x2); //start bit + //data bits MSB first + for(uint8_t i=0; i>3; + uint8_t mask = 1 << (7 - (i & 0x7)); + _tx_push_2hb( data[pos] & mask ? 0x2 : 0x1 ); + } + _tx_push_2hb(0x0); //stop bit + _tx_push_2hb(0x0); //stop bit + + //setup tx vars + txhbcnt = 0; + txspcnt = 0; + txcollision = 0; + rxstate = EMPTY; + busstate = TX; + return DALI_OK; +} + +uint8_t Dali::tx_state() { + if(txcollision) { + txcollision = 0; + return DALI_RESULT_COLLISION; + } + if(busstate == TX) return DALI_RESULT_TRANSMITTING; + return DALI_OK; +} + + + + +//------------------------------------------------------------------- +//manchester decode +/* + +Prefectly matched transmitter and sampling: 8 samples per bit +---------+ +---+ +-------+ +-------+ +------------------------ + | | | | | | | | + +---+ +---+ +-------+ +---+ +sample-> 012345670123456701234567012345670123456701234567012345670 +sync-> ^ ^ ^ ^ ^ ^ ^ ^ +decode-> start 1 1 0 1 0 stop stop + + +slow transmitter: 9 samples per bit +---------+ +----+ +--------+ +--------+ +------------------------ + | | | | | | | | + +---+ +----+ +--------+ +---+ +sample-> 0123456780123456780123456780123456780123456780123456780123456780 +sync-> ^ ^ ^ ^ ^ ^ ^ ^ +decode-> start 1 1 0 1 0 stop stop + +*/ + +//compute weight for a 8 bit sample i +uint8_t Dali::_man_weight(uint8_t i) { + int8_t w = 0; + w += ((i>>7) & 1) ? 1 : -1; + w += ((i>>6) & 1) ? 2 : -2; //put more weight in middle + w += ((i>>5) & 1) ? 2 : -2; //put more weight in middle + w += ((i>>4) & 1) ? 1 : -1; + w -= ((i>>3) & 1) ? 1 : -1; + w -= ((i>>2) & 1) ? 2 : -2; //put more weight in middle + w -= ((i>>1) & 1) ? 2 : -2; //put more weight in middle + w -= ((i>>0) & 1) ? 1 : -1; + //w at this point: + //w = -12 perfect manchester encoded value 1 + //... + //w = -2 very weak value 1 + //w = 0 unknown (all samples high or low) + //... + //w = 12 perfect manchester encoded value 0 + + w *= 2; + if(w<0) w = -w + 1; + return w; +} + +//call with bitpos <= DALI_RX_BUF_SIZE*8-8; +uint8_t Dali::_man_sample(uint8_t *edata, uint16_t bitpos, uint8_t *stop_coll) { + uint8_t pos = bitpos>>3; + uint8_t shift = bitpos & 0x7; + uint8_t sample = (edata[pos] << shift) | (edata[pos+1] >> (8-shift)); + + //stop bit: received high (non-asserted) bus for last 8 samples + if(sample == 0xFF) *stop_coll = 1; + + //collision: received low (asserted) bus for last 8 samples + if(sample == 0x00) *stop_coll = 2; + + return sample; +} + + +//decode 8 times oversampled encoded data +//returns bitlen of decoded data, or 0 on collision +uint8_t Dali::_man_decode(uint8_t *edata, uint8_t ebitlen, uint8_t *ddata) { + uint8_t dbitlen = 0; + uint16_t ebitpos = 1; + while(ebitpos+1 0) { //ignore start bit + uint8_t bytepos = (dbitlen - 1) >> 3; + uint8_t bitpos = (dbitlen - 1) & 0x7; + if(bitpos == 0) ddata[bytepos] = 0; //empty data before storing first bit + ddata[bytepos] = (ddata[bytepos] << 1) | (weightmax & 1); //get databit from bit0 of weight + } + dbitlen++; + ebitpos += pmax; //jump to next mancheter bit, skipping over number of samples with max weight + } + if(dbitlen>1) dbitlen--; + return dbitlen; +} + +//non-blocking receive, +//returns 0 empty, 1 if busy receiving, 2 decode error, >2 number of bits received +uint8_t Dali::rx(uint8_t *ddata) { + switch(rxstate) { + case EMPTY: return 0; + case RECEIVING: return 1; + case COMPLETED: + rxstate = EMPTY; + uint8_t dlen = _man_decode(rxdata,rxpos*8,ddata); + + +#ifdef DALI_DEBUG + if(dlen!=8){ + //print received samples + Serial.print("RX: len="); + Serial.print(rxpos*8); + Serial.print(" "); + for(uint8_t i=0;i>=1) { + if(rxdata[i]&m) Serial.print("1"); else Serial.print("0"); + } + Serial.print(" "); + } + + //print decoded data + Serial.print("decoded: len="); + Serial.print(dlen); + Serial.print(" "); + for(uint8_t i=0;i>3] & (1 << (7 - (i & 0x7))) ) Serial.print("1"); else Serial.print("0"); + } + Serial.println(); + } +#endif + + if(dlen<3) return 2; + return dlen; + } + return 0; //should not get here +} + + +//================================================================= +// HIGH LEVEL FUNCTIONS +//================================================================= + +//blocking send - wait until successful send or timeout +uint8_t Dali::tx_wait(uint8_t* data, uint8_t bitlen, uint16_t timeout_ms) { + if(bitlen>32) return DALI_RESULT_DATA_TOO_LONG; + uint16_t start_ms = milli(); + while(1) { + //wait for 10ms idle + while(idlecnt < BEFORE_CMD_IDLE_MS){ + //Serial.print('w'); + if(milli() - start_ms > timeout_ms) return DALI_RESULT_TIMEOUT; + } + //try transmit + while(tx(data,bitlen) != DALI_OK){ + //Serial.print('w'); + if(milli() - start_ms > timeout_ms) return DALI_RESULT_TIMEOUT; + } + //wait for completion + uint8_t rv; + while(1) { + rv = tx_state(); + if(rv != DALI_RESULT_TRANSMITTING) break; + if(milli() - start_ms > timeout_ms) return DALI_RESULT_TIMEOUT; + } + //exit if transmit was ok + if(rv == DALI_OK) return DALI_OK; + //not ok (for example collision) - retry until timeout + } + return DALI_RESULT_TIMEOUT; +} + +//blocking transmit 2 byte command, receive 1 byte reply (if a reply was sent) +//returns >=0 with reply byte +//returns <0 with negative result code +int16_t Dali::tx_wait_rx(uint8_t cmd0, uint8_t cmd1, uint16_t timeout_ms) { +#ifdef DALI_DEBUG + Serial.print("TX"); + Serial.print(cmd0>>4,HEX); + Serial.print(cmd0&0xF,HEX); + Serial.print(cmd1>>4,HEX); + Serial.print(cmd1&0xF,HEX); + Serial.print(" "); +#endif + uint8_t data[4]; + data[0] = cmd0; + data[1] = cmd1; + int16_t rv = tx_wait(data, 16, timeout_ms); + if(rv) return -rv;; + + //wait up to 10 ms for start of reply, additional 15ms for receive to complete + uint16_t rx_start_ms = milli(); + uint16_t rx_timeout_ms = 10; + while(1) { + rv = rx(data); + switch( rv ) { + case 0: break; //nothing received yet, wait + case 1: rx_timeout_ms = 25; break; //extend timeout, wait for RX completion + case 2: return -DALI_RESULT_COLLISION; //report collision + default: + if(rv==8) + return data[0]; + else + return -DALI_RESULT_INVALID_REPLY; + } + if(milli() - rx_start_ms > rx_timeout_ms) return -DALI_RESULT_NO_REPLY; + } + return -DALI_RESULT_NO_REPLY; //should not get here +} + + +//check YAAAAAA: 0000 0000 to 0011 1111 adr, 0100 0000 to 0100 1111 group, x111 1111 broadcast +uint8_t Dali::_check_yaaaaaa(uint8_t yaaaaaa) { + return (yaaaaaa<=0b01001111 || yaaaaaa==0b01111111 || yaaaaaa==0b11111111); +} + +void Dali::set_level(uint8_t level, uint8_t adr) { + if(_check_yaaaaaa(adr)) tx_wait_rx(adr<<1,level); +} + +int16_t Dali::cmd(uint16_t cmd, uint8_t arg) { + //Serial.print("dali_cmd[");Serial.print(cmd,HEX);Serial.print(",");Serial.print(arg,HEX);Serial.print(")"); + uint8_t cmd0,cmd1; + if(cmd & 0x0100) { + //special commands: MUST NOT have YAAAAAAX pattern for cmd + //Serial.print(" SPC"); + if(!_check_yaaaaaa(cmd>>1)) { + cmd0 = cmd; + cmd1 = arg; + }else{ + return DALI_RESULT_INVALID_CMD; + } + }else{ + //regular commands: MUST have YAAAAAA pattern for arg + + //Serial.print(" REG"); + if(_check_yaaaaaa(arg)) { + cmd0 = arg<<1|1; + cmd1 = cmd; + }else{ + return DALI_RESULT_INVALID_CMD; + } + } + if(cmd & 0x0200) { + //Serial.print(" REPEAT"); + tx_wait_rx(cmd0, cmd1); + } + int16_t rv = tx_wait_rx(cmd0, cmd1); + //Serial.print(" rv=");Serial.println(rv); + return rv; +} + + +uint8_t Dali::set_operating_mode(uint8_t v, uint8_t adr) { + return _set_value(DALI_SET_OPERATING_MODE, DALI_QUERY_OPERATING_MODE, v, adr); +} + +uint8_t Dali::set_max_level(uint8_t v, uint8_t adr) { + return _set_value(DALI_SET_MAX_LEVEL, DALI_QUERY_MAX_LEVEL, v, adr); +} + +uint8_t Dali::set_min_level(uint8_t v, uint8_t adr) { + return _set_value(DALI_SET_MIN_LEVEL, DALI_QUERY_MIN_LEVEL, v, adr); +} + + +uint8_t Dali::set_system_failure_level(uint8_t v, uint8_t adr) { + return _set_value(DALI_SET_SYSTEM_FAILURE_LEVEL, DALI_QUERY_SYSTEM_FAILURE_LEVEL, v, adr); +} + +uint8_t Dali::set_power_on_level(uint8_t v, uint8_t adr) { + return _set_value(DALI_SET_POWER_ON_LEVEL, DALI_QUERY_POWER_ON_LEVEL, v, adr); +} + +//set a parameter value, returns 0 on success +uint8_t Dali::_set_value(uint16_t setcmd, uint16_t getcmd, uint8_t v, uint8_t adr) { + int16_t current_v = cmd(getcmd,adr); //get current parameter value + if(current_v == v) return 0; + cmd(DALI_DATA_TRANSFER_REGISTER0,v); //store value in DTR + int16_t dtr = cmd(DALI_QUERY_CONTENT_DTR0,adr); //get DTR value + if(dtr != v) return 1; + cmd(setcmd,adr); //set parameter value = DTR + current_v = cmd(getcmd,adr); //get current parameter value + if(current_v != v) return 2; + return 0; +} + + + + +//====================================================================== +// Commissioning short addresses +//====================================================================== + +//Sets the slave Note 1 to the INITIALISE status for15 minutes. +//Commands 259 to 270 are enabled only for a slave in this +//status. + +//set search address +void Dali::set_searchaddr(uint32_t adr) { + cmd(DALI_SEARCHADDRH,adr>>16); + cmd(DALI_SEARCHADDRM,adr>>8); + cmd(DALI_SEARCHADDRL,adr); +} + +//set search address, but set only changed bytes (takes less time) +void Dali::set_searchaddr_diff(uint32_t adr_new,uint32_t adr_current) { + if( (uint8_t)(adr_new>>16) != (uint8_t)(adr_current>>16) ) cmd(DALI_SEARCHADDRH,adr_new>>16); + if( (uint8_t)(adr_new>>8) != (uint8_t)(adr_current>>8) ) cmd(DALI_SEARCHADDRM,adr_new>>8); + if( (uint8_t)(adr_new) != (uint8_t)(adr_current) ) cmd(DALI_SEARCHADDRL,adr_new); +} + +//Is the random address smaller or equal to the search address? +//as more than one device can reply, the reply gets garbled +uint8_t Dali::compare() { + uint8_t retry = 2; + while(retry>0) { + //compare is true if we received any activity on the bus as reply. + //sometimes the reply is not registered... so only accept retry times 'no reply' as a real false compare + int16_t rv = cmd(DALI_COMPARE,0x00); + if(rv == -DALI_RESULT_COLLISION) return 1; + if(rv == -DALI_RESULT_INVALID_REPLY) return 1; + if(rv == 0xFF) return 1; + + retry--; + } + return 0; +} + +//The slave shall store the received 6-bit address (AAAAAA) as a short address if it is selected. +void Dali::program_short_address(uint8_t shortadr) { + cmd(DALI_PROGRAM_SHORT_ADDRESS, (shortadr << 1) | 0x01); +} + +//What is the short address of the slave being selected? +uint8_t Dali::query_short_address() { + return cmd(DALI_QUERY_SHORT_ADDRESS, 0x00) >> 1; +} + +//find addr with binary search +uint32_t Dali::find_addr() { + uint32_t adr = 0x800000; + uint32_t addsub = 0x400000; + uint32_t adr_last = adr; + set_searchaddr(adr); + + while(addsub) { + set_searchaddr_diff(adr,adr_last); + adr_last = adr; + //Serial.print("cmpadr="); + //Serial.print(adr,HEX); + uint8_t cmp = compare(); //returns 1 if searchadr > adr + //Serial.print("cmp "); + //Serial.print(adr,HEX); + //Serial.print(" = "); + //Serial.println(cmp); + if(cmp) adr-=addsub; else adr+=addsub; + addsub >>= 1; + } + set_searchaddr_diff(adr,adr_last); + adr_last = adr; + if(!compare()) { + adr++; + set_searchaddr_diff(adr,adr_last); + } + return adr; +} + +//init_arg=11111111 : all without short address +//init_arg=00000000 : all +//init_arg=0AAAAAA1 : only for this shortadr +//returns number of new short addresses assigned +uint8_t Dali::commission(uint8_t init_arg) { + uint8_t cnt = 0; + uint8_t arr[64]; + uint8_t sa; + for(sa=0; sa<64; sa++) arr[sa]=0; + + //start commissioning + cmd(DALI_INITIALISE,init_arg); + cmd(DALI_RANDOMISE,0x00); + //need 100ms pause after RANDOMISE, scan takes care of this... + + //find used short addresses (run always, seems to work better than without...) + for(sa = 0; sa<64; sa++) { + int16_t rv = cmd(DALI_QUERY_STATUS,sa); + if(rv>=0) { + if(init_arg!=0b00000000) arr[sa]=1; //remove address from list if not in "all" mode + } + } + + //find random addresses and assign unused short addresses + while(1) { + uint32_t adr = find_addr(); + if(adr>0xffffff) break; //no more random addresses found -> exit + + //find first unused short address + for(sa=0; sa<64; sa++) { + if(arr[sa]==0) break; + } + if(sa>=64) break; //all 64 short addresses assigned -> exit + + //mark short address as used + arr[sa] = 1; + cnt++; + + //assign short address + program_short_address(sa); + + //Serial.println(query_short_address()); //TODO check read adr, handle if not the same... + + //remove the device from the search + cmd(DALI_WITHDRAW,0x00); + } + + //terminate the DALI_INITIALISE command + cmd(DALI_TERMINATE,0x00); + return cnt; +} + +//====================================================================== +// Memory +//====================================================================== +uint8_t Dali::set_dtr0(uint8_t value, uint8_t adr) { + uint8_t retry=3; + while(retry) { + cmd(DALI_DATA_TRANSFER_REGISTER0,value); //store value in DTR + int16_t dtr = cmd(DALI_QUERY_CONTENT_DTR0,adr); //get DTR value + if(dtr == value) return 0; + retry--; + } + return 1; +} + +uint8_t Dali::set_dtr1(uint8_t value, uint8_t adr) { + uint8_t retry=3; + while(retry) { + cmd(DALI_DATA_TRANSFER_REGISTER1,value); //store value in DTR + int16_t dtr = cmd(DALI_QUERY_CONTENT_DTR1,adr); //get DTR value + if(dtr == value) return 0; + retry--; + } + return 1; +} + +uint8_t Dali::set_dtr2(uint8_t value, uint8_t adr) { + uint8_t retry=3; + while(retry) { + cmd(DALI_DATA_TRANSFER_REGISTER2,value); //store value in DTR + int16_t dtr = cmd(DALI_QUERY_CONTENT_DTR2,adr); //get DTR value + if(dtr == value) return 0; + retry--; + } + return 1; +} + +uint8_t Dali::read_memory_bank(uint8_t bank, uint8_t adr) { + uint16_t rv; + + if(set_dtr0(0, adr)) return 1; + if(set_dtr1(bank, adr)) return 2; + + //uint8_t data[255]; + uint16_t len = cmd(DALI_READ_MEMORY_LOCATION, adr); +#ifdef DALI_DEBUG + Serial.print("memlen="); + Serial.println(len); + for(uint8_t i=0;i=0) { + //data[i] = mem; + Serial.print(i,HEX); + Serial.print(":"); + Serial.print(mem); + Serial.print(" 0x"); + Serial.print(mem,HEX); + Serial.print(" "); + if(mem>=32 && mem <127) Serial.print((char)mem); + Serial.println(); + }else if(mem!=-DALI_RESULT_NO_REPLY) { + Serial.print(i,HEX); + Serial.print(":err="); + Serial.println(mem); + } + //delay(10); + } +#endif + + uint16_t dtr0 = cmd(DALI_QUERY_CONTENT_DTR0,adr); //get DTR value + if(dtr0 != 255) return 4; +} + + +//====================================================================== diff --git a/qqqDALI.h b/qqqDALI.h new file mode 100644 index 0000000..83d5f7e --- /dev/null +++ b/qqqDALI.h @@ -0,0 +1,643 @@ +/*########################################################################### + copyright qqqlab.com / github.com/qqqlab + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Changelog: +2020-11-14 Rewrite with sampling instead of pinchange +2020-11-10 Split off hardware specific code into separate class +2020-11-08 Created & tested on ATMega328 @ 8Mhz +###########################################################################*/ +#include + +//------------------------------------------------- +//LOW LEVEL DRIVER DEFINES +#define DALI_BAUD 1200 + +//low level +#define DALI_OK 0 +#define DALI_RESULT_BUS_NOT_IDLE 1 //can't transmit, bus is not idle +#define DALI_RESULT_FRAME_TOO_LONG 2 //can't transmit, attempting to send more than 32 bits +#define DALI_RESULT_COLLISION 3 //bus collision occured +#define DALI_RESULT_TRANSMITTING 4 //currently transmitting +#define DALI_RESULT_RECEIVING 5 //currently receiving + +//high level +#define DALI_RESULT_NO_REPLY 101 //cmd() did not receive a reply (i.e. received a 'NO' Backward Frame) +#define DALI_RESULT_TIMEOUT 102 //Timeout waiting for DALI bus +#define DALI_RESULT_DATA_TOO_LONG 103 //Trying to send too many bytes (max 3) +#define DALI_RESULT_INVALID_CMD 104 //The cmd argument in the call to cmd() was invalid +#define DALI_RESULT_INVALID_REPLY 105 //cmd() received an invalid reply (not 8 bits) + + +//tx collision handling +#define DALI_TX_COLLISSION_AUTO 0 //handle tx collisions for non 8 bit frames +#define DALI_TX_COLLISSION_OFF 1 //don't handle tx collisions +#define DALI_TX_COLLISSION_ON 2 //handle all tx collisions + +#define DALI_RX_BUF_SIZE 40 + +class Dali { +public: + //------------------------------------------------- + //LOW LEVEL DRIVER PUBLIC + void begin(uint8_t (*bus_is_high)(), void (*bus_set_low)(), void (*bus_set_high)()); + void timer(); //call this function every 104.167 us (1200 baud 8x oversampled) + uint8_t tx(uint8_t *data, uint8_t bitlen); //low level non-blocking transmit + uint8_t rx(uint8_t *data); //low level non-blocking receive + uint8_t tx_state(); //low level tx state, returns DALI_RESULT_COLLISION, DALI_RESULT_TRANSMITTING or DALI_OK + uint8_t txcollisionhandling; //collision handling DALI_TX_COLLISSION_AUTO,DALI_TX_COLLISSION_OFF,DALI_TX_COLLISSION_ON + uint16_t milli(); //millis() implementation, 1 milli is 1.04167 ms (10 timer ticks), rollover 65 seconds + Dali() : busstate(0), ticks(0), _milli(0), idlecnt(0), txcollisionhandling(DALI_TX_COLLISSION_AUTO) {}; //initialize variables + + //------------------------------------------------- + //HIGH LEVEL PUBLIC + void set_level(uint8_t level, uint8_t adr=0xFF); //set arc level + int16_t cmd(uint16_t cmd, uint8_t arg); //execute DALI command, use a DALI_xxx command define as cmd argument, returns negative DALI_RESULT_xxx or reply byte + uint8_t set_operating_mode(uint8_t v, uint8_t adr=0xFF); //returns 0 on success + uint8_t set_max_level(uint8_t v, uint8_t adr=0xFF); //returns 0 on success + uint8_t set_min_level(uint8_t v, uint8_t adr=0xFF); //returns 0 on success + uint8_t set_system_failure_level(uint8_t v, uint8_t adr=0xFF); //returns 0 on success + uint8_t set_power_on_level(uint8_t v, uint8_t adr=0xFF); //returns 0 on success + uint8_t tx_wait(uint8_t* data, uint8_t bitlen, uint16_t timeout_ms=500); //blocking transmit bytes + int16_t tx_wait_rx(uint8_t cmd0, uint8_t cmd1, uint16_t timeout_ms=500); //blocking transmit and receive + + uint8_t read_memory_bank(uint8_t bank, uint8_t adr); + uint8_t set_dtr0(uint8_t value, uint8_t adr); + uint8_t set_dtr1(uint8_t value, uint8_t adr); + uint8_t set_dtr2(uint8_t value, uint8_t adr); + + //commissioning + uint8_t commission(uint8_t init_arg=0xff); + void set_searchaddr(uint32_t adr); + void set_searchaddr_diff(uint32_t adr_new,uint32_t adr_current); + uint8_t compare(); + void program_short_address(uint8_t shortadr); + uint8_t query_short_address(); + uint32_t find_addr(); + +private: + //------------------------------------------------- + //LOW LEVEL DRIVER PRIVATE + + //BUS + volatile uint8_t busstate; //current bus state IDLE,TX,RX,COLLISION_RX,COLLISION_TX + volatile uint8_t ticks; //sample counter, wraps around. 1 tick is approx 0.1 ms, overflow 6.5 seconds + volatile uint16_t _milli; //millisecond counter, wraps around, overflow 256 ms + volatile uint8_t idlecnt; //number of idle samples (capped at 255) + + //RECEIVER + enum rx_stateEnum { EMPTY, RECEIVING, COMPLETED}; + volatile rx_stateEnum rxstate; //state of receiver + volatile uint8_t rxdata[DALI_RX_BUF_SIZE]; //received samples + volatile uint8_t rxpos; //pos in rxdata + volatile uint8_t rxbyte; //last 8 samples, MSB is oldest + volatile uint8_t rxbitcnt; //bitcnt in rxbyte + volatile uint8_t rxidle; //idle tick counter during RX + + + //TRANSMITTER + volatile uint8_t txhbdata[9]; //half bit data to transmit (max 32 bits = 2+64+4 half bits = 9 bytes) + volatile uint8_t txhblen; //number of half bits to transmit, incl start + stop bits + volatile uint8_t txhbcnt; //number of transmitted half bits, incl start + stop bits + volatile uint8_t txspcnt; //sample count since last transmitted bit + volatile uint8_t txhigh; //currently bus is high + volatile uint8_t txcollision; //collision count (capped at 255) + + //hardware abstraction layer + uint8_t (*bus_is_high)(); //returns !=0 if DALI bus is in high (non-asserted) state + void (*bus_set_low)(); //set DALI bus in low (asserted) state + void (*bus_set_high)(); //set DALI bus in high (released) state + + void _init(); + void _set_busstate_idle(); + void _tx_push_2hb(uint8_t hb); + + + uint8_t _man_weight(uint8_t i); + uint8_t _man_sample(uint8_t *edata, uint16_t bitpos, uint8_t *stop_coll); + uint8_t _man_decode(uint8_t *edata, uint8_t ebitlen, uint8_t *ddata); + + //------------------------------------------------- + //HIGH LEVEL PRIVATE + uint8_t _check_yaaaaaa(uint8_t yaaaaaa); //check for yaaaaaa pattern + uint8_t _set_value(uint16_t setcmd, uint16_t getcmd, uint8_t v, uint8_t adr); //set a parameter value, returns 0 on success + +}; + + +//------------------------------------------------- +//HIGH LEVEL DEFINES + +#define DALI_BAUD 1200 + + + +//bit8=extended commands, bit9=repeat +#define DALI_OFF 0 //0 - Turns off lighting. +#define DALI_UP 1 //1 - Increases the lighting control level for 200 ms according to the Fade rate. +#define DALI_DOWN 2 //2 - Decreases the lighting control level for 200 ms according to the Fade rate. +#define DALI_STEP_UP 3 //3 - Increments the lighting control level (without fade). +#define DALI_STEP_DOWN 4 //4 - Decrements the lighting control level (without fade). +#define DALI_RECALL_MAX_LEVEL 5 //5 - Maximizes the lighting control level (without fade). +#define DALI_RECALL_MIN_LEVEL 6 //6 - Minimizes the lighting control level (without fade) +#define DALI_STEP_DOWN_AND_OFF 7 //7 - Decrements the lighting control level and turns off lighting if the level is at the minimum (without fade). +#define DALI_ON_AND_STEP_UP 8 //8 - Increments the lighting control level and turns on lighting if lighting is off (with fade). +#define DALI_ENABLE_DAPC_SEQUENCE 9 //9 - It shows the repeat start of the DAPC command. +#define DALI_GO_TO_LAST_ACTIVE_LEVEL 10 //10 DALI-2 - Adjusts the lighting control level to the last light control level according to the Fade time. (Command that exist only in IEC62386-102ed2.0) +#define DALI_RESERVED11 11 //11 - [Reserved] +#define DALI_RESERVED12 12 //12 - [Reserved] +#define DALI_RESERVED13 13 //13 - [Reserved] +#define DALI_RESERVED14 14 //14 - [Reserved] +#define DALI_RESERVED16 16 //16 - [Reserved] +#define DALI_GO_TO_SCENE0 16 //16 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE1 17 //17 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE2 18 //18 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE3 19 //19 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE4 20 //20 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE5 21 //21 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE6 22 //22 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE7 23 //23 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE8 24 //24 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE9 25 //25 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE10 26 //26 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE11 27 //27 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE12 28 //28 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE13 29 //29 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE14 30 //30 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_GO_TO_SCENE15 31 //31 - Adjusts the lighting control level for Scene XXXX according to the fade time. +#define DALI_RESET 544 //32 REPEAT - Makes a slave an RESET state. +#define DALI_STORE_ACTUAL_LEVEL_IN_THE_DTR0 545 //33 REPEAT - Saves the current lighting control level to the DTR (DTR0). (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SAVE_PERSISTENT_VARIABLES 546 //34 REPEAT DALI-2 - Saves a variable in nonvolatile memory (NVM). (Command that exist only in IEC62386-102ed2.0) +#define DALI_SET_OPERATING_MODE 547 //35 REPEAT DALI-2 - Sets data of DTR0 as an operating mode. (Command that exist only in IEC62386-102ed2.0) +#define DALI_RESET_MEMORY_BANK 548 //36 REPEAT DALI-2 - Changes to the reset value the specified memory bank in DTR0. (Command that exist only in IEC62386-102ed2.0) +#define DALI_IDENTIFY_DEVICE 549 //37 REPEAT DALI-2 - Starts the identification state of the device. (Command that exist only in IEC62386-102ed2.0) +#define DALI_RESERVED38 550 //38 REPEAT - [Reserved] +#define DALI_RESERVED39 551 //39 REPEAT - [Reserved] +#define DALI_RESERVED40 552 //40 REPEAT - [Reserved] +#define DALI_RESERVED41 553 //41 REPEAT - [Reserved] +#define DALI_SET_MAX_LEVEL 554 //42 REPEAT - Specifies the DTR data as the maximum lighting control level. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_MIN_LEVEL 555 //43 REPEAT - Specifies the DTR data as the minimum lighting control level. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SYSTEM_FAILURE_LEVEL 556 //44 REPEAT - Specifies the DTR data as the "FAILURELEVEL". (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_POWER_ON_LEVEL 557 //45 REPEAT - Specifies the DTR data as the "POWER ONLEVEL". (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_FADE_TIME 558 //46 REPEAT - Specifies the DTR data as the Fade time. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_FADE_RATE 559 //47 REPEAT - Specifies the DTR data as the Fade rate. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_EXTENDED_FADE_TIME 560 //48 REPEAT DALI-2 - Specifies the DTR data as the Extended Fade Time. (Command that exist only in IEC62386-102ed2.0) +#define DALI_RESERVED49 561 //49 REPEAT - [Reserved] +#define DALI_RESERVED50 562 //50 REPEAT - [Reserved] +#define DALI_RESERVED51 563 //51 REPEAT - [Reserved] +#define DALI_RESERVED52 564 //52 REPEAT - [Reserved] +#define DALI_RESERVED53 565 //53 REPEAT - [Reserved] +#define DALI_RESERVED54 566 //54 REPEAT - [Reserved] +#define DALI_RESERVED55 567 //55 REPEAT - [Reserved] +#define DALI_RESERVED56 568 //56 REPEAT - [Reserved] +#define DALI_RESERVED57 569 //57 REPEAT - [Reserved] +#define DALI_RESERVED58 570 //58 REPEAT - [Reserved] +#define DALI_RESERVED59 571 //59 REPEAT - [Reserved] +#define DALI_RESERVED60 572 //60 REPEAT - [Reserved] +#define DALI_RESERVED61 573 //61 REPEAT - [Reserved] +#define DALI_RESERVED62 574 //62 REPEAT - [Reserved] +#define DALI_RESERVED63 575 //63 REPEAT - [Reserved] +#define DALI_SET_SCENE0 576 //64 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE1 577 //65 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE2 578 //66 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE3 579 //67 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE4 580 //68 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE5 581 //69 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE6 582 //70 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE7 583 //71 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE8 584 //72 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE9 585 //73 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE10 586 //74 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE11 587 //75 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE12 588 //76 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE13 589 //77 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE14 590 //78 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_SET_SCENE15 591 //79 REPEAT - Specifies the DTR data as Scene XXXX. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_REMOVE_FROM_SCENE0 592 //80 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE1 593 //81 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE2 594 //82 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE3 595 //83 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE4 596 //84 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE5 597 //85 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE6 598 //86 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE7 599 //87 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE8 600 //88 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE9 601 //89 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE10 602 //90 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE11 603 //91 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE12 604 //92 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE13 605 //93 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE14 606 //94 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_REMOVE_FROM_SCENE15 607 //95 REPEAT - Deletes the Scene XXXX setting. (Specifies 1111 1111 for the scene register.) +#define DALI_ADD_TO_GROUP0 608 //96 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP1 609 //97 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP2 610 //98 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP3 611 //99 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP4 612 //100 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP5 613 //101 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP6 614 //102 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP7 615 //103 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP8 616 //104 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP9 617 //105 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP10 618 //106 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP11 619 //107 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP12 620 //108 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP13 621 //109 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP14 622 //110 REPEAT - Adds the slave to Group XXXX. +#define DALI_ADD_TO_GROUP15 623 //111 REPEAT - Adds the slave to Group XXXX. +#define DALI_REMOVE_FROM_GROUP0 624 //112 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP1 625 //113 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP2 626 //114 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP3 627 //115 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP4 628 //116 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP5 629 //117 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP6 630 //118 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP7 631 //119 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP8 632 //120 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP9 633 //121 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP10 634 //122 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP11 635 //123 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP12 636 //124 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP13 637 //125 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP14 638 //126 REPEAT - Deletes the slave from Group XXXX. +#define DALI_REMOVE_FROM_GROUP15 639 //127 REPEAT - Deletes the slave from Group XXXX. +#define DALI_SET_SHORT_ADDRESS 640 //128 REPEAT - Specifies the DTR data as a Short Address. (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_ENABLE_WRITE_MEMORY 641 //129 REPEAT - Allows writing of the memory bank. +#define DALI_RESERVED130 642 //130 REPEAT - [Reserved] +#define DALI_RESERVED131 643 //131 REPEAT - [Reserved] +#define DALI_RESERVED132 644 //132 REPEAT - [Reserved] +#define DALI_RESERVED133 645 //133 REPEAT - [Reserved] +#define DALI_RESERVED134 646 //134 REPEAT - [Reserved] +#define DALI_RESERVED135 647 //135 REPEAT - [Reserved] +#define DALI_RESERVED136 648 //136 REPEAT - [Reserved] +#define DALI_RESERVED137 649 //137 REPEAT - [Reserved] +#define DALI_RESERVED138 650 //138 REPEAT - [Reserved] +#define DALI_RESERVED139 651 //139 REPEAT - [Reserved] +#define DALI_RESERVED140 652 //140 REPEAT - [Reserved] +#define DALI_RESERVED141 653 //141 REPEAT - [Reserved] +#define DALI_RESERVED142 654 //142 REPEAT - [Reserved] +#define DALI_RESERVED143 655 //143 REPEAT - [Reserved] +#define DALI_QUERY_STATUS 144 //144 - Returns "STATUS INFORMATION" +#define DALI_QUERY_CONTROL_GEAR_PRESENT 145 //145 - Is there a slave that can communicate? (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_QUERY_LAMP_FAILURE 146 //146 - Is there a lamp problem? +#define DALI_QUERY_LAMP_POWER_ON 147 //147 - Is a lamp on? +#define DALI_QUERY_LIMIT_ERROR 148 //148 - Is the specified lighting control level out of the range from the minimum to the maximum values? +#define DALI_QUERY_RESET_STATE 149 //149 - Is the slave in 'RESET STATE'? +#define DALI_QUERY_MISSING_SHORT_ADDRESS 150 //150 - Does the slave not have a short address? +#define DALI_QUERY_VERSION_NUMBER 151 //151 - What is the corresponding IEC standard number? +#define DALI_QUERY_CONTENT_DTR0 152 //152 - What is the DTR content? (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_QUERY_DEVICE_TYPE 153 //153 - What is the device type? (fluorescent lamp:0000 0000) (IEC62386-207 is 6 fixed) +#define DALI_QUERY_PHYSICAL_MINIMUM_LEVEL 154 //154 - What is the minimum lighting control level specified by the hardware? +#define DALI_QUERY_POWER_FAILURE 155 //155 - Has the slave operated without the execution of reset-command or the adjustment of the lighting control level? +#define DALI_QUERY_CONTENT_DTR1 156 //156 - What is the DTR1 content? +#define DALI_QUERY_CONTENT_DTR2 157 //157 - What is the DTR2 content? +#define DALI_QUERY_OPERATING_MODE 158 //158 DALI-2 - What is the Operating Mode? (Only IEC62386-102ed2.0 ) +#define DALI_QUERY_LIGHT_SOURCE_TYPE 159 //159 DALI-2 - What is the Light source type? (Only IEC62386-102ed2.0 ) +#define DALI_QUERY_ACTUAL_LEVEL 160 //160 - What is the "ACTUAL LEVEL" (the current lighting control level)? +#define DALI_QUERY_MAX_LEVEL 161 //161 - What is the maximum lighting control level? +#define DALI_QUERY_MIN_LEVEL 162 //162 - What is the minimum lighting control level? +#define DALI_QUERY_POWER_ON_LEVEL 163 //163 - What is the "POWER ON LEVEL" (the lighting control level when the power is turned on)? +#define DALI_QUERY_SYSTEM_FAILURE_LEVEL 164 //164 - What is the "SYSTEM FAILURE LEVEL" (the lighting control level when a failure occurs)? +#define DALI_QUERY_FADE_TIME_FADE_RATE 165 //165 - What are the Fade time and Fade rate? +#define DALI_QUERY_MANUFACTURER_SPECIFIC_MODE 166 //166 DALI-2 - What is the Specific Mode? (Command that exist only in IEC62386-102ed2.0) +#define DALI_QUERY_NEXT_DEVICE_TYPE 167 //167 DALI-2 - What is the next Device Type? (Command that exist only in IEC62386-102ed2.0) +#define DALI_QUERY_EXTENDED_FADE_TIME 168 //168 DALI-2 - What is the Extended Fade Time? (Command that exist only in IEC62386-102ed2.0) +#define DALI_QUERY_CONTROL_GEAR_FAILURE 169 //169 DALI-2 - Does a slave have the abnormality? (Command that exist only in IEC62386-102ed2.0) +#define DALI_RESERVED170 170 //170 - [Reserved] +#define DALI_RESERVED171 171 //171 - [Reserved] +#define DALI_RESERVED172 172 //172 - [Reserved] +#define DALI_RESERVED173 173 //173 - [Reserved] +#define DALI_RESERVED174 174 //174 - [Reserved] +#define DALI_RESERVED175 175 //175 - [Reserved] +#define DALI_QUERY_SCENE0_LEVEL 176 //176 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE1_LEVEL 177 //177 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE2_LEVEL 178 //178 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE3_LEVEL 179 //179 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE4_LEVEL 180 //180 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE5_LEVEL 181 //181 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE6_LEVEL 182 //182 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE7_LEVEL 183 //183 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE8_LEVEL 184 //184 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE9_LEVEL 185 //185 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE10_LEVEL 186 //186 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE11_LEVEL 187 //187 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE12_LEVEL 188 //188 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE13_LEVEL 189 //189 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE14_LEVEL 190 //190 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_SCENE15_LEVEL 191 //191 - What is the lighting control level for SCENE XXXX? +#define DALI_QUERY_GROUPS_0_7 192 //192 - Does the slave belong to a group among groups 0 to 7? (Each bit corresponds to agroup.) +#define DALI_QUERY_GROUPS_8_15 193 //193 - Does the slave belong to a group among groups 8 to 15? (Each bit corresponds to agroup.) +#define DALI_QUERY_RANDOM_ADDRESS_H 194 //194 - What are the higher 8 bits of the random address? +#define DALI_QUERY_RANDOM_ADDRESS_M 195 //195 - What are the middle 8 bits of the random address? +#define DALI_QUERY_RANDOM_ADDRESS_L 196 //196 - What are the lower 8 bits of the random address? +#define DALI_READ_MEMORY_LOCATION 197 //197 - What is the memory location content? +#define DALI_RESERVED198 198 //198 - [Reserved] +#define DALI_RESERVED199 199 //199 - [Reserved] +#define DALI_RESERVED200 200 //200 - [Reserved] +#define DALI_RESERVED201 201 //201 - [Reserved] +#define DALI_RESERVED202 202 //202 - [Reserved] +#define DALI_RESERVED203 203 //203 - [Reserved] +#define DALI_RESERVED204 204 //204 - [Reserved] +#define DALI_RESERVED205 205 //205 - [Reserved] +#define DALI_RESERVED206 206 //206 - [Reserved] +#define DALI_RESERVED207 207 //207 - [Reserved] +#define DALI_RESERVED208 208 //208 - [Reserved] +#define DALI_RESERVED209 209 //209 - [Reserved] +#define DALI_RESERVED210 210 //210 - [Reserved] +#define DALI_RESERVED211 211 //211 - [Reserved] +#define DALI_RESERVED212 212 //212 - [Reserved] +#define DALI_RESERVED213 213 //213 - [Reserved] +#define DALI_RESERVED214 214 //214 - [Reserved] +#define DALI_RESERVED215 215 //215 - [Reserved] +#define DALI_RESERVED216 216 //216 - [Reserved] +#define DALI_RESERVED217 217 //217 - [Reserved] +#define DALI_RESERVED218 218 //218 - [Reserved] +#define DALI_RESERVED219 219 //219 - [Reserved] +#define DALI_RESERVED220 220 //220 - [Reserved] +#define DALI_RESERVED221 221 //221 - [Reserved] +#define DALI_RESERVED222 222 //222 - [Reserved] +#define DALI_RESERVED223 223 //223 - [Reserved] +#define DALI_REFERENCE_SYSTEM_POWER 224 //224 IEC62386-207 - Starts power measurement. (Command that exist only in IEC62386-207) +#define DALI_ENABLE_CURRENT_PROTECTOR 225 //225 IEC62386-207 - Enables the current protection. (Command that exist only in IEC62386-207) +#define DALI_DISABLE_CURRENT_PROTECTOR 226 //226 IEC62386-207 - Disables the current protection. (Command that exist only in IEC62386-207) +#define DALI_SELECT_DIMMING_CURVE 227 //227 IEC62386-207 - Selects Dimming curve. (Command that exist only in IEC62386-207) +#define DALI_STORE_DTR_AS_FAST_FADE_TIME 228 //228 IEC62386-207 - Sets the DTR of the data as Fast Fade Time.(Command that exist only in IEC62386-207) +#define DALI_RESERVED229 229 //229 - [Reserved] +#define DALI_RESERVED230 230 //230 - [Reserved] +#define DALI_RESERVED231 231 //231 - [Reserved] +#define DALI_RESERVED232 232 //232 - [Reserved] +#define DALI_RESERVED233 233 //233 - [Reserved] +#define DALI_RESERVED234 234 //234 - [Reserved] +#define DALI_RESERVED235 235 //235 - [Reserved] +#define DALI_RESERVED236 236 //236 - [Reserved] +#define DALI_QUERY_GEAR_TYPE 237 //237 IEC62386-207 - Returns ‘GEAR TYPE’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_DIMMING_CURVE 238 //238 IEC62386-207 - Returns ’Dimming curve’in use (Command that exist only in IEC62386-207) +#define DALI_QUERY_POSSIBLE_OPERATING_MODE 239 //239 IEC62386-207 - Returns ‘POSSIBLEG OPERATING MODE’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_FEATURES 240 //240 IEC62386-207 - Returns ‘FEATURES’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_FAILURE_STATUS 241 //241 IEC62386-207 - Returns ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_SHORT_CIRCUIT 242 //242 IEC62386-207 - Returns bit0 short circuit of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_OPEN_CIRCUIT 243 //243 IEC62386-207 - Returns bit1 open circuit of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_LOAD_DECREASE 244 //244 IEC62386-207 - Returns bit2 load decrease of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_LOAD_INDREASE 245 //245 IEC62386-207 - Returns bit3 load increase of‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_CURRENT_PROTECTOR_ACTIVE 246 //246 IEC62386-207 - Returns bit4 current protector active of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_THERMAL_SHUTDOWN 247 //247 IEC62386-207 - Returns bit5 thermal shut down of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_THERMAL_OVERLOAD 248 //248 IEC62386-207 - Returns bit6 thermal overload with light level reduction of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_REFARENCE_RUNNING 249 //249 IEC62386-207 - Returns whetherReference System Power is in operation. (Command that exist only in IEC62386-207) +#define DALI_QUERY_REFERENCE_MEASURMENT_FAILED 250 //250 IEC62386-207 - Returns bit7 reference measurement failed of ‘FAILURE STATUS’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_CURRENT_PROTECTOR_ENABLE 251 //251 IEC62386-207 - Returns state of Curent protector (Command that exist only in IEC62386-207) +#define DALI_QUERY_OPERATING_MODE 252 //252 IEC62386-207 - Returns ‘OPERATING MODE’ (Command that exist only in IEC62386-207) +#define DALI_QUERY_FAST_FADE_TIME 253 //253 IEC62386-207 - Returns set Fast fade time. (Command that exist only in IEC62386-207) +#define DALI_QUERY_MIN_FAST_FADE_TIME 254 //254 IEC62386-207 - Returns set Minimum fast fade time (Command that exist only in IEC62386-207) +#define DALI_QUERY_EXTENDED_VERSION_NUMBER 255 //255 IEC62386-207 - The version number of the extended support? IEC62386-207: 1, Other: NO(no response) +#define DALI_TERMINATE 0x01A1 //256 - Releases the INITIALISE state. +#define DALI_DATA_TRANSFER_REGISTER0 0x01A3 //257 - Stores the data XXXX XXXX to the DTR(DTR0). (In the parenthesis is a name in IEC62386-102ed2.0) +#define DALI_INITIALISE 0x03A5 //258 REPEAT - Sets the slave to the INITIALISE status for15 minutes. Commands 259 to 270 are enabled only for a slave in this status. +#define DALI_RANDOMISE 0x03A7 //259 REPEAT - Generates a random address. +#define DALI_COMPARE 0x01A9 //260 - Is the random address smaller or equal to the search address? +#define DALI_WITHDRAW 0x01AB //261 - Excludes slaves for which the random address and search address match from the Compare process. +#define DALI_RESERVED262 0x01AD //262 - [Reserved] +#define DALI_PING 0x01AF //263 DALI-2 - Ignores in the slave. (Command that exist only in IEC62386-102ed2.0) +#define DALI_SEARCHADDRH 0x01B1 //264 - Specifies the higher 8 bits of the search address. +#define DALI_SEARCHADDRM 0x01B3 //265 - Specifies the middle 8 bits of the search address. +#define DALI_SEARCHADDRL 0x01B5 //266 - Specifies the lower 8 bits of the search address. +#define DALI_PROGRAM_SHORT_ADDRESS 0x01B7 //267 - The slave shall store the received 6-bit address (AAA AAA) as a short address if it is selected. +#define DALI_VERIFY_SHORT_ADDRESS 0x01B9 //268 - Is the short address AAA AAA? +#define DALI_QUERY_SHORT_ADDRESS 0x01BB //269 - What is the short address of the slaveNote 2being selected? +#define DALI_PHYSICAL_SELECTION 0x01BD //270 not DALI-2 - Sets the slave to Physical Selection Mode and excludes the slave from the Compare process. (Excluding IEC62386-102ed2.0) (Command that exist only in IEC62386-102ed1.0, -207ed1.0) +#define DALI_RESERVED271 0x01BF //271 - [Reserved] +#define DALI_ENABLE_DEVICE_TYPE_X 0x01C1 //272 - Adds the device XXXX (a special device). +#define DALI_DATA_TRANSFER_REGISTER1 0x01C3 //273 - Stores data XXXX into DTR1. +#define DALI_DATA_TRANSFER_REGISTER2 0x01C5 //274 - Stores data XXXX into DTR2. +#define DALI_WRITE_MEMORY_LOCATION 0x01C7 //275 - Write data into the specified address of the specified memory bank. (There is BW) (DTR(DTR0):address, DTR1:memory bank number) +#define DALI_WRITE_MEMORY_LOCATION_NO_REPLY 0x01C9 //276 DALI-2 - Write data into the specified address of the specified memory bank. (There is no BW) (DTR(DTR0):address, TR1:memory bank number) (Command that exist only in IEC62386-102ed2.0) +#define DALI_RESERVED277 0x01CB //277 - [Reserved] +#define DALI_RESERVED278 0x01CD //278 - [Reserved] +#define DALI_RESERVED279 0x01CF //279 - [Reserved] +#define DALI_RESERVED280 0x01D1 //280 - [Reserved] +#define DALI_RESERVED281 0x01D3 //281 - [Reserved] +#define DALI_RESERVED282 0x01D5 //282 - [Reserved] +#define DALI_RESERVED283 0x01D7 //283 - [Reserved] +#define DALI_RESERVED284 0x01D9 //284 - [Reserved] +#define DALI_RESERVED285 0x01DB //285 - [Reserved] +#define DALI_RESERVED286 0x01DD //286 - [Reserved] +#define DALI_RESERVED287 0x01DF //287 - [Reserved] +#define DALI_RESERVED288 0x01E1 //288 - [Reserved] +#define DALI_RESERVED289 0x01E3 //289 - [Reserved] +#define DALI_RESERVED290 0x01E5 //290 - [Reserved] +#define DALI_RESERVED291 0x01E7 //291 - [Reserved] +#define DALI_RESERVED292 0x01E9 //292 - [Reserved] +#define DALI_RESERVED293 0x01EB //293 - [Reserved] +#define DALI_RESERVED294 0x01ED //294 - [Reserved] +#define DALI_RESERVED295 0x01DF //295 - [Reserved] +#define DALI_RESERVED296 0x01F1 //296 - [Reserved] +#define DALI_RESERVED297 0x01F3 //297 - [Reserved] +#define DALI_RESERVED298 0x01F5 //298 - [Reserved] +#define DALI_RESERVED299 0x01F7 //299 - [Reserved] +#define DALI_RESERVED300 0x01F9 //300 - [Reserved] +#define DALI_RESERVED301 0x01FB //301 - [Reserved] +#define DALI_RESERVED302 0x01FD //302 - [Reserved] + + + + +/* +SIGNAL CHARACTERISTICS +High Level: 9.5 to 22.5 V (Typical 16 V) +Low Level: -6.5 to + 6.5 V (Typical 0 V) +Te = half cycle = 416.67 us +/- 10 % +10 us <= tfall <= 100 us +10 us <= trise <= 100 us + +BIT TIMING +msb send first + logical 1 = 1Te Low 1Te High + logical 0 = 1Te High 1Te Low + Start bit = logical 1 + Stop bit = 2Te High + +FRAME TIMING +FF: TX Forward Frame 2 bytes (38Te) = 2*(1start+16bits+2stop) +BF: RX Backward Frame 1 byte (22Te) = 2*(1start+8bits+2stop) +no reply: FF >22Te pause FF +with reply: FF >7Te <22Te pause BF >22Te pause FF + + +DALI commands +============= +In accordance with the DIN EN 60929 standard, addresses and commands are transmitted as numbers with a length of two bytes. + +These commands take the form YAAA AAAS xxXXxx. Each letter here stands for one bit. + +Y: type of address + 0bin: short address + 1bin: group address or collective call + +A: significant address bit + +S: selection bit (specifies the significance of the following eight bits): + 0bin: the 8 xxXXxx bits contain a value for direct control of the lamp power + 1bin: the 8 xxXXxx bits contain a command number. + +x: a bit in the lamp power or in the command number + + +Type of Addresses +================= +Type of Addresses Byte Description +Short address 0AAAAAAS (AAAAAA = 0 to 63, S = 0/1) +Group address 100AAAAS (AAAA = 0 to 15, S = 0/1) +Broadcast address 1111111S (S = 0/1) +Special command 101CCCC1 (CCCC = command number) + + +Direct DALI commands for lamp power +=================================== +These commands take the form YAAA AAA0 xxXXxx. + +xxXXxx: the value representing the lamp power is transmitted in these 8 bits. It is calculated according to this formula: + +Pvalue = 10 ^ ((value-1) / (253/3)) * Pmax / 1000 + +253 values from 1dec to 254dec are available for transmission in accordance with this formula. + +There are also 2 direct DALI commands with special meanings: + +Command; Command No; Description; Answer +00hex; 0dec; The DALI device dims using the current fade time down to the parameterised MIN value, and then switches off.; - +FFhex; 254dec; Mask (no change): this value is ignored in what follows, and is therefore not loaded into memory.; - + + +Indirect DALI commands for lamp power +===================================== +These commands take the form YAAA AAA1 xxXXxx. + +xxXXxx: These 8 bits transfer the command number. The available command numbers are listed and explained in the following tables in hexadecimal and decimal formats. + +Command; Command No; Description; Answer +00hex 0dez Extinguish the lamp (without fading) - +01hex 1dez Dim up 200 ms using the selected fade rate - +02hex 2dez Dim down 200 ms using the selected fade rate - +03hex 3dez Set the actual arc power level one step higher without fading. If the lamp is off, it will be not ignited. - +04hex 4dez Set the actual arc power level one step lower without fading. If the lamp has already it's minimum value, it is not switched off. - +05hex 5dez Set the actual arc power level to the maximum value. If the lamp is off, it will be ignited. - +06hex 6dez Set the actual arc power level to the minimum value. If the lamp is off, it will be ignited. - +07hex 7dez Set the actual arc power level one step lower without fading. If the lamp has already it's minimum value, it is switched off. - +08hex 8dez Set the actual arc power level one step higher without fading. If the lamp is off, it will be ignited. - +09hex ... 0Fhex 9dez ... 15dez reserved - +1nhex +(n: 0hex ... Fhex) 16dez ... 31dez Set the light level to the value stored for the selected scene (n) - + + +Configuration commands +====================== +Command; Command No; Description; Answer +20hex 32dez Reset the parameters to default settings - +21hex 33dez Store the current light level in the DTR (Data Transfer Register) - +22hex ... 29hex 34dez ... 41dez reserved - +2Ahex 42dez Store the value in the DTR as the maximum level - +2Bhex 43dez Store the value in the DTR as the minimum level - +2Chex 44dez Store the value in the DTR as the system failure level - +2Dhex 45dez Store the value in the DTR as the power on level - +2Ehex 46dez Store the value in the DTR as the fade time - +2Fhex 47dez Store the value in the DTR as the fade rate - +30hex ... 3Fhex 48dez ... 63dez reserved - +4nhex +(n: 0hex ... Fhex) 64dez ... 79dez Store the value in the DTR as the selected scene (n) - +5nhex +(n: 0hex ... Fhex) 80dez ... 95dez Remove the selected scene (n) from the DALI slave - +6nhex +(n: 0hex ... Fhex) 96dez ... 111dez Add the DALI slave unit to the selected group (n) - +7nhex +(n: 0hex ... Fhex) 112dez ... 127dez Remove the DALI slave unit from the selected group (n) - +80hex 128dez Store the value in the DTR as a short address - +81hex ... 8Fhex 129dez ... 143dez reserved - +90hex 144dez Returns the status (XX) of the DALI slave XX +91hex 145dez Check if the DALI slave is working yes/no +92hex 146dez Check if there is a lamp failure yes/no +93hex 147dez Check if the lamp is operating yes/no +94hex 148dez Check if the slave has received a level out of limit yes/no +95hex 149dez Check if the DALI slave is in reset state yes/no +96hex 150dez Check if the DALI slave is missing a short address XX +97hex 151dez Returns the version number as XX +98hex 152dez Returns the content of the DTR as XX +99hex 153dez Returns the device type as XX +9Ahex 154dez Returns the physical minimum level as XX +9Bhex 155dez Check if the DALI slave is in power failure mode yes/no +9Chex ... 9Fhex 156dez ... 159dez reserved - +A0hex 160dez Returns the current light level as XX +A1hex 161dez Returns the maximum allowed light level as XX +A2hex 162dez Returns the minimum allowed light level as XX +A3hex 163dez Return the power up level as XX +A4hex 164dez Returns the system failure level as XX +A5hex 165dez Returns the fade time as X and the fade rate as Y XY +A6hex ... AFhex 166dez ... 175dez reserved - +Bnhex +(n: 0hex ... Fhex) 176dez ... 191dez Returns the light level XX for the selected scene (n) XX +C0hex 192dez Returns a bit pattern XX indicating which group (0-7) the DALI slave belongs to XX +C1hex 193dez Returns a bit pattern XX indicating which group (8-15) the DALI slave belongs to XX +C2hex 194dez Returns the high bits of the random address as HH +C3hex 195dez Return the middle bit of the random address as MM +C4hex 196dez Returns the lower bits of the random address as LL +C5hex ... DFhex 197dez ... 223dez reserved - +E0hex ... FFhex 224dez ... 255dez Returns application specific extension commands + + +Note Repeat of DALI commands +============================ +According to IEC 60929, a DALI Master has to repeat several commands within 100 ms, so that DALI-Slaves will execute them. + +The DALI Master Terminal KL6811 repeats the commands 32dez to 128dez, 258dez and 259dez (bold marked) automatically to make the the double call from the user program unnecessary. + +The DALI Master Terminal KL6811 repeats also the commands 224dez to 255dez, if you have activated this with Bit 1 of the Control-Byte (CB.1) before. + + +DALI Control Device Type List +============================= +Type DEC Type HEX Name Comments +128 0x80 Unknown Device. If one of the devices below don't apply +129 0x81 Switch Device A Wall-Switch based Controller including, but not limited to ON/OFF devices, Scene switches, dimming device. +130 0x82 Slide Dimmer An analog/positional dimming controller +131 0x83 Motion/Occupancy Sensor. A device that indicates the presence of people within a control area. +132 0x84 Open-loop daylight Controller. A device that outputs current light level and/or sends control messages to actuators based on light passing a threshold. +133 0x85 Closed-loop daylight controller. A device that outputs current light level and/or sends control messages to actuators based on a change in light level. +134 0x86 Scheduler. A device that establishes the building mode based on time of day, or which provides control outputs. +135 0x87 Gateway. An interface to other control systems or communication busses +136 0x88 Sequencer. A device which sequences lights based on a triggering event +137 0x89 Power Supply *). A DALI Power Supply device which supplies power for the communication loop +138 0x8a Emergency Lighting Controller. A device, which is certified for use in control of emergency lighting, or, if not certified, for noncritical backup lighting. +139 0x8b Analog input unit. A general device with analog input. +140 0x8c Data Logger. A unit logging data (can be digital or analog data) + + +Flash Variables and Offset in Information +========================================= +Memory Name Offset +Power On Level [0] +System Failure Level [1] +Minimum Level [2] +Maximum Level [3] +Fade Rate [4] +Fade Time [5] +Short Address [6] +Group 0 through 7 [7] +Group 8 through 15 [8] +Scene 0 through 15 [9-24] +Random Address [25-27] +Fast Fade Time [28] +Failure Status [29] +Operating Mode [30] +Dimming Curve [31] +*/ -- libgit2 0.21.4