Sakura IoT Platform b
Fork of SakuraIO by
SakuraIO.h@0:8d34375d954c, 2016-11-19 (annotated)
- Committer:
- spiralray
- Date:
- Sat Nov 19 03:20:17 2016 +0000
- Revision:
- 0:8d34375d954c
- Child:
- 1:20e1dfe45dab
First commit(This only works with SPI)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spiralray | 0:8d34375d954c | 1 | #ifndef _SAKURAIO_H_ |
spiralray | 0:8d34375d954c | 2 | #define _SAKURAIO_H_ |
spiralray | 0:8d34375d954c | 3 | |
spiralray | 0:8d34375d954c | 4 | #include <SakuraIO/commands.h> |
spiralray | 0:8d34375d954c | 5 | |
spiralray | 0:8d34375d954c | 6 | class SakuraIO |
spiralray | 0:8d34375d954c | 7 | { |
spiralray | 0:8d34375d954c | 8 | protected: |
spiralray | 0:8d34375d954c | 9 | virtual void begin(){} |
spiralray | 0:8d34375d954c | 10 | virtual void end(){} |
spiralray | 0:8d34375d954c | 11 | |
spiralray | 0:8d34375d954c | 12 | virtual void sendByte(uint8_t data){} |
spiralray | 0:8d34375d954c | 13 | //virtual void finishSending(){} |
spiralray | 0:8d34375d954c | 14 | |
spiralray | 0:8d34375d954c | 15 | virtual uint8_t startReceive(uint8_t length){return length;}; |
spiralray | 0:8d34375d954c | 16 | virtual uint8_t receiveByte(){return 0x00;} |
spiralray | 0:8d34375d954c | 17 | virtual uint8_t receiveByte(bool stop){return 0x00;} |
spiralray | 0:8d34375d954c | 18 | //virtual void finishReceiving(){} |
spiralray | 0:8d34375d954c | 19 | |
spiralray | 0:8d34375d954c | 20 | uint8_t executeCommand(uint8_t cmd,uint8_t requestLength, uint8_t *request, uint8_t *responseLength, uint8_t *response); |
spiralray | 0:8d34375d954c | 21 | |
spiralray | 0:8d34375d954c | 22 | uint8_t enqueueTxRaw(uint8_t ch, uint8_t type, uint8_t length, uint8_t *data, uint64_t offset); |
spiralray | 0:8d34375d954c | 23 | |
spiralray | 0:8d34375d954c | 24 | public: |
spiralray | 0:8d34375d954c | 25 | uint8_t getConnectionStatus(); |
spiralray | 0:8d34375d954c | 26 | uint8_t getSignalQuarity(); |
spiralray | 0:8d34375d954c | 27 | uint64_t getUnixtime(); |
spiralray | 0:8d34375d954c | 28 | uint8_t echoback(uint8_t length, uint8_t *data, uint8_t *response); |
spiralray | 0:8d34375d954c | 29 | uint16_t getADC(uint8_t channel); |
spiralray | 0:8d34375d954c | 30 | uint8_t enqueueTx(uint8_t ch, int32_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 31 | uint8_t enqueueTx(uint8_t ch, uint32_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 32 | uint8_t enqueueTx(uint8_t ch, int64_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 33 | uint8_t enqueueTx(uint8_t ch, uint64_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 34 | uint8_t enqueueTx(uint8_t ch, float value, uint64_t offset); |
spiralray | 0:8d34375d954c | 35 | uint8_t enqueueTx(uint8_t ch, double value, uint64_t offset); |
spiralray | 0:8d34375d954c | 36 | uint8_t enqueueTx(uint8_t ch, uint8_t value[8], uint64_t offset); |
spiralray | 0:8d34375d954c | 37 | uint8_t enqueueTx(uint8_t ch, int32_t value); |
spiralray | 0:8d34375d954c | 38 | uint8_t enqueueTx(uint8_t ch, uint32_t value); |
spiralray | 0:8d34375d954c | 39 | uint8_t enqueueTx(uint8_t ch, int64_t value); |
spiralray | 0:8d34375d954c | 40 | uint8_t enqueueTx(uint8_t ch, uint64_t value); |
spiralray | 0:8d34375d954c | 41 | uint8_t enqueueTx(uint8_t ch, float value); |
spiralray | 0:8d34375d954c | 42 | uint8_t enqueueTx(uint8_t ch, double value); |
spiralray | 0:8d34375d954c | 43 | uint8_t enqueueTx(uint8_t ch, uint8_t value[8]); |
spiralray | 0:8d34375d954c | 44 | uint8_t getTxQueueLength(uint8_t *available, uint8_t *queued); |
spiralray | 0:8d34375d954c | 45 | uint8_t clearTx(); |
spiralray | 0:8d34375d954c | 46 | uint8_t getTxStatus(uint8_t *queue, uint8_t *immediate); |
spiralray | 0:8d34375d954c | 47 | uint8_t send(); |
spiralray | 0:8d34375d954c | 48 | uint8_t dequeueRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset); |
spiralray | 0:8d34375d954c | 49 | uint8_t peekRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset); |
spiralray | 0:8d34375d954c | 50 | uint8_t getRxQueueLength(uint8_t *available, uint8_t *queued); |
spiralray | 0:8d34375d954c | 51 | uint8_t clearRx(); |
spiralray | 0:8d34375d954c | 52 | uint16_t getProductID(); |
spiralray | 0:8d34375d954c | 53 | uint8_t getUniqueID(char *data); |
spiralray | 0:8d34375d954c | 54 | uint8_t getFirmwareVersion(char *data); |
spiralray | 0:8d34375d954c | 55 | uint8_t unlock(); |
spiralray | 0:8d34375d954c | 56 | uint8_t updateFirmware(); |
spiralray | 0:8d34375d954c | 57 | uint8_t getFirmwareUpdateStatus(); |
spiralray | 0:8d34375d954c | 58 | uint8_t reset(); |
spiralray | 0:8d34375d954c | 59 | }; |
spiralray | 0:8d34375d954c | 60 | |
spiralray | 0:8d34375d954c | 61 | class SakuraIO_SPI : public SakuraIO |
spiralray | 0:8d34375d954c | 62 | { |
spiralray | 0:8d34375d954c | 63 | protected: |
spiralray | 0:8d34375d954c | 64 | SPI &spi; |
spiralray | 0:8d34375d954c | 65 | DigitalOut &cs; |
spiralray | 0:8d34375d954c | 66 | void begin(); |
spiralray | 0:8d34375d954c | 67 | void end(); |
spiralray | 0:8d34375d954c | 68 | void sendByte(uint8_t data); |
spiralray | 0:8d34375d954c | 69 | uint8_t receiveByte(bool stop); |
spiralray | 0:8d34375d954c | 70 | uint8_t receiveByte(); |
spiralray | 0:8d34375d954c | 71 | public: |
spiralray | 0:8d34375d954c | 72 | SakuraIO_SPI(SPI &_spi, DigitalOut &_cs); |
spiralray | 0:8d34375d954c | 73 | }; |
spiralray | 0:8d34375d954c | 74 | |
spiralray | 0:8d34375d954c | 75 | class SakuraIO_I2C : public SakuraIO |
spiralray | 0:8d34375d954c | 76 | { |
spiralray | 0:8d34375d954c | 77 | protected: |
spiralray | 0:8d34375d954c | 78 | I2C &i2c; |
spiralray | 0:8d34375d954c | 79 | void begin(); |
spiralray | 0:8d34375d954c | 80 | void end(); |
spiralray | 0:8d34375d954c | 81 | void sendByte(uint8_t data); |
spiralray | 0:8d34375d954c | 82 | uint8_t startReceive(uint8_t length); |
spiralray | 0:8d34375d954c | 83 | uint8_t receiveByte(bool stop); |
spiralray | 0:8d34375d954c | 84 | uint8_t receiveByte(); |
spiralray | 0:8d34375d954c | 85 | uint8_t mode; |
spiralray | 0:8d34375d954c | 86 | public: |
spiralray | 0:8d34375d954c | 87 | SakuraIO_I2C(I2C &_i2c); |
spiralray | 0:8d34375d954c | 88 | }; |
spiralray | 0:8d34375d954c | 89 | |
spiralray | 0:8d34375d954c | 90 | #endif // _SAKURAIO_H_ |