#ifndef __AMSSWCOMM_HPP__ #define __AMSSWCOMM_HPP__ #define AMSSWCOMM_BUFFSIZE 64 //the size of the message buffer class amsswcomm { public: uint8_t ms; uint8_t clkpin; uint8_t sendpin; uint8_t recvpin; //time int8_t divisor; int8_t clockticks; uint8_t lastclockstate; uint8_t clockstate; int16_t recvmessage_size; uint16_t recvmessage_byte; //extended bit that is being received int8_t recvstate; //0 - no starting bit has been received //1 - receive message start byte //2 - receiving message bytes //3 - message received - read and/or clear int16_t recvbytepointer; //0 - 10, pointer to bit being received uint8_t recvbitpointer; //pointer to byte being received int16_t sendmessage_size; uint16_t sendmessage_byte; //extended byte that is being sent int8_t sendstate; //0 - no message being sent //1 - message exists in queue, send start byte //2 - message exists in queue, send message bytes //3 - send end message byte //4 - clear message and reset int16_t sendbytepointer; //0 - 10, pointer to byte being sent uint8_t sendbitpointer; //pointer to byte being sent char sendmessage[AMSSWCOMM_BUFFSIZE]; char recvmessage[AMSSWCOMM_BUFFSIZE]; //initialize the sw communication channel // each swcomm channel has 3 pins, the clock pin (controlled by the master), // the input pin (receiving a signal from the other device) // and an output pin (sending a signal to the other device) //Inputs: // ms - master or slave // clkpin - the clock pin number // outpin - the output pin number // inpin - the input pin number void init(uint8_t _ms, uint8_t _clkpin, uint8_t _sendpin, uint8_t _recvpin, int _divisor); //called on each timestep to update the state of the communicator void update_step(); //called by update_step void update_send(); void update_recv(); //communicator has received a complete message //int is the size of the message, or -1 for no message received bool has_message(); //receives the message and resets the receive queue //return value is message size, or -1 for no message int recv_message(char *outputbuff, int outputbuffsize); //clears a received message and prepares to receive again void clearrecvqueue(); void clearsendqueue(); //places a message in the send queue //1 - success //0 - failure - a message is being sent, must wait to send bool send_message(char *inputbuff, int messagesize); }; #endif