discoverpixy
link.h
1 //
2 // begin license header
3 //
4 // This file is part of Pixy CMUcam5 or "Pixy" for short
5 //
6 // All Pixy source code is provided under the terms of the
7 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
8 // Those wishing to use Pixy source code, software and/or
9 // technologies under different licensing terms should contact us at
10 // cmucam@cs.cmu.edu. Such licensing terms are available for
11 // all portions of the Pixy codebase presented here.
12 //
13 // end license header
14 //
15 #ifndef LINK_H
16 #define LINK_H
17 
18 #include <stdint.h>
19 
20 // flags
21 #define LINK_FLAG_SHARED_MEM 0x01
22 #define LINK_FLAG_ERROR_CORRECTED 0x02
23 
24 // result codes
25 #define LINK_RESULT_OK 0
26 #define LINK_RESULT_ERROR -100
27 #define LINK_RESULT_ERROR_RECV_TIMEOUT -101
28 #define LINK_RESULT_ERROR_SEND_TIMEOUT -102
29 
30 // link flag index
31 #define LINK_FLAG_INDEX_FLAGS 0x00
32 #define LINK_FLAG_INDEX_SHARED_MEMORY_LOCATION 0x01
33 #define LINK_FLAG_INDEX_SHARED_MEMORY_SIZE 0x02
34 
35 
36 class Link
37 {
38 public:
39  Link()
40  {
41  m_flags = 0;
42  m_blockSize = 0;
43  }
44  ~Link()
45  {
46  }
47 
48  // the timeoutMs is a timeout value in milliseconds. The timeout timer should expire
49  // when the data channel has been continuously idle for the specified amount of time
50  // not the summation of the idle times.
51  virtual int send(const uint8_t *data, uint32_t len, uint16_t timeoutMs) = 0;
52  virtual int receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) = 0;
53  virtual void setTimer() = 0;
54  virtual uint32_t getTimer() = 0; // returns elapsed time in milliseconds since setTimer() was called
55  virtual uint32_t getFlags(uint8_t index=LINK_FLAG_INDEX_FLAGS)
56  {
57  if (index==LINK_FLAG_INDEX_FLAGS)
58  return m_flags;
59  else
60  return 0;
61  }
62  virtual uint32_t blockSize()
63  {
64  return m_blockSize;
65  }
66  virtual int getBuffer(uint8_t **, uint32_t *)
67  {
68  return LINK_RESULT_ERROR;
69  }
70 
71 protected:
72  uint32_t m_flags;
73  uint32_t m_blockSize;
74 };
75 
76 #endif // LINK_H