COSA
An Object-Oriented Platform for Arduino Programming
Ciao.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_CIAO_HH
22 #define COSA_CIAO_HH
23 
24 #include "Cosa/IOStream.hh"
25 
47 class Ciao {
48 public:
54  enum {
55  MASK_ATTR = 0x0f,
56  COUNT0_ATTR = 0x00,
57  COUNT4_MASK = 0x07,
58  COUNT8_ATTR = 0x08,
59  COUNT16_ATTR = 0x09,
61  } __attribute__((packed));
62 
67  enum {
68  MASK_TYPE = 0xf0,
69  UINT8_TYPE = 0x00,
70  UINT16_TYPE = 0x10,
71  UINT32_TYPE = 0x20,
72  UINT64_TYPE = 0x30,
77  USER8_TYPE = 0x60,
78  USER16_TYPE = 0x70,
79  INT8_TYPE = 0x80,
80  INT16_TYPE = 0x90,
81  INT32_TYPE = 0xa0,
82  INT64_TYPE = 0xb0,
83  FLOAT16_TYPE = 0xc0,
84  FLOAT32_TYPE = 0xd0,
85  FLOAT64_TYPE = 0xe0,
86  FLOAT80_TYPE = 0xf0
87  } __attribute__((packed));
88 
92  class Descriptor {
93  public:
98  enum {
99  HEADER_ID = 0x00,
100  COSA_FAI_ID = 0x10,
101  USER_ID = 0x0100
102  };
103  struct member_t {
104  uint8_t type;
105  uint16_t count;
106  const char* name;
107  const struct user_t* desc;
108  };
109  struct user_t {
110  uint16_t id;
111  const char* name;
112  const member_t* member;
113  uint8_t count;
114  };
115  static const user_t header_t PROGMEM;
116  };
117 
122  struct header_t {
123  char* magic;
124  uint8_t major;
125  uint8_t minor;
126  uint8_t endian;
127  };
128  enum {
131  } __attribute__((packed));
132 
133 public:
138  Ciao(IOStream::Device* dev = NULL) : m_dev(dev) {}
139 
144  void set(IOStream::Device* dev)
145  __attribute__((always_inline))
146  {
147  if (dev == NULL) return;
148  m_dev = dev;
149  }
150 
154  void begin();
155 
160  void write(char* s);
161 
166  void write(str_P s);
167 
172  void write(uint8_t value);
173 
179  void write(uint8_t* buf, uint16_t count);
180 
185  void write(uint16_t value);
186 
192  void write(uint16_t* buf, uint16_t count);
193 
198  void write(uint32_t value);
199 
205  void write(uint32_t* buf, uint16_t count);
206 
211  void write(uint64_t value);
212 
218  void write(uint64_t* buf, uint16_t count);
219 
224  void write(int8_t value);
225 
231  void write(int8_t* buf, uint16_t count);
232 
237  void write(int16_t value);
238 
244  void write(int16_t* buf, uint16_t count);
245 
250  void write(int32_t value);
251 
257  void write(int32_t* buf, uint16_t count);
258 
263  void write(int64_t value);
264 
270  void write(int64_t* buf, uint16_t count);
271 
276  void write(float value);
277 
283  void write(float* buf, uint16_t count);
284 
289  void write(const Descriptor::user_t* desc);
290 
297  void write(const Descriptor::user_t* desc, void* buf, uint16_t count);
298 
299 protected:
305  void write(uint8_t type, uint16_t count);
306 
308 };
309 
310 #endif
void begin()
Definition: Ciao.cpp:76
uint8_t major
Definition: Ciao.hh:124
void write(char *s)
Definition: Ciao.cpp:87
Definition: Ciao.hh:47
const char * name
Definition: Ciao.hh:111
#define NULL
Definition: Types.h:101
Ciao(IOStream::Device *dev=NULL)
Definition: Ciao.hh:138
const char * name
Definition: Ciao.hh:106
User descriptors (16-bit, 256-).
Definition: Ciao.hh:101
const struct user_t * desc
Definition: Ciao.hh:107
char * magic
Definition: Ciao.hh:123
Cosa Fai descriptors (8-bit, 16-).
Definition: Ciao.hh:100
const class prog_str * str_P
Definition: Types.h:187
uint8_t minor
Definition: Ciao.hh:125
IOStream::Device * m_dev
Definition: Ciao.hh:307
uint8_t endian
Definition: Ciao.hh:126
const member_t * member
Definition: Ciao.hh:112
Ciao header descriptor (8-bit, 1-15).
Definition: Ciao.hh:99