// Auto-generated file by ./make_pde.sh #define MODULE_WEBSERVER 1 #define MODULE_TELNET 1 // Auto-generated file by ./make_pde.sh //#define MODULE_WEBSERVER 1 //#define MODULE_TELNET 1 #define MODULE_RANGES 1 //#define MODULE_SD 1 #ifndef DOMINO_H #define DOMINO_H //#include // function declaration #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define MEGA 1 #endif #ifdef MEGA // ====[ Arduino Mega board ]================================ #define DIGITALPORTS 54 //!< Digital ports count #define ANALOGPORTS 16 //!< Analog ports count #define VIRTUALPORTS 10 //!< Virtual ports count #define MAXLINKS 99 //!< Maximum number of links /// EEPROM Memory distribution #define FUNCSPACE 1000 //!< Total space for on-board functions #define EMPORTSOFFSET 0 //!< Bytes 0000-1399 Ports configuration #define EMVPORTOFFSET 1400 //!< Bytes 1400-2299 Virtual ports #define EMLINKSOFFSET 2300 //!< Bytes 2300-2999 Links #define EMNETCFOFFSET 3000 //!< Bytes 3000-3020 Network: MAC(6) + IP(4) + GW(4) + MASK(4) #define EMBOARDOFFSET 3050 //!< Bytes 3050-3099 Additional board information (name) #define EMFUNCSOFFSET 3100 //!< Bytes 3100-4100 On-board functions #define EMSEGMENTS 200 //!< Number of segments in \ref EEPROM #else // =======[ Arduino Duemilanove and Uno boards ]===================== #define DIGITALPORTS 14 //!< Number of digital ports #define ANALOGPORTS 6 //!< Number of analog ports #define VIRTUALPORTS 4 //!< Number of virtual ports #define MAXLINKS 8 //!< Maximum number of links // EEPROM Memory distribution #define FUNCSPACE 100 //!< Total space for on-board functions #define EMPORTSOFFSET 0 //!< \ref EEPROM Bytes 000-399 Ports configuration #define EMVPORTOFFSET 400 //!< \ref EEPROM Bytes 400-499 Virtual ports #define EMLINKSOFFSET 500 //!< \ref EEPROM Bytes 500-699 Links #define EMNETCFOFFSET 800 //!< \ref EEPROM Bytes 800-820 Network: MAC(6) + IP(4)+GW(4)+MASK(4) #define EMBOARDOFFSET 850 //!< \ref EEPROM Bytes 850-899 Additional board information (name) #define EMFUNCSOFFSET 900 //!< \ref EEPROM Bytes 900-999 On-board functions #define EMSEGMENTS 50 //!< Number of segments in \ref EEPROM #endif #define EMPORTSLOT 20 //!< Reserved bytes for each port #define DELAYCYCLE 100 //!< Delay in each cycle, in milliseconds #define BUFFERSIZE 20 //!< Maximum lenght for the command #define MAXCHANGES 6 //!< Maximum number of changes allowed per second /// Encoded values #define ANALOG 65 //!< Alias for ANALOG ! ANALOG DIGITAL #define DIGITAL 68 //!< Alias for DIGITAL --+---------------- #define IN 73 //!< Alias for INPUT ! a d #define OUT 79 //!< Alias for OUTPUT ! A D #define OFF 0 //!< Alias for OFF #define ON HIGH //!< Alias for ON ///! Event types enum eventType { DEBUG = 68, NOTICE = 78, WARNING = 87, ALARM = 65, ERROR = 69, INFO = 73 }; byte h2d(char a, char b) __attribute__((noinline)); void print_error(byte out, int code) __attribute__((noinline)); void print_cmdok(byte out) __attribute__((noinline)); int setPortValue(byte i, int value) __attribute__((noinline)); int processInstruction(const char *cmd) __attribute__((noinline)); int initNetwork(); void writef(byte out, const char* fmt, ...); //char *flstr(prog_char *flash_str) __attribute__((noinline)); char * itoan(int val, char *result, byte len); int ethSetIP(byte ipb1, byte ipb2, byte ipb3, byte ipb4); int ethSetMAC(byte macb3, byte macb4, byte macb5, byte macb6); int ethSetGW(byte ipb1, byte ipb2, byte ipb3, byte ipb4); int ethSetNetmask(byte ipb1, byte ipb2, byte ipb3, byte ipb4); // {{{ writef(): personalized printf void writef(byte out, const char *fmt, ...) { va_list ap, ap2; short d; char c, *s; char i[6]; va_start(ap, fmt); while (*fmt) { if (*fmt == '%') { *fmt++; switch (*fmt) { case 's': s = va_arg(ap, char*); owrite(out, s); break; case 'd': d = va_arg(ap, int); itoan(d, i, sizeof(i)); owrite(out, i); break; case 'c': c = va_arg(ap, int); i[0]=char(c); i[1]=0; owrite(out, i); } *fmt++; } else { i[0]=char(*fmt); i[1]=0; owrite(out, i); *fmt++; } } va_end(ap); } // }}} //{{{ flstrn() copies a string from flash to a buffer // The function returns a pointer to the buffer or NULL if failed char *flstrn(prog_char *flash_str, char *buffer, byte len){ byte i=0; char c; buffer[0]=0; if (!flash_str) return NULL; while ((c = pgm_read_byte(flash_str++)) && i < len - 1) buffer[i++] = c; buffer[i] = 0; return buffer; } //}}} /* {{{ flstr() read string from flash memory // Uses a circular buffer of 3 strings, you cannot use it more than three times // without losing the internal buffer. char *flstr(prog_char * flash_str) { int i = 0; char c; char buffer[16]; static int idx = 0; static char b0[16]; static char b1[16]; static char b2[16]; if (!flash_str) return ""; while ((c = pgm_read_byte(flash_str++)) && i < sizeof(buffer) - 1) buffer[i++] = c; buffer[i] = 0; switch (idx++) { case 0: strlcpy(b0, buffer, sizeof(b0)); return b0; break; case 1: strlcpy(b1, buffer, sizeof(b1)); return b1; break; case 2: strlcpy(b2, buffer, sizeof(b2)); idx = 0; return b2; break; } return b0; } // }}} */ /// table for encoding characters in precompilation #define BYTE1_A 0b000010000000000 #define BYTE1_B 0b000100000000000 #define BYTE1_C 0b000110000000000 #define BYTE1_D 0b001000000000000 #define BYTE1_E 0b001010000000000 #define BYTE1_F 0b001100000000000 #define BYTE1_G 0b001110000000000 #define BYTE1_H 0b010000000000000 #define BYTE1_I 0b010010000000000 #define BYTE1_J 0b010100000000000 #define BYTE1_K 0b010110000000000 #define BYTE1_L 0b011000000000000 #define BYTE1_M 0b011010000000000 #define BYTE1_N 0b011100000000000 #define BYTE1_O 0b011110000000000 #define BYTE1_P 0b100000000000000 #define BYTE1_Q 0b100010000000000 #define BYTE1_R 0b100100000000000 #define BYTE1_S 0b100110000000000 #define BYTE1_T 0b101000000000000 #define BYTE1_U 0b101010000000000 #define BYTE1_V 0b101100000000000 #define BYTE1_W 0b101110000000000 #define BYTE1_X 0b110000000000000 #define BYTE1_Y 0b110010000000000 #define BYTE1_Z 0b110100000000000 #define BYTE2_A 0b0000100000 #define BYTE2_B 0b0001000000 #define BYTE2_C 0b0001100000 #define BYTE2_D 0b0010000000 #define BYTE2_E 0b0010100000 #define BYTE2_F 0b0011000000 #define BYTE2_G 0b0011100000 #define BYTE2_H 0b0100000000 #define BYTE2_I 0b0100100000 #define BYTE2_J 0b0101000000 #define BYTE2_K 0b0101100000 #define BYTE2_L 0b0110000000 #define BYTE2_M 0b0110100000 #define BYTE2_N 0b0111000000 #define BYTE2_O 0b0111100000 #define BYTE2_P 0b1000000000 #define BYTE2_Q 0b1000100000 #define BYTE2_R 0b1001000000 #define BYTE2_S 0b1001100000 #define BYTE2_T 0b1010000000 #define BYTE2_U 0b1010100000 #define BYTE2_V 0b1011000000 #define BYTE2_W 0b1011100000 #define BYTE2_X 0b1100000000 #define BYTE2_Y 0b1100100000 #define BYTE2_Z 0b1101000000 #define BYTE3_A 0b00001 #define BYTE3_B 0b00010 #define BYTE3_C 0b00011 #define BYTE3_D 0b00100 #define BYTE3_E 0b00101 #define BYTE3_F 0b00110 #define BYTE3_G 0b00111 #define BYTE3_H 0b01000 #define BYTE3_I 0b01001 #define BYTE3_J 0b01010 #define BYTE3_K 0b01011 #define BYTE3_L 0b01100 #define BYTE3_M 0b01101 #define BYTE3_N 0b01110 #define BYTE3_O 0b01111 #define BYTE3_P 0b10000 #define BYTE3_Q 0b10001 #define BYTE3_R 0b10010 #define BYTE3_S 0b10011 #define BYTE3_T 0b10100 #define BYTE3_U 0b10101 #define BYTE3_V 0b10110 #define BYTE3_W 0b10111 #define BYTE3_X 0b11000 #define BYTE3_Y 0b11001 #define BYTE3_Z 0b11010 // {{{ instructions are encoded into integer a + b + c #define CMD_AMN BYTE1_A + BYTE2_M + BYTE3_N #define CMD_AMX BYTE1_A + BYTE2_M + BYTE3_X #define CMD_CFG BYTE1_C + BYTE2_F + BYTE3_G #define CMD_DEB BYTE1_D + BYTE2_E + BYTE3_B #define CMD_DEF BYTE1_D + BYTE2_E + BYTE3_F #define CMD_ECH BYTE1_E + BYTE2_C + BYTE3_H #define CMD_ETH BYTE1_E + BYTE2_T + BYTE3_H #define CMD_EXE BYTE1_E + BYTE2_X + BYTE3_E #define CMD_FXA BYTE1_F + BYTE2_X + BYTE3_A #define CMD_FXB BYTE1_F + BYTE2_X + BYTE3_B #define CMD_HIB BYTE1_H + BYTE2_I + BYTE3_B #define CMD_LBL BYTE1_L + BYTE2_B + BYTE3_L #define CMD_LCF BYTE1_L + BYTE2_C + BYTE3_F #define CMD_LLN BYTE1_L + BYTE2_L + BYTE3_N #define CMD_LNK BYTE1_L + BYTE2_N + BYTE3_K #define CMD_LOA BYTE1_L + BYTE2_O + BYTE3_A #define CMD_LST BYTE1_L + BYTE2_S + BYTE3_T #define CMD_MAP BYTE1_M + BYTE2_A + BYTE3_P #define CMD_MEM BYTE1_M + BYTE2_E + BYTE3_M #define CMD_PUT BYTE1_P + BYTE2_U + BYTE3_T #define CMD_RES BYTE1_R + BYTE2_E + BYTE3_S #define CMD_RNG BYTE1_R + BYTE2_N + BYTE3_G #define CMD_SAV BYTE1_S + BYTE2_A + BYTE3_V #define CMD_SET BYTE1_S + BYTE2_E + BYTE3_T #define CMD_SNM BYTE1_S + BYTE2_N + BYTE3_M #define CMD_SUB BYTE1_S + BYTE2_U + BYTE3_B #define CMD_TOL BYTE1_T + BYTE2_O + BYTE3_L #define CMD_TST BYTE1_T + BYTE2_S + BYTE3_T #define CMD_UNL BYTE1_U + BYTE2_N + BYTE3_L #define CMD_UPT BYTE1_U + BYTE2_P + BYTE3_T #define CMD_VER BYTE1_V + BYTE2_E + BYTE3_R #define CMD_WMX BYTE1_W + BYTE2_M + BYTE3_X #define CMD_WMN BYTE1_W + BYTE2_M + BYTE3_N #define CMD_GRP BYTE1_G + BYTE2_R + BYTE3_P #define CMD_SOP BYTE1_S + BYTE2_O + BYTE3_P #define CMD_CSS BYTE1_C + BYTE2_S + BYTE3_S // }}} // {{{ /** \page Func On-Board functions Domino can store configurable functions in the configuration space. This routines are stored in the \ref EMFUNCSOFFSET and are processed by \ref executeNextInstruction, one instruction in every cycle of the main loop. The commands supported are encoded in one Byte per instruction: - \ref INS_END - \ref INS_SET - \ref INS_DECREASE - \ref INS_INCREASE - \ref INS_JMP - \ref INS_JMP_IF_ISZERO - \ref INS_JMP_IF_NOTZERO */ #define INS_END 0 //!< Exit the program #define INS_SET 83 //!< Set the value of the port #define INS_AND 97 //!< Logic AND #define INS_OR 111 //!< Logic OR #define INS_DECREASE 68 //!< Decrease the value of the port #define INS_INCREASE 73 //!< Increase the value of the port #define INS_JMP 74 //!< Jump to another instruction #define INS_JIF_ISZERO 90 //!< Jump if port value is zero #define INS_JIF_NOTZERO 78 //!< Jump if port value is not zero #define INS_STORE 115 //!< Save the value to main register #define INS_JIF_GT 62 //!< Jump if value is greater than (main register) #define INS_JIF_LT 60 //!< Jump if value is greater than (main register) // }}} unsigned char eeprom_get_byte(int byte_index) { return eeprom_read_byte((unsigned char*) byte_index); } void eeprom_set_byte(int byte_index, byte value) { eeprom_write_byte((unsigned char*)byte_index,value); } // {{{ eeprom_get_ushort(): read an unsigned short from eeprom unsigned short eeprom_get_ushort(int byte_index) { unsigned short s = 0; s = eeprom_get_byte(byte_index); s = s << 8; s ^= eeprom_get_byte(byte_index + 1); return s; } // }}} // {{{ eeprom_set_ushort(): write an unsigned short into eeprom unsigned short eeprom_set_ushort(int byte_index, unsigned short value) { char sl = 0; char sr = 0; sl = value >> 8; sr = value; eeprom_set_byte(byte_index, sl); eeprom_set_byte(byte_index + 1, sr); } // }}} // {{{ eeprom_get_str() int eeprom_get_str(char *dst, int addr, size_t len) { eeprom_read_block((void*)dst, (void*)addr, len); dst[5] = 0; } // }}} // {{{ eeprom_set_str() int eeprom_set_str(int addr, char *src, size_t len) { eeprom_write_block((void*)src, (void*)addr, len); } // }}} void eeprom_reset() { for (int i=0;i