VM201 TCP protocol /****************************************************************************** * Generic TCP Protocol description * Packet : ... * STX : 0x0F * LEN : number of bytes in packet incl. STX & CHECKSUM * CMD : command byte * data_x : optional data bytes * CHECKSUM : two-complement of the sum of all previous bytes in the packet * ETX : 0x04 * * 1a.At opening a connection and no authentication is needed there will be send: * - logged in successfully: <5> * 1b.At opening a connection and authentication is needed there will be send: * - authentication needed: <5> * the client will answer with username and password (max 8 characters): * - username: <14>... * - password: <14>... * if the username and password are invalid the following packets will be send: * - access denied: <5> * - session closed: <5> * - the client will be disconnected * if the username and password are valid the following packets will be send: * - logged in successfully: <5> * 2.After successfully logged in the names (max 16 characters) of the 8 output channels and input will be send: * - channel names: <22>... * 3.The status will be send: * - output, timer & input status: <8> * output status bits 7...0 = channels 8...1 ; bit=0 OFF; bit=1 ON * output timer status bits 7...0 = timer channels 8...1 ; bit=0 DISABLED; bit=1 ENABLED * input status bit 0 = input channel; bit=0 OFF; bit=1 ON * 4.Now we are listening to the following commands from the client: * - status request: <5> * - switch an output channel ON: <6> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 switch channel ON * - switch an output channel OFF: <6> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 switch channel OFF * - toggle an output channel: <6> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 toggle channel * - pulse an output channel: <8> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 pulse channel * pulse time: 1...99 * units: 's'= seconds; 'm' = minutes; 'h' = hours * - update all output channels: <6> * channel bits 7...0 = channels 8...1 ; bit=0 switch channel OFF; bit=1 switch channel ON * - enable an output channel timer: <6> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 switch channel ON * - disable an output channel timer: <6> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 switch channel OFF * - toggle an output channel timer: <6> * channel bits 7...0 = channels 8...1 ; bit=0 no change ; bit=1 toggle channel * - connection closed: <5> * 5.Every time the status changes it will be send an update to the client * * ******************************************************************************/ #define MIN_GENERIC_TCP_PACKET_SIZE 5 #define MAX_GENERIC_TCP_PACKET_SIZE 22 #define STX 0x02 #define ETX 0x03 #define CMD_AUTH 'A' // connected with authentication needed #define LEN_CMD_AUTH 5 #define CMD_USERNAME 'U' // connected with authentication needed #define LEN_CMD_USERNAME 14 #define CMD_PASSWORD 'W' // connected with authentication needed #define LEN_CMD_PASSWORD 14 #define CMD_LOGGED_IN 'L' // successfully logged in #define LEN_CMD_LOGGED_IN 5 #define CMD_ACCESS_DENIED 'X' // access denied #define LEN_CMD_ACCESS_DENIED 5 #define CMD_CLOSED 'C' // connection closed #define LEN_CMD_CLOSED 5 #define CMD_NAME 'N' // channel name #define LEN_CMD_NAME 22 #define CMD_STATUS_REQ 'R' // status request #define LEN_CMD_STATUS_REQ 5 #define CMD_STATUS 'S' // output, timer & input channel status #define LEN_CMD_STATUS 8 #define CMD_ON 'O' // switch channel on #define LEN_CMD_ON 6 #define CMD_OFF 'F' // switch channel off #define LEN_CMD_OFF 6 #define CMD_TOGGLE 'T' // toggle channel #define LEN_CMD_TOGGLE 6 #define CMD_PULSE 'P' // pulse channel #define LEN_CMD_PULSE 8 #define CMD_UPDATE 'V' // update all channels #define LEN_CMD_UPDATE 6 #define CMD_TMR_ENA 'E' // enable timer channel programs #define LEN_CMD_TMR_ENA 6 #define CMD_TMR_DIS 'D' // disable timer channel programs #define LEN_CMD_TMR_DIS 6 #define CMD_TMR_TOGGLE 'G' // toggle timer channel programs #define LEN_CMD_TMR_TOGGLE 6