00001
00002
00003
00004
00005
00006
00007
00008 #define NULL 0
00009
00010 #ifndef SHETSource_h
00011 #define SHETSource_h
00012
00013
00014 #define MAX_ADDRESS 10
00015
00016
00017
00018 #define MAX_STRING_SIZE 16
00019
00020
00021 #define DEFAULT_STATUS_PIN 13
00022
00023 #define STATUS_BLINK_DURATION 100
00024
00025
00026
00027 #define CLIENT_WAIT_TIME 10
00028
00029
00030
00031
00032 #define NUM_INPUTS 8
00033 #define NUM_OUTPUTS 8
00034
00035 class SHETSourceRemoteClient;
00036 class SHETSourceServer;
00037 class SHETSourceClient;
00038 struct Response;
00039
00040
00041 typedef byte int8;
00042 typedef int int16;
00043
00044
00045 typedef byte notify_flags_t;
00046 #define CLEAR 0
00047
00051 enum client_status_t {
00052 STATUS_OK,
00053 STATUS_NOT_CONNECTED,
00054 STATUS_ERROR
00056 };
00057
00061 enum output_type_t {
00062 OUTTYPE_NONE,
00063 OUTTYPE_bool,
00064 OUTTYPE_int8,
00065 OUTTYPE_int16
00066 };
00067
00071 enum client_command {
00072 CMD_GET_STATUS,
00075 CMD_GET_OUTPUT_TYPES,
00078 CMD_READ
00081 };
00082
00087 struct Response {
00088 public:
00093 byte *data;
00094
00098 int length;
00099 };
00100
00107 class SHETSourceRemoteClient
00108 {
00109 private:
00110 const SHETSourceServer *_server;
00111 int _address;
00112 bool _connected;
00113
00114 notify_flags_t _output_notify;
00115 output_type_t _output_types[NUM_OUTPUTS];
00116
00117 bool getStatus(void);
00118
00119 public:
00128 SHETSourceRemoteClient(const SHETSourceServer *server, int address);
00129
00135 void updateStatus(void);
00136
00141 void updateOutputTypes(void);
00142
00147 bool isConnected(void);
00148
00154 bool isOutputNotifying(void);
00155
00156
00161 notify_flags_t getOutputNotify(void);
00162
00169 bool getOutputNotify(int port);
00170
00182 bool readBool(int port);
00183
00195 int8 readInt8(int port);
00196
00208 int16 readInt16(int port);
00209
00214 void beginTransmission(void);
00215
00221 void endTransmission(void);
00222
00229 void request(int length);
00230
00231 };
00232
00237 class SHETSourceServer
00238 {
00239 private:
00240 SHETSourceRemoteClient *_remote_clients[MAX_ADDRESS];
00241
00242 public:
00247 SHETSourceServer(void);
00248
00259 SHETSourceRemoteClient *getClient(int address);
00260
00268 void pollClients(void);
00269 };
00270
00277 class SHETSourceClient
00278 {
00279 private:
00280 const char *_name;
00281 int _address;
00282 bool _connected;
00283 bool _error;
00284
00285 int _status_pin;
00286 const void statusWrite(int value);
00287
00288 struct Response _response;
00289
00290 void onCmdStatus(byte challenge);
00291 void onCmdOutputTypes(void);
00292 void onCmdRead(int port);
00293 notify_flags_t _output_notify;
00294
00295 output_type_t _output_types[NUM_OUTPUTS];
00296 char *_output_names[NUM_OUTPUTS];
00297 bool (*_output_function_bool[NUM_OUTPUTS])();
00298 int8 (*_output_function_int8[NUM_OUTPUTS])();
00299 int16 (*_output_function_int16[NUM_OUTPUTS])();
00300
00301 public:
00313 SHETSourceClient(const char *name,
00314 int address,
00315 int status_pin = DEFAULT_STATUS_PIN);
00316
00324 const client_status_t getStatus();
00325
00339 const void displayStatus();
00340
00346 void outputNotify(int port);
00347
00358 void bindOutputPort(int port, char *name, bool (*func)());
00359
00370 void bindOutputPort(int port, char *name, int8 (*func)());
00371
00382 void bindOutputPort(int port, char *name, int16 (*func)());
00383
00389 void onReceive(int length);
00390
00396 void onRequest(void);
00397 };
00398
00399
00400 static SHETSourceClient *_current_client = NULL;
00401
00402
00403
00404 void onReceiveWrapper(int length);
00405 void onRequestWrapper(void);
00406
00407 #endif // SHETSource_h