#ifndef __PORTAIL_H__ #define __PORTAIL_H__ #include #include "buffer.h" #define BIT0 0 #define BIT1 1 #define START_OF_DATA 2 #define START_OF_FRAME 3 #define END_OF_FRAME 4 #define ON 1 #define OFF 0 /** * Encode bits with Portail encoding (1 => 10, 0 => 01) * * @param frame 32-bit frame to encode * * @return new buffer * */ BYTE_BUFFER portailEncode(unsigned long int frame); /** * Decode bits with Portail encoding (1 => 10, 0 => 01) * * @param buffer the buffuer to decode * * @return new frame * */ unsigned long int portailDecode(BYTE_BUFFER *buffer); /** * Encode a byte according to Portail * * @param byte the byte to encode * * @return the encoded byte */ unsigned short int encodeByte(unsigned char byte); /** * Decode a byte according to Portail * * @param byte the byte to decode * * @return the decoded byte */ unsigned char decodeByte(unsigned short int word); /** * Create a complete command according to Chacon protocole * * @param id command id (refer to your remote) * @param section button section ('A' | 'B' | 'C' | 'D' | 'G') * @param nb button number(1, 2, 3, 4) * @param on boolean for on/off * * @return Portail frame */ unsigned long int createPortailCommand(unsigned long int id, char section, unsigned char nb, unsigned char on); /** * Send a complete command according to Chacon protocole * * @param id command id (refer to your remote) * @param section button section ('A' | 'B' | 'C' | 'D' | 'G') * @param nb button number(1, 2, 3, 4) * @param on boolean for on/off * @param repeat number of repeatition */ void sendPortailCommand(unsigned long int id, char section, unsigned char nb, unsigned char on, unsigned char repeat); /** * Send n times a data frame * * @param frame the data to send * @param repeat number of repeatition */ void sendFrame(BYTE_BUFFER frame, unsigned int repeat); /** * Configure the GPIO output pin * * @param pinNumber wiringPi pin number */ void setPortailTransmittorPin(unsigned char pinNumber); /** * Init input/output * * @return status */ int initIO(); /** * retrieve the Portail device ID from a frame * * @param buffer the buffer that hold the frame * * @return the device id */ unsigned long int getPortailId(unsigned long int frame); /** * Get all information about the portail frame * * @param frame the frame to read * @param id the identifier to extract * @param onOff boolean to extract; if true : on * @param section letter section to extract * @param number number to extract */ void getPortailInfo(unsigned long int frame, unsigned long int* id, unsigned char* onOff, unsigned char* section, unsigned char* number); /** * read the GPIO output pin * * @return wiringPi pin number */ unsigned char getPortailTransmittorPin(); /** * Configure the GPIO input pin * * @param pinNumber wiringPi pin number */ void setPortailReceptorPin(unsigned char pinNumber); /** * read the GPIO input pin * * @return wiringPi pin number */ unsigned char getPortailReceptorPin(); /** * Send a bit to the RF transmitter * * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME) */ void sendPortailBit(unsigned char bit); /** * Send a byte to the RF transmitter * * @param byte the byte to transmit */ void sendPortailByte(unsigned char byte); /** * Send the content of a buffer to the RF transmitter * * @param buffer the buffer to transmit */ void sendPortailBytes(BYTE_BUFFER buffer); /** * Calculate the length of the frame * * @param data data to scan (each byte represent a bit) * @param high length of high level * @param low length of low level * * @return total length of the frame */ unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* low); /** * Reading data from GPIO * * @param samples number of samples to read * @param duration waiting time between samples * * @return buffer */ BYTE_BUFFER readData(unsigned long int samples, unsigned int duration); #endif