Sakura IoT Platform b

Fork of SakuraIO by SAKURA Internet

Committer:
chibiegg
Date:
Sat Nov 19 15:19:49 2016 +0000
Revision:
3:c54a1eba22c4
Parent:
2:6f8e51a42a7d
add license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chibiegg 3:c54a1eba22c4 1 /* SAKURA Internet IoT Communication Module Library for mbed
chibiegg 3:c54a1eba22c4 2 *
chibiegg 3:c54a1eba22c4 3 * The MIT License (MIT)
chibiegg 3:c54a1eba22c4 4 *
chibiegg 3:c54a1eba22c4 5 * Copyright (c) SAKURA Internet Inc.
chibiegg 3:c54a1eba22c4 6 *
chibiegg 3:c54a1eba22c4 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
chibiegg 3:c54a1eba22c4 8 * of this software and associated documentation files (the "Software"),
chibiegg 3:c54a1eba22c4 9 * to deal in the Software without restriction, including without limitation
chibiegg 3:c54a1eba22c4 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
chibiegg 3:c54a1eba22c4 11 * and/or sell copies of the Software, and to permit persons to whom the Software
chibiegg 3:c54a1eba22c4 12 * is furnished to do so, subject to the following conditions:
chibiegg 3:c54a1eba22c4 13 *
chibiegg 3:c54a1eba22c4 14 * The above copyright notice and this permission notice shall be included
chibiegg 3:c54a1eba22c4 15 * in all copies or substantial portions of the Software.
chibiegg 3:c54a1eba22c4 16 *
chibiegg 3:c54a1eba22c4 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
chibiegg 3:c54a1eba22c4 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
chibiegg 3:c54a1eba22c4 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
chibiegg 3:c54a1eba22c4 20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
chibiegg 3:c54a1eba22c4 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
chibiegg 3:c54a1eba22c4 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
chibiegg 3:c54a1eba22c4 23 */
chibiegg 3:c54a1eba22c4 24
spiralray 0:8d34375d954c 25 #ifndef _SAKURAIO_H_
spiralray 0:8d34375d954c 26 #define _SAKURAIO_H_
spiralray 0:8d34375d954c 27
spiralray 1:20e1dfe45dab 28 #include "mbed.h"
spiralray 0:8d34375d954c 29 #include <SakuraIO/commands.h>
spiralray 0:8d34375d954c 30
spiralray 0:8d34375d954c 31 class SakuraIO
spiralray 0:8d34375d954c 32 {
spiralray 0:8d34375d954c 33 protected:
spiralray 0:8d34375d954c 34 virtual void begin(){}
spiralray 0:8d34375d954c 35 virtual void end(){}
spiralray 0:8d34375d954c 36
spiralray 0:8d34375d954c 37 virtual void sendByte(uint8_t data){}
spiralray 0:8d34375d954c 38 //virtual void finishSending(){}
spiralray 0:8d34375d954c 39
spiralray 0:8d34375d954c 40 virtual uint8_t startReceive(uint8_t length){return length;};
spiralray 0:8d34375d954c 41 virtual uint8_t receiveByte(){return 0x00;}
spiralray 0:8d34375d954c 42 virtual uint8_t receiveByte(bool stop){return 0x00;}
spiralray 0:8d34375d954c 43 //virtual void finishReceiving(){}
spiralray 0:8d34375d954c 44
spiralray 0:8d34375d954c 45 uint8_t executeCommand(uint8_t cmd,uint8_t requestLength, uint8_t *request, uint8_t *responseLength, uint8_t *response);
spiralray 0:8d34375d954c 46
spiralray 0:8d34375d954c 47 uint8_t enqueueTxRaw(uint8_t ch, uint8_t type, uint8_t length, uint8_t *data, uint64_t offset);
spiralray 0:8d34375d954c 48
spiralray 0:8d34375d954c 49 public:
spiralray 0:8d34375d954c 50 uint8_t getConnectionStatus();
spiralray 0:8d34375d954c 51 uint8_t getSignalQuarity();
spiralray 0:8d34375d954c 52 uint64_t getUnixtime();
spiralray 0:8d34375d954c 53 uint8_t echoback(uint8_t length, uint8_t *data, uint8_t *response);
spiralray 0:8d34375d954c 54 uint16_t getADC(uint8_t channel);
spiralray 0:8d34375d954c 55 uint8_t enqueueTx(uint8_t ch, int32_t value, uint64_t offset);
spiralray 0:8d34375d954c 56 uint8_t enqueueTx(uint8_t ch, uint32_t value, uint64_t offset);
spiralray 0:8d34375d954c 57 uint8_t enqueueTx(uint8_t ch, int64_t value, uint64_t offset);
spiralray 0:8d34375d954c 58 uint8_t enqueueTx(uint8_t ch, uint64_t value, uint64_t offset);
spiralray 0:8d34375d954c 59 uint8_t enqueueTx(uint8_t ch, float value, uint64_t offset);
spiralray 0:8d34375d954c 60 uint8_t enqueueTx(uint8_t ch, double value, uint64_t offset);
spiralray 0:8d34375d954c 61 uint8_t enqueueTx(uint8_t ch, uint8_t value[8], uint64_t offset);
spiralray 0:8d34375d954c 62 uint8_t enqueueTx(uint8_t ch, int32_t value);
spiralray 0:8d34375d954c 63 uint8_t enqueueTx(uint8_t ch, uint32_t value);
spiralray 0:8d34375d954c 64 uint8_t enqueueTx(uint8_t ch, int64_t value);
spiralray 0:8d34375d954c 65 uint8_t enqueueTx(uint8_t ch, uint64_t value);
spiralray 0:8d34375d954c 66 uint8_t enqueueTx(uint8_t ch, float value);
spiralray 0:8d34375d954c 67 uint8_t enqueueTx(uint8_t ch, double value);
spiralray 0:8d34375d954c 68 uint8_t enqueueTx(uint8_t ch, uint8_t value[8]);
spiralray 0:8d34375d954c 69 uint8_t getTxQueueLength(uint8_t *available, uint8_t *queued);
spiralray 0:8d34375d954c 70 uint8_t clearTx();
spiralray 0:8d34375d954c 71 uint8_t getTxStatus(uint8_t *queue, uint8_t *immediate);
spiralray 0:8d34375d954c 72 uint8_t send();
spiralray 0:8d34375d954c 73 uint8_t dequeueRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset);
spiralray 0:8d34375d954c 74 uint8_t peekRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset);
spiralray 0:8d34375d954c 75 uint8_t getRxQueueLength(uint8_t *available, uint8_t *queued);
spiralray 0:8d34375d954c 76 uint8_t clearRx();
spiralray 0:8d34375d954c 77 uint16_t getProductID();
spiralray 0:8d34375d954c 78 uint8_t getUniqueID(char *data);
spiralray 0:8d34375d954c 79 uint8_t getFirmwareVersion(char *data);
spiralray 0:8d34375d954c 80 uint8_t unlock();
spiralray 0:8d34375d954c 81 uint8_t updateFirmware();
spiralray 0:8d34375d954c 82 uint8_t getFirmwareUpdateStatus();
spiralray 0:8d34375d954c 83 uint8_t reset();
spiralray 0:8d34375d954c 84 };
spiralray 0:8d34375d954c 85
spiralray 0:8d34375d954c 86 class SakuraIO_SPI : public SakuraIO
spiralray 0:8d34375d954c 87 {
spiralray 0:8d34375d954c 88 protected:
spiralray 0:8d34375d954c 89 SPI &spi;
spiralray 0:8d34375d954c 90 DigitalOut &cs;
spiralray 2:6f8e51a42a7d 91 virtual void begin();
spiralray 2:6f8e51a42a7d 92 virtual void end();
spiralray 2:6f8e51a42a7d 93 virtual void sendByte(uint8_t data);
spiralray 2:6f8e51a42a7d 94 virtual uint8_t receiveByte(bool stop);
spiralray 2:6f8e51a42a7d 95 virtual uint8_t receiveByte();
spiralray 0:8d34375d954c 96 public:
spiralray 0:8d34375d954c 97 SakuraIO_SPI(SPI &_spi, DigitalOut &_cs);
spiralray 0:8d34375d954c 98 };
spiralray 0:8d34375d954c 99
spiralray 0:8d34375d954c 100 class SakuraIO_I2C : public SakuraIO
spiralray 0:8d34375d954c 101 {
spiralray 0:8d34375d954c 102 protected:
spiralray 1:20e1dfe45dab 103 I2C i2c;
spiralray 1:20e1dfe45dab 104 int _length;
spiralray 1:20e1dfe45dab 105
spiralray 1:20e1dfe45dab 106 virtual void begin();
spiralray 1:20e1dfe45dab 107 virtual void end();
spiralray 1:20e1dfe45dab 108 virtual void sendByte(uint8_t data);
spiralray 1:20e1dfe45dab 109 virtual uint8_t startReceive(uint8_t length);
spiralray 1:20e1dfe45dab 110 virtual uint8_t receiveByte(bool stop);
spiralray 1:20e1dfe45dab 111 virtual uint8_t receiveByte();
spiralray 0:8d34375d954c 112 uint8_t mode;
spiralray 0:8d34375d954c 113 public:
spiralray 1:20e1dfe45dab 114 SakuraIO_I2C (I2C &_i2c);
spiralray 1:20e1dfe45dab 115 SakuraIO_I2C (PinName sda, PinName scl);
spiralray 0:8d34375d954c 116 };
spiralray 0:8d34375d954c 117
spiralray 0:8d34375d954c 118 #endif // _SAKURAIO_H_