I am no longer actively working on the ppCANOpen library, however, I want to publish this project so that anyone who wants to pick up any of the pieces can have a good example. This is a a project I was working on using the ppCANOpen library. It has a pretty in deep use of the object dictionary structure. And a number of functions to control high voltage pinball drivers, if you're into that sort of thing.
Dependencies: CANnucleo mbed ppCANOpen
Application/include/SerialBuffered.h@10:ec59d628ebdc, 2016-03-19 (annotated)
- Committer:
- ptpaterson
- Date:
- Sat Mar 19 01:44:35 2016 +0000
- Revision:
- 10:ec59d628ebdc
Final Submission (probs)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptpaterson | 10:ec59d628ebdc | 1 | #ifndef _SERIAL_BUFFERED_H_ |
ptpaterson | 10:ec59d628ebdc | 2 | #define _SERIAL_BUFFERED_H_ |
ptpaterson | 10:ec59d628ebdc | 3 | |
ptpaterson | 10:ec59d628ebdc | 4 | /** |
ptpaterson | 10:ec59d628ebdc | 5 | * Buffered serial class. |
ptpaterson | 10:ec59d628ebdc | 6 | */ |
ptpaterson | 10:ec59d628ebdc | 7 | class SerialBuffered : public Serial { |
ptpaterson | 10:ec59d628ebdc | 8 | public: |
ptpaterson | 10:ec59d628ebdc | 9 | /** |
ptpaterson | 10:ec59d628ebdc | 10 | * Create a buffered serial class. |
ptpaterson | 10:ec59d628ebdc | 11 | * |
ptpaterson | 10:ec59d628ebdc | 12 | * @param tx A pin for transmit. |
ptpaterson | 10:ec59d628ebdc | 13 | * @param rx A pin for receive. |
ptpaterson | 10:ec59d628ebdc | 14 | */ |
ptpaterson | 10:ec59d628ebdc | 15 | SerialBuffered(PinName tx, PinName rx); |
ptpaterson | 10:ec59d628ebdc | 16 | |
ptpaterson | 10:ec59d628ebdc | 17 | /** |
ptpaterson | 10:ec59d628ebdc | 18 | * Destroy. |
ptpaterson | 10:ec59d628ebdc | 19 | */ |
ptpaterson | 10:ec59d628ebdc | 20 | virtual ~SerialBuffered(); |
ptpaterson | 10:ec59d628ebdc | 21 | |
ptpaterson | 10:ec59d628ebdc | 22 | /** |
ptpaterson | 10:ec59d628ebdc | 23 | * Get a character. |
ptpaterson | 10:ec59d628ebdc | 24 | * |
ptpaterson | 10:ec59d628ebdc | 25 | * @return A character. (-1:timeout) |
ptpaterson | 10:ec59d628ebdc | 26 | */ |
ptpaterson | 10:ec59d628ebdc | 27 | int getc(); |
ptpaterson | 10:ec59d628ebdc | 28 | |
ptpaterson | 10:ec59d628ebdc | 29 | /** |
ptpaterson | 10:ec59d628ebdc | 30 | * Returns 1 if there is a character available to read, 0 otherwise. |
ptpaterson | 10:ec59d628ebdc | 31 | */ |
ptpaterson | 10:ec59d628ebdc | 32 | int readable(); |
ptpaterson | 10:ec59d628ebdc | 33 | |
ptpaterson | 10:ec59d628ebdc | 34 | /** |
ptpaterson | 10:ec59d628ebdc | 35 | * Set timeout for getc(). |
ptpaterson | 10:ec59d628ebdc | 36 | * |
ptpaterson | 10:ec59d628ebdc | 37 | * @param ms milliseconds. (-1:Disable timeout) |
ptpaterson | 10:ec59d628ebdc | 38 | */ |
ptpaterson | 10:ec59d628ebdc | 39 | void setTimeout(int ms); |
ptpaterson | 10:ec59d628ebdc | 40 | |
ptpaterson | 10:ec59d628ebdc | 41 | /** |
ptpaterson | 10:ec59d628ebdc | 42 | * Read requested bytes. |
ptpaterson | 10:ec59d628ebdc | 43 | * |
ptpaterson | 10:ec59d628ebdc | 44 | * @param bytes A pointer to a buffer. |
ptpaterson | 10:ec59d628ebdc | 45 | * @param requested Length. |
ptpaterson | 10:ec59d628ebdc | 46 | * |
ptpaterson | 10:ec59d628ebdc | 47 | * @return Readed byte length. |
ptpaterson | 10:ec59d628ebdc | 48 | */ |
ptpaterson | 10:ec59d628ebdc | 49 | size_t readBytes(uint8_t *bytes, size_t requested); |
ptpaterson | 10:ec59d628ebdc | 50 | |
ptpaterson | 10:ec59d628ebdc | 51 | private: |
ptpaterson | 10:ec59d628ebdc | 52 | void handleInterrupt(); |
ptpaterson | 10:ec59d628ebdc | 53 | static const int BUFFERSIZE = 2048; |
ptpaterson | 10:ec59d628ebdc | 54 | uint8_t buffer[BUFFERSIZE]; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end |
ptpaterson | 10:ec59d628ebdc | 55 | uint16_t indexContentStart; // index of first bytes of content |
ptpaterson | 10:ec59d628ebdc | 56 | uint16_t indexContentEnd; // index of bytes after last byte of content |
ptpaterson | 10:ec59d628ebdc | 57 | int timeout; |
ptpaterson | 10:ec59d628ebdc | 58 | Timer timer; |
ptpaterson | 10:ec59d628ebdc | 59 | }; |
ptpaterson | 10:ec59d628ebdc | 60 | |
ptpaterson | 10:ec59d628ebdc | 61 | #endif |