yocto_spiport.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yocto_spiport.h 28748 2017-10-03 08:23:39Z seb $
4  *
5  * Declares yFindSpiPort(), the high-level API for SpiPort functions
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 'AS IS' WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 
41 #ifndef YOCTO_SPIPORT_H
42 #define YOCTO_SPIPORT_H
43 
44 #include "yocto_api.h"
45 #include <cfloat>
46 #include <cmath>
47 #include <map>
48 
49 //--- (YSpiPort return codes)
50 //--- (end of YSpiPort return codes)
51 //--- (YSpiPort definitions)
52 class YSpiPort; // forward declaration
53 
54 typedef void (*YSpiPortValueCallback)(YSpiPort *func, const string& functionValue);
55 #ifndef _Y_VOLTAGELEVEL_ENUM
56 #define _Y_VOLTAGELEVEL_ENUM
57 typedef enum {
67 #endif
68 #ifndef _Y_SSPOLARITY_ENUM
69 #define _Y_SSPOLARITY_ENUM
70 typedef enum {
75 #endif
76 #ifndef _Y_SHITFTSAMPLING_ENUM
77 #define _Y_SHITFTSAMPLING_ENUM
78 typedef enum {
83 #endif
84 #define Y_RXCOUNT_INVALID (YAPI_INVALID_UINT)
85 #define Y_TXCOUNT_INVALID (YAPI_INVALID_UINT)
86 #define Y_ERRCOUNT_INVALID (YAPI_INVALID_UINT)
87 #define Y_RXMSGCOUNT_INVALID (YAPI_INVALID_UINT)
88 #define Y_TXMSGCOUNT_INVALID (YAPI_INVALID_UINT)
89 #define Y_LASTMSG_INVALID (YAPI_INVALID_STRING)
90 #define Y_CURRENTJOB_INVALID (YAPI_INVALID_STRING)
91 #define Y_STARTUPJOB_INVALID (YAPI_INVALID_STRING)
92 #define Y_COMMAND_INVALID (YAPI_INVALID_STRING)
93 #define Y_PROTOCOL_INVALID (YAPI_INVALID_STRING)
94 #define Y_SPIMODE_INVALID (YAPI_INVALID_STRING)
95 //--- (end of YSpiPort definitions)
96 
97 //--- (YSpiPort declaration)
108 #ifdef __BORLANDC__
109 #pragma option push -w-8022
110 #endif
111 //--- (end of YSpiPort declaration)
112 protected:
113  //--- (YSpiPort attributes)
114  // Attributes (function value cache)
115  int _rxCount;
116  int _txCount;
120  string _lastMsg;
121  string _currentJob;
122  string _startupJob;
123  string _command;
125  string _protocol;
126  string _spiMode;
130  int _rxptr;
131  string _rxbuff;
133 
134  friend YSpiPort *yFindSpiPort(const string& func);
135  friend YSpiPort *yFirstSpiPort(void);
136 
137  // Function-specific method for parsing of JSON output and caching result
138  virtual int _parseAttr(YJSONObject* json_val);
139 
140  // Constructor is protected, use yFindSpiPort factory function to instantiate
141  YSpiPort(const string& func);
142  //--- (end of YSpiPort attributes)
143 
144 public:
145  ~YSpiPort();
146  //--- (YSpiPort accessors declaration)
147 
148  static const int RXCOUNT_INVALID = YAPI_INVALID_UINT;
149  static const int TXCOUNT_INVALID = YAPI_INVALID_UINT;
150  static const int ERRCOUNT_INVALID = YAPI_INVALID_UINT;
151  static const int RXMSGCOUNT_INVALID = YAPI_INVALID_UINT;
152  static const int TXMSGCOUNT_INVALID = YAPI_INVALID_UINT;
153  static const string LASTMSG_INVALID;
154  static const string CURRENTJOB_INVALID;
155  static const string STARTUPJOB_INVALID;
156  static const string COMMAND_INVALID;
157  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_OFF = Y_VOLTAGELEVEL_OFF;
158  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL3V = Y_VOLTAGELEVEL_TTL3V;
159  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL3VR = Y_VOLTAGELEVEL_TTL3VR;
160  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL5V = Y_VOLTAGELEVEL_TTL5V;
161  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL5VR = Y_VOLTAGELEVEL_TTL5VR;
162  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_RS232 = Y_VOLTAGELEVEL_RS232;
163  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_RS485 = Y_VOLTAGELEVEL_RS485;
164  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_INVALID = Y_VOLTAGELEVEL_INVALID;
165  static const string PROTOCOL_INVALID;
166  static const string SPIMODE_INVALID;
167  static const Y_SSPOLARITY_enum SSPOLARITY_ACTIVE_LOW = Y_SSPOLARITY_ACTIVE_LOW;
168  static const Y_SSPOLARITY_enum SSPOLARITY_ACTIVE_HIGH = Y_SSPOLARITY_ACTIVE_HIGH;
169  static const Y_SSPOLARITY_enum SSPOLARITY_INVALID = Y_SSPOLARITY_INVALID;
170  static const Y_SHITFTSAMPLING_enum SHITFTSAMPLING_OFF = Y_SHITFTSAMPLING_OFF;
171  static const Y_SHITFTSAMPLING_enum SHITFTSAMPLING_ON = Y_SHITFTSAMPLING_ON;
172  static const Y_SHITFTSAMPLING_enum SHITFTSAMPLING_INVALID = Y_SHITFTSAMPLING_INVALID;
173 
181  int get_rxCount(void);
182 
183  inline int rxCount(void)
184  { return this->get_rxCount(); }
185 
193  int get_txCount(void);
194 
195  inline int txCount(void)
196  { return this->get_txCount(); }
197 
205  int get_errCount(void);
206 
207  inline int errCount(void)
208  { return this->get_errCount(); }
209 
217  int get_rxMsgCount(void);
218 
219  inline int rxMsgCount(void)
220  { return this->get_rxMsgCount(); }
221 
229  int get_txMsgCount(void);
230 
231  inline int txMsgCount(void)
232  { return this->get_txMsgCount(); }
233 
241  string get_lastMsg(void);
242 
243  inline string lastMsg(void)
244  { return this->get_lastMsg(); }
245 
253  string get_currentJob(void);
254 
255  inline string currentJob(void)
256  { return this->get_currentJob(); }
257 
269  int set_currentJob(const string& newval);
270  inline int setCurrentJob(const string& newval)
271  { return this->set_currentJob(newval); }
272 
280  string get_startupJob(void);
281 
282  inline string startupJob(void)
283  { return this->get_startupJob(); }
284 
296  int set_startupJob(const string& newval);
297  inline int setStartupJob(const string& newval)
298  { return this->set_startupJob(newval); }
299 
300  string get_command(void);
301 
302  inline string command(void)
303  { return this->get_command(); }
304 
305  int set_command(const string& newval);
306  inline int setCommand(const string& newval)
307  { return this->set_command(newval); }
308 
318  Y_VOLTAGELEVEL_enum get_voltageLevel(void);
319 
321  { return this->get_voltageLevel(); }
322 
338  int set_voltageLevel(Y_VOLTAGELEVEL_enum newval);
340  { return this->set_voltageLevel(newval); }
341 
353  string get_protocol(void);
354 
355  inline string protocol(void)
356  { return this->get_protocol(); }
357 
373  int set_protocol(const string& newval);
374  inline int setProtocol(const string& newval)
375  { return this->set_protocol(newval); }
376 
387  string get_spiMode(void);
388 
389  inline string spiMode(void)
390  { return this->get_spiMode(); }
391 
404  int set_spiMode(const string& newval);
405  inline int setSpiMode(const string& newval)
406  { return this->set_spiMode(newval); }
407 
415  Y_SSPOLARITY_enum get_ssPolarity(void);
416 
418  { return this->get_ssPolarity(); }
419 
429  int set_ssPolarity(Y_SSPOLARITY_enum newval);
430  inline int setSsPolarity(Y_SSPOLARITY_enum newval)
431  { return this->set_ssPolarity(newval); }
432 
441  Y_SHITFTSAMPLING_enum get_shitftSampling(void);
442 
444  { return this->get_shitftSampling(); }
445 
457  int set_shitftSampling(Y_SHITFTSAMPLING_enum newval);
459  { return this->set_shitftSampling(newval); }
460 
488  static YSpiPort* FindSpiPort(string func);
489 
501  virtual int registerValueCallback(YSpiPortValueCallback callback);
503 
504  virtual int _invokeValueCallback(string value);
505 
506  virtual int sendCommand(string text);
507 
515  virtual int reset(void);
516 
526  virtual int writeByte(int code);
527 
537  virtual int writeStr(string text);
538 
548  virtual int writeBin(string buff);
549 
559  virtual int writeArray(vector<int> byteList);
560 
570  virtual int writeHex(string hexString);
571 
581  virtual int writeLine(string text);
582 
592  virtual int readByte(void);
593 
605  virtual string readStr(int nChars);
606 
618  virtual string readBin(int nChars);
619 
631  virtual vector<int> readArray(int nChars);
632 
644  virtual string readHex(int nBytes);
645 
659  virtual string readLine(void);
660 
682  virtual vector<string> readMessages(string pattern,int maxWait);
683 
693  virtual int read_seek(int absPos);
694 
700  virtual int read_tell(void);
701 
708  virtual int read_avail(void);
709 
722  virtual string queryLine(string query,int maxWait);
723 
735  virtual int uploadJob(string jobfile,string jsonDef);
736 
748  virtual int selectJob(string jobfile);
749 
760  virtual int set_SS(int val);
761 
762 
763  inline static YSpiPort* Find(string func)
764  { return YSpiPort::FindSpiPort(func); }
765 
773  YSpiPort *nextSpiPort(void);
774  inline YSpiPort *next(void)
775  { return this->nextSpiPort();}
776 
786  static YSpiPort* FirstSpiPort(void);
787  inline static YSpiPort* First(void)
788  { return YSpiPort::FirstSpiPort();}
789 #ifdef __BORLANDC__
790 #pragma option pop
791 #endif
792  //--- (end of YSpiPort accessors declaration)
793 };
794 
795 //--- (YSpiPort functions declaration)
796 
824 inline YSpiPort* yFindSpiPort(const string& func)
825 { return YSpiPort::FindSpiPort(func);}
835 inline YSpiPort* yFirstSpiPort(void)
836 { return YSpiPort::FirstSpiPort();}
837 
838 //--- (end of YSpiPort functions declaration)
839 
840 #endif
Y_SHITFTSAMPLING_enum
Definition: yocto_spiport.h:78
Y_SHITFTSAMPLING_enum _shitftSampling
Y_VOLTAGELEVEL_enum
Definition: yocto_spiport.h:57
string _command
string _protocol
YSpiPortValueCallback _valueCallbackSpiPort
YSpiPort * yFirstSpiPort(void)
Y_VOLTAGELEVEL_enum voltageLevel(void)
Y_VOLTAGELEVEL_enum
string _currentJob
void(* YSpiPortValueCallback)(YSpiPort *func, const string &functionValue)
Definition: yocto_spiport.h:54
string protocol(void)
string _rxbuff
Y_SHITFTSAMPLING_enum shitftSampling(void)
int setCurrentJob(const string &newval)
int txCount(void)
static const string LASTMSG_INVALID
#define YAPI_INVALID_UINT
Definition: yocto_api.h:71
static const string CURRENTJOB_INVALID
string _spiMode
static const string SPIMODE_INVALID
int _rxMsgCount
string _startupJob
static YSpiPort * FindSpiPort(string func)
Y_SSPOLARITY_enum
Definition: yocto_spiport.h:70
YSpiPort * next(void)
static YSpiPort * First(void)
virtual int _parseAttr(YJSONObject *json_val)
Definition: yocto_api.cpp:2367
int _txMsgCount
int setStartupJob(const string &newval)
int rxCount(void)
int errCount(void)
string command(void)
Y_SSPOLARITY_enum _ssPolarity
static YSpiPort * Find(string func)
string spiMode(void)
int setProtocol(const string &newval)
int rxMsgCount(void)
int setVoltageLevel(Y_VOLTAGELEVEL_enum newval)
int _rxbuffptr
int setSsPolarity(Y_SSPOLARITY_enum newval)
static YSpiPort * FirstSpiPort(void)
string _lastMsg
virtual int registerValueCallback(YFunctionValueCallback callback)
Definition: yocto_api.cpp:2544
string lastMsg(void)
int setSpiMode(const string &newval)
#define YOCTO_CLASS_EXPORT
Definition: yocto_api.h:61
Y_VOLTAGELEVEL_enum _voltageLevel
string currentJob(void)
Y_SSPOLARITY_enum ssPolarity(void)
int setShitftSampling(Y_SHITFTSAMPLING_enum newval)
static const string PROTOCOL_INVALID
int txMsgCount(void)
static const string STARTUPJOB_INVALID
static const string COMMAND_INVALID
int setCommand(const string &newval)
string startupJob(void)
YSpiPort * yFindSpiPort(const string &func)
virtual int _invokeValueCallback(string value)
Definition: yocto_api.cpp:2563


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:11