SAKURA Internet IoT Communication Module Library for mbed
Dependents: patlite_sakuraio sakuraio_lte_firmwareupdater shownet2017-iinebutton patlite_sakuraio_stack ... more
SAKURA Internet IoT Communication Module Library for mbed
Sakura Communication Module (with sakura.io) library for mbed.
Support
This library supports following products.
- SCM-LTE-01 (sakura.io Module (LTE) )
- SCM-LTE-Beta (Sakura Communication Module (LTE) β)
Reference
Please see the datasheet.
License
The MIT License (MIT)
Copyright (c) SAKURA Internet Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SakuraIO.cpp@11:16e726ca39c6, 2017-09-28 (annotated)
- Committer:
- chibiegg
- Date:
- Thu Sep 28 16:58:17 2017 +0900
- Revision:
- 11:16e726ca39c6
- Parent:
- 6:34a0233cdf04
- Child:
- 13:a9dbb86be232
Follow SakuraIOArduino v1.1.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chibiegg | 3:c54a1eba22c4 | 1 | /* SAKURA Internet IoT Communication Module Library for mbed |
chibiegg | 6:34a0233cdf04 | 2 | * |
chibiegg | 3:c54a1eba22c4 | 3 | * The MIT License (MIT) |
chibiegg | 6:34a0233cdf04 | 4 | * |
chibiegg | 3:c54a1eba22c4 | 5 | * Copyright (c) SAKURA Internet Inc. |
chibiegg | 6:34a0233cdf04 | 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 | 6:34a0233cdf04 | 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 | 6:34a0233cdf04 | 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 | #include "mbed.h" |
spiralray | 0:8d34375d954c | 26 | #include "SakuraIO.h" |
spiralray | 0:8d34375d954c | 27 | #include "SakuraIO/commands.h" |
spiralray | 0:8d34375d954c | 28 | #include "SakuraIO/debug.h" |
spiralray | 0:8d34375d954c | 29 | |
chibiegg |
11:16e726ca39c6 | 30 | #define delay(ms) wait_ms(ms) |
chibiegg |
11:16e726ca39c6 | 31 | |
spiralray | 0:8d34375d954c | 32 | uint8_t SakuraIO::executeCommand(uint8_t cmd,uint8_t requestLength, uint8_t *request, uint8_t *responseLength, uint8_t *response) |
spiralray | 0:8d34375d954c | 33 | { |
spiralray | 0:8d34375d954c | 34 | uint8_t parity = 0x00; |
spiralray | 0:8d34375d954c | 35 | uint8_t result = 0x00; |
chibiegg |
11:16e726ca39c6 | 36 | uint8_t reservedResponseLength, tmpResponse, receivedResponseLength; |
spiralray | 0:8d34375d954c | 37 | |
spiralray | 0:8d34375d954c | 38 | dbgln("executeCommand"); |
spiralray | 0:8d34375d954c | 39 | |
spiralray | 0:8d34375d954c | 40 | this->begin(); |
spiralray | 0:8d34375d954c | 41 | |
spiralray | 0:8d34375d954c | 42 | // request |
spiralray | 0:8d34375d954c | 43 | this->sendByte(cmd); |
spiralray | 0:8d34375d954c | 44 | this->sendByte(requestLength); |
spiralray | 0:8d34375d954c | 45 | parity = cmd ^ requestLength; |
spiralray | 0:8d34375d954c | 46 | for(int16_t i=0; i<requestLength; i++){ |
spiralray | 0:8d34375d954c | 47 | parity ^= request[i]; |
spiralray | 0:8d34375d954c | 48 | this->sendByte(request[i]); |
spiralray | 0:8d34375d954c | 49 | } |
spiralray | 0:8d34375d954c | 50 | this->sendByte(parity); |
spiralray | 0:8d34375d954c | 51 | //this->finishSending(); |
spiralray | 0:8d34375d954c | 52 | |
chibiegg |
11:16e726ca39c6 | 53 | reservedResponseLength = 0; |
spiralray | 0:8d34375d954c | 54 | if(responseLength != NULL){ |
chibiegg |
11:16e726ca39c6 | 55 | reservedResponseLength = *responseLength; |
spiralray | 0:8d34375d954c | 56 | } |
spiralray | 0:8d34375d954c | 57 | |
chibiegg |
11:16e726ca39c6 | 58 | delay(10); |
spiralray | 0:8d34375d954c | 59 | |
spiralray | 0:8d34375d954c | 60 | // response |
chibiegg |
11:16e726ca39c6 | 61 | this->startReceive(reservedResponseLength+3); |
spiralray | 0:8d34375d954c | 62 | result = this->receiveByte(); |
spiralray | 0:8d34375d954c | 63 | if(result != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 64 | dbgln("Invalid status"); |
spiralray | 0:8d34375d954c | 65 | this->end(); |
spiralray | 0:8d34375d954c | 66 | return result; |
spiralray | 0:8d34375d954c | 67 | } |
chibiegg |
11:16e726ca39c6 | 68 | receivedResponseLength = this->receiveByte(); |
spiralray | 0:8d34375d954c | 69 | if(responseLength != NULL){ |
chibiegg |
11:16e726ca39c6 | 70 | *responseLength = receivedResponseLength; |
spiralray | 0:8d34375d954c | 71 | } |
chibiegg |
11:16e726ca39c6 | 72 | |
chibiegg |
11:16e726ca39c6 | 73 | parity = result ^ receivedResponseLength; |
chibiegg |
11:16e726ca39c6 | 74 | for(int16_t i=0; i<receivedResponseLength; i++){ |
spiralray | 0:8d34375d954c | 75 | tmpResponse = this->receiveByte(); |
spiralray | 0:8d34375d954c | 76 | parity ^= tmpResponse; |
chibiegg |
11:16e726ca39c6 | 77 | if(response != NULL && i<reservedResponseLength){ |
spiralray | 0:8d34375d954c | 78 | response[i] = tmpResponse; |
spiralray | 0:8d34375d954c | 79 | } |
spiralray | 0:8d34375d954c | 80 | } |
spiralray | 0:8d34375d954c | 81 | dbgln("Parity"); |
spiralray | 0:8d34375d954c | 82 | uint8_t p = this->receiveByte(true); |
spiralray | 0:8d34375d954c | 83 | parity ^= p; |
spiralray | 0:8d34375d954c | 84 | dbg("Parity="); |
spiralray | 0:8d34375d954c | 85 | dbgln(p); |
spiralray | 0:8d34375d954c | 86 | if(parity != 0x00){ |
spiralray | 0:8d34375d954c | 87 | result = CMD_ERROR_PARITY; |
spiralray | 0:8d34375d954c | 88 | dbgln("Invalid parity"); |
spiralray | 0:8d34375d954c | 89 | }else{ |
spiralray | 0:8d34375d954c | 90 | dbgln("Success"); |
spiralray | 0:8d34375d954c | 91 | } |
spiralray | 0:8d34375d954c | 92 | //this->finishReceiving(); |
spiralray | 0:8d34375d954c | 93 | |
spiralray | 0:8d34375d954c | 94 | this->end(); |
spiralray | 0:8d34375d954c | 95 | return result; |
spiralray | 0:8d34375d954c | 96 | } |
spiralray | 0:8d34375d954c | 97 | |
spiralray | 0:8d34375d954c | 98 | /* Common Commands */ |
spiralray | 0:8d34375d954c | 99 | |
spiralray | 0:8d34375d954c | 100 | uint8_t SakuraIO::getConnectionStatus(){ |
spiralray | 0:8d34375d954c | 101 | uint8_t responseLength = 1; |
spiralray | 0:8d34375d954c | 102 | uint8_t response[1] = {0x00}; |
spiralray | 0:8d34375d954c | 103 | if(executeCommand(CMD_GET_CONNECTION_STATUS, 0, NULL, &responseLength, response) != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 104 | return 0x7F; |
spiralray | 0:8d34375d954c | 105 | } |
spiralray | 0:8d34375d954c | 106 | return response[0]; |
spiralray | 0:8d34375d954c | 107 | } |
spiralray | 0:8d34375d954c | 108 | |
chibiegg | 6:34a0233cdf04 | 109 | uint8_t SakuraIO::getSignalQuality(){ |
spiralray | 0:8d34375d954c | 110 | uint8_t responseLength = 1; |
spiralray | 0:8d34375d954c | 111 | uint8_t response[1] = {0x00}; |
spiralray | 0:8d34375d954c | 112 | |
spiralray | 0:8d34375d954c | 113 | if(executeCommand(CMD_GET_SIGNAL_QUALITY, 0, NULL, &responseLength, response) != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 114 | return 0x00; |
spiralray | 0:8d34375d954c | 115 | } |
spiralray | 0:8d34375d954c | 116 | return response[0]; |
spiralray | 0:8d34375d954c | 117 | } |
spiralray | 0:8d34375d954c | 118 | |
chibiegg | 6:34a0233cdf04 | 119 | uint8_t SakuraIO::getSignalQuarity(){ |
chibiegg | 6:34a0233cdf04 | 120 | // deprecated |
chibiegg | 6:34a0233cdf04 | 121 | return getSignalQuality(); |
chibiegg | 6:34a0233cdf04 | 122 | } |
chibiegg | 6:34a0233cdf04 | 123 | |
spiralray | 0:8d34375d954c | 124 | uint64_t SakuraIO::getUnixtime(){ |
spiralray | 0:8d34375d954c | 125 | uint8_t responseLength = 8; |
spiralray | 0:8d34375d954c | 126 | uint8_t response[8] = {0x00}; |
spiralray | 0:8d34375d954c | 127 | if(executeCommand(CMD_GET_DATETIME, 0, NULL, &responseLength, response) != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 128 | return 0x00; |
spiralray | 0:8d34375d954c | 129 | } |
spiralray | 0:8d34375d954c | 130 | return *((uint64_t *)response); |
spiralray | 0:8d34375d954c | 131 | } |
spiralray | 0:8d34375d954c | 132 | |
spiralray | 0:8d34375d954c | 133 | uint8_t SakuraIO::echoback(uint8_t length, uint8_t *data, uint8_t *response){ |
spiralray | 0:8d34375d954c | 134 | uint8_t responseLength = length; |
spiralray | 0:8d34375d954c | 135 | if(executeCommand(CMD_ECHO_BACK, length, data, &responseLength, response) != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 136 | return 0x00; |
spiralray | 0:8d34375d954c | 137 | } |
spiralray | 0:8d34375d954c | 138 | return responseLength; |
spiralray | 0:8d34375d954c | 139 | } |
spiralray | 0:8d34375d954c | 140 | |
spiralray | 0:8d34375d954c | 141 | /* IO Commands */ |
spiralray | 0:8d34375d954c | 142 | |
spiralray | 0:8d34375d954c | 143 | uint16_t SakuraIO::getADC(uint8_t channel){ |
spiralray | 0:8d34375d954c | 144 | uint8_t request[1] = {channel}; |
spiralray | 0:8d34375d954c | 145 | uint8_t response[2] = {0x00}; |
spiralray | 0:8d34375d954c | 146 | uint8_t responseLength = sizeof(response); |
spiralray | 0:8d34375d954c | 147 | if(executeCommand(CMD_READ_ADC, 1, request, &responseLength, response) != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 148 | return 0xffff; |
spiralray | 0:8d34375d954c | 149 | } |
spiralray | 0:8d34375d954c | 150 | return *((uint16_t *)response); |
spiralray | 0:8d34375d954c | 151 | } |
spiralray | 0:8d34375d954c | 152 | |
spiralray | 0:8d34375d954c | 153 | /* TX Commands */ |
spiralray | 0:8d34375d954c | 154 | uint8_t SakuraIO::enqueueTxRaw(uint8_t ch, uint8_t type, uint8_t length, uint8_t *data, uint64_t offset){ |
spiralray | 0:8d34375d954c | 155 | uint8_t request[18] = {0x00}; |
spiralray | 0:8d34375d954c | 156 | uint8_t requestLength = 10; |
spiralray | 0:8d34375d954c | 157 | request[0] = ch; |
spiralray | 0:8d34375d954c | 158 | request[1] = type; |
spiralray | 0:8d34375d954c | 159 | for(uint8_t i=0;i<length;i++){ |
spiralray | 0:8d34375d954c | 160 | request[2+i] = data[i]; |
spiralray | 0:8d34375d954c | 161 | } |
spiralray | 0:8d34375d954c | 162 | if(offset != 0){ |
spiralray | 0:8d34375d954c | 163 | requestLength = 18; |
spiralray | 0:8d34375d954c | 164 | for(uint8_t i=0;i<8;i++){ |
spiralray | 0:8d34375d954c | 165 | request[10+i] = ((uint8_t *)&offset)[i]; |
spiralray | 0:8d34375d954c | 166 | } |
spiralray | 0:8d34375d954c | 167 | } |
spiralray | 0:8d34375d954c | 168 | return executeCommand(CMD_TX_ENQUEUE, requestLength, request, NULL, NULL); |
spiralray | 0:8d34375d954c | 169 | } |
spiralray | 0:8d34375d954c | 170 | |
spiralray | 0:8d34375d954c | 171 | uint8_t SakuraIO::enqueueTx(uint8_t ch, int32_t value, uint64_t offset){ |
spiralray | 0:8d34375d954c | 172 | return enqueueTxRaw(ch, 'i', 4, (uint8_t *)&value, offset); |
spiralray | 0:8d34375d954c | 173 | } |
spiralray | 0:8d34375d954c | 174 | |
spiralray | 0:8d34375d954c | 175 | uint8_t SakuraIO::enqueueTx(uint8_t ch, uint32_t value, uint64_t offset){ |
spiralray | 0:8d34375d954c | 176 | return enqueueTxRaw(ch, 'I', 4, (uint8_t *)&value, offset); |
spiralray | 0:8d34375d954c | 177 | } |
spiralray | 0:8d34375d954c | 178 | |
spiralray | 0:8d34375d954c | 179 | uint8_t SakuraIO::enqueueTx(uint8_t ch, int64_t value, uint64_t offset){ |
spiralray | 0:8d34375d954c | 180 | return enqueueTxRaw(ch, 'l', 8, (uint8_t *)&value, offset); |
spiralray | 0:8d34375d954c | 181 | } |
spiralray | 0:8d34375d954c | 182 | |
spiralray | 0:8d34375d954c | 183 | uint8_t SakuraIO::enqueueTx(uint8_t ch, uint64_t value, uint64_t offset){ |
spiralray | 0:8d34375d954c | 184 | return enqueueTxRaw(ch, 'L', 8, (uint8_t *)&value, offset); |
spiralray | 0:8d34375d954c | 185 | } |
spiralray | 0:8d34375d954c | 186 | |
spiralray | 0:8d34375d954c | 187 | uint8_t SakuraIO::enqueueTx(uint8_t ch, float value, uint64_t offset){ |
spiralray | 0:8d34375d954c | 188 | return enqueueTxRaw(ch, 'f', 4, (uint8_t *)&value, offset); |
spiralray | 0:8d34375d954c | 189 | } |
spiralray | 0:8d34375d954c | 190 | |
spiralray | 0:8d34375d954c | 191 | uint8_t SakuraIO::enqueueTx(uint8_t ch, double value, uint64_t offset){ |
spiralray | 0:8d34375d954c | 192 | return enqueueTxRaw(ch, 'd', 8, (uint8_t *)&value, offset); |
spiralray | 0:8d34375d954c | 193 | } |
spiralray | 0:8d34375d954c | 194 | |
spiralray | 0:8d34375d954c | 195 | uint8_t SakuraIO::enqueueTx(uint8_t ch, uint8_t value[8], uint64_t offset){ |
spiralray | 0:8d34375d954c | 196 | return enqueueTxRaw(ch, 'b', 8, (uint8_t *)value, offset); |
spiralray | 0:8d34375d954c | 197 | } |
spiralray | 0:8d34375d954c | 198 | |
spiralray | 0:8d34375d954c | 199 | uint8_t SakuraIO::enqueueTx(uint8_t ch, int32_t value){ |
spiralray | 0:8d34375d954c | 200 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 201 | } |
spiralray | 0:8d34375d954c | 202 | |
spiralray | 0:8d34375d954c | 203 | uint8_t SakuraIO::enqueueTx(uint8_t ch, uint32_t value){ |
spiralray | 0:8d34375d954c | 204 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 205 | } |
spiralray | 0:8d34375d954c | 206 | |
spiralray | 0:8d34375d954c | 207 | uint8_t SakuraIO::enqueueTx(uint8_t ch, int64_t value){ |
spiralray | 0:8d34375d954c | 208 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 209 | } |
spiralray | 0:8d34375d954c | 210 | |
spiralray | 0:8d34375d954c | 211 | uint8_t SakuraIO::enqueueTx(uint8_t ch, uint64_t value){ |
spiralray | 0:8d34375d954c | 212 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 213 | } |
spiralray | 0:8d34375d954c | 214 | |
spiralray | 0:8d34375d954c | 215 | uint8_t SakuraIO::enqueueTx(uint8_t ch, float value){ |
spiralray | 0:8d34375d954c | 216 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 217 | } |
spiralray | 0:8d34375d954c | 218 | |
spiralray | 0:8d34375d954c | 219 | uint8_t SakuraIO::enqueueTx(uint8_t ch, double value){ |
spiralray | 0:8d34375d954c | 220 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 221 | } |
spiralray | 0:8d34375d954c | 222 | |
spiralray | 0:8d34375d954c | 223 | uint8_t SakuraIO::enqueueTx(uint8_t ch, uint8_t value[8]){ |
spiralray | 0:8d34375d954c | 224 | return enqueueTx(ch, value, (uint32_t)0); |
spiralray | 0:8d34375d954c | 225 | } |
spiralray | 0:8d34375d954c | 226 | |
chibiegg |
11:16e726ca39c6 | 227 | uint8_t SakuraIO::sendImmediatelyRaw(uint8_t ch, uint8_t type, uint8_t length, uint8_t *data, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 228 | uint8_t request[18] = {0x00}; |
chibiegg |
11:16e726ca39c6 | 229 | uint8_t requestLength = 10; |
chibiegg |
11:16e726ca39c6 | 230 | request[0] = ch; |
chibiegg |
11:16e726ca39c6 | 231 | request[1] = type; |
chibiegg |
11:16e726ca39c6 | 232 | for(uint8_t i=0;i<length;i++){ |
chibiegg |
11:16e726ca39c6 | 233 | request[2+i] = data[i]; |
chibiegg |
11:16e726ca39c6 | 234 | } |
chibiegg |
11:16e726ca39c6 | 235 | if(offset != 0){ |
chibiegg |
11:16e726ca39c6 | 236 | requestLength = 18; |
chibiegg |
11:16e726ca39c6 | 237 | for(uint8_t i=0;i<8;i++){ |
chibiegg |
11:16e726ca39c6 | 238 | request[10+i] = ((uint8_t *)&offset)[i]; |
chibiegg |
11:16e726ca39c6 | 239 | } |
chibiegg |
11:16e726ca39c6 | 240 | } |
chibiegg |
11:16e726ca39c6 | 241 | return executeCommand(CMD_TX_SENDIMMED, requestLength, request, NULL, NULL); |
chibiegg |
11:16e726ca39c6 | 242 | } |
chibiegg |
11:16e726ca39c6 | 243 | |
chibiegg |
11:16e726ca39c6 | 244 | uint8_t SakuraIO::sendImmediately(uint8_t ch, int32_t value, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 245 | return sendImmediatelyRaw(ch, 'i', 4, (uint8_t *)&value, offset); |
chibiegg |
11:16e726ca39c6 | 246 | } |
chibiegg |
11:16e726ca39c6 | 247 | |
chibiegg |
11:16e726ca39c6 | 248 | uint8_t SakuraIO::sendImmediately(uint8_t ch, uint32_t value, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 249 | return sendImmediatelyRaw(ch, 'I', 4, (uint8_t *)&value, offset); |
chibiegg |
11:16e726ca39c6 | 250 | } |
chibiegg |
11:16e726ca39c6 | 251 | |
chibiegg |
11:16e726ca39c6 | 252 | uint8_t SakuraIO::sendImmediately(uint8_t ch, int64_t value, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 253 | return sendImmediatelyRaw(ch, 'l', 8, (uint8_t *)&value, offset); |
chibiegg |
11:16e726ca39c6 | 254 | } |
chibiegg |
11:16e726ca39c6 | 255 | |
chibiegg |
11:16e726ca39c6 | 256 | uint8_t SakuraIO::sendImmediately(uint8_t ch, uint64_t value, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 257 | return sendImmediatelyRaw(ch, 'L', 8, (uint8_t *)&value, offset); |
chibiegg |
11:16e726ca39c6 | 258 | } |
chibiegg |
11:16e726ca39c6 | 259 | |
chibiegg |
11:16e726ca39c6 | 260 | uint8_t SakuraIO::sendImmediately(uint8_t ch, float value, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 261 | return sendImmediatelyRaw(ch, 'f', 4, (uint8_t *)&value, offset); |
chibiegg |
11:16e726ca39c6 | 262 | } |
chibiegg |
11:16e726ca39c6 | 263 | |
chibiegg |
11:16e726ca39c6 | 264 | uint8_t SakuraIO::sendImmediately(uint8_t ch, double value, uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 265 | return sendImmediatelyRaw(ch, 'd', 8, (uint8_t *)&value, offset); |
chibiegg |
11:16e726ca39c6 | 266 | } |
chibiegg |
11:16e726ca39c6 | 267 | |
chibiegg |
11:16e726ca39c6 | 268 | uint8_t SakuraIO::sendImmediately(uint8_t ch, uint8_t value[8], uint64_t offset){ |
chibiegg |
11:16e726ca39c6 | 269 | return sendImmediatelyRaw(ch, 'b', 8, (uint8_t *)value, offset); |
chibiegg |
11:16e726ca39c6 | 270 | } |
chibiegg |
11:16e726ca39c6 | 271 | |
chibiegg |
11:16e726ca39c6 | 272 | uint8_t SakuraIO::sendImmediately(uint8_t ch, int32_t value){ |
chibiegg |
11:16e726ca39c6 | 273 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 274 | } |
chibiegg |
11:16e726ca39c6 | 275 | |
chibiegg |
11:16e726ca39c6 | 276 | uint8_t SakuraIO::sendImmediately(uint8_t ch, uint32_t value){ |
chibiegg |
11:16e726ca39c6 | 277 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 278 | } |
chibiegg |
11:16e726ca39c6 | 279 | |
chibiegg |
11:16e726ca39c6 | 280 | uint8_t SakuraIO::sendImmediately(uint8_t ch, int64_t value){ |
chibiegg |
11:16e726ca39c6 | 281 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 282 | } |
chibiegg |
11:16e726ca39c6 | 283 | |
chibiegg |
11:16e726ca39c6 | 284 | uint8_t SakuraIO::sendImmediately(uint8_t ch, uint64_t value){ |
chibiegg |
11:16e726ca39c6 | 285 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 286 | } |
chibiegg |
11:16e726ca39c6 | 287 | |
chibiegg |
11:16e726ca39c6 | 288 | uint8_t SakuraIO::sendImmediately(uint8_t ch, float value){ |
chibiegg |
11:16e726ca39c6 | 289 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 290 | } |
chibiegg |
11:16e726ca39c6 | 291 | |
chibiegg |
11:16e726ca39c6 | 292 | uint8_t SakuraIO::sendImmediately(uint8_t ch, double value){ |
chibiegg |
11:16e726ca39c6 | 293 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 294 | } |
chibiegg |
11:16e726ca39c6 | 295 | |
chibiegg |
11:16e726ca39c6 | 296 | uint8_t SakuraIO::sendImmediately(uint8_t ch, uint8_t value[8]){ |
chibiegg |
11:16e726ca39c6 | 297 | return sendImmediately(ch, value, (uint32_t)0); |
chibiegg |
11:16e726ca39c6 | 298 | } |
chibiegg |
11:16e726ca39c6 | 299 | |
chibiegg |
11:16e726ca39c6 | 300 | |
chibiegg |
11:16e726ca39c6 | 301 | |
spiralray | 0:8d34375d954c | 302 | uint8_t SakuraIO::getTxQueueLength(uint8_t *available, uint8_t *queued){ |
spiralray | 0:8d34375d954c | 303 | uint8_t response[2] = {0x00}; |
spiralray | 0:8d34375d954c | 304 | uint8_t responseLength = 2; |
spiralray | 0:8d34375d954c | 305 | uint8_t ret = executeCommand(CMD_TX_LENGTH, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 306 | *available = response[0]; |
spiralray | 0:8d34375d954c | 307 | *queued = response[1]; |
spiralray | 0:8d34375d954c | 308 | return ret; |
spiralray | 0:8d34375d954c | 309 | } |
spiralray | 0:8d34375d954c | 310 | |
spiralray | 0:8d34375d954c | 311 | uint8_t SakuraIO::clearTx(){ |
spiralray | 0:8d34375d954c | 312 | return executeCommand(CMD_TX_CLEAR, 0, NULL, NULL, NULL); |
spiralray | 0:8d34375d954c | 313 | } |
spiralray | 0:8d34375d954c | 314 | |
spiralray | 0:8d34375d954c | 315 | uint8_t SakuraIO::send(){ |
spiralray | 0:8d34375d954c | 316 | return executeCommand(CMD_TX_SEND, 0, NULL, NULL, NULL); |
spiralray | 0:8d34375d954c | 317 | } |
spiralray | 0:8d34375d954c | 318 | |
spiralray | 0:8d34375d954c | 319 | uint8_t SakuraIO::getTxStatus(uint8_t *queue, uint8_t *immediate){ |
spiralray | 0:8d34375d954c | 320 | uint8_t response[2] = {0x00}; |
spiralray | 0:8d34375d954c | 321 | uint8_t responseLength = 2; |
spiralray | 0:8d34375d954c | 322 | uint8_t ret = executeCommand(CMD_TX_STAT, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 323 | *queue = response[0]; |
spiralray | 0:8d34375d954c | 324 | *immediate = response[1]; |
spiralray | 0:8d34375d954c | 325 | return ret; |
spiralray | 0:8d34375d954c | 326 | } |
spiralray | 0:8d34375d954c | 327 | |
spiralray | 0:8d34375d954c | 328 | /* RX Commands */ |
spiralray | 0:8d34375d954c | 329 | |
spiralray | 0:8d34375d954c | 330 | uint8_t SakuraIO::dequeueRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset){ |
spiralray | 0:8d34375d954c | 331 | uint8_t response[18] = {0x00}; |
spiralray | 0:8d34375d954c | 332 | uint8_t responseLength = 18; |
spiralray | 0:8d34375d954c | 333 | uint8_t ret = executeCommand(CMD_RX_DEQUEUE, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 334 | if(ret != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 335 | return ret; |
spiralray | 0:8d34375d954c | 336 | } |
spiralray | 0:8d34375d954c | 337 | |
spiralray | 0:8d34375d954c | 338 | *ch = response[0]; |
spiralray | 0:8d34375d954c | 339 | *type = response[1]; |
spiralray | 0:8d34375d954c | 340 | for(uint8_t i=0; i<8; i++){ |
spiralray | 0:8d34375d954c | 341 | value[i] = response[2+i]; |
spiralray | 0:8d34375d954c | 342 | } |
spiralray | 0:8d34375d954c | 343 | for(uint8_t i=0; i<8; i++){ |
spiralray | 0:8d34375d954c | 344 | ((uint8_t *)offset)[i] = response[10+i]; |
spiralray | 0:8d34375d954c | 345 | } |
spiralray | 0:8d34375d954c | 346 | |
spiralray | 0:8d34375d954c | 347 | return ret; |
spiralray | 0:8d34375d954c | 348 | } |
spiralray | 0:8d34375d954c | 349 | |
spiralray | 0:8d34375d954c | 350 | uint8_t SakuraIO::peekRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset){ |
spiralray | 0:8d34375d954c | 351 | uint8_t response[18] = {0x00}; |
spiralray | 0:8d34375d954c | 352 | uint8_t responseLength = 18; |
spiralray | 0:8d34375d954c | 353 | uint8_t ret = executeCommand(CMD_RX_PEEK, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 354 | if(ret != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 355 | return ret; |
spiralray | 0:8d34375d954c | 356 | } |
spiralray | 0:8d34375d954c | 357 | |
spiralray | 0:8d34375d954c | 358 | *ch = response[0]; |
spiralray | 0:8d34375d954c | 359 | *type = response[1]; |
spiralray | 0:8d34375d954c | 360 | for(uint8_t i=0; i<8; i++){ |
spiralray | 4:3d73874507bc | 361 | value[i] = response[2+i]; |
spiralray | 0:8d34375d954c | 362 | } |
spiralray | 0:8d34375d954c | 363 | for(uint8_t i=0; i<8; i++){ |
spiralray | 0:8d34375d954c | 364 | ((uint8_t *)offset)[i] = response[10+i]; |
spiralray | 0:8d34375d954c | 365 | } |
spiralray | 0:8d34375d954c | 366 | |
spiralray | 0:8d34375d954c | 367 | return ret; |
spiralray | 0:8d34375d954c | 368 | } |
spiralray | 0:8d34375d954c | 369 | |
spiralray | 0:8d34375d954c | 370 | uint8_t SakuraIO::getRxQueueLength(uint8_t *available, uint8_t *queued){ |
spiralray | 0:8d34375d954c | 371 | uint8_t response[2] = {0x00}; |
spiralray | 0:8d34375d954c | 372 | uint8_t responseLength = 2; |
spiralray | 0:8d34375d954c | 373 | uint8_t ret = executeCommand(CMD_RX_LENGTH, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 374 | *available = response[0]; |
spiralray | 0:8d34375d954c | 375 | *queued = response[1]; |
spiralray | 0:8d34375d954c | 376 | return ret; |
spiralray | 0:8d34375d954c | 377 | } |
spiralray | 0:8d34375d954c | 378 | |
spiralray | 0:8d34375d954c | 379 | uint8_t SakuraIO::clearRx(){ |
spiralray | 0:8d34375d954c | 380 | return executeCommand(CMD_RX_CLEAR, 0, NULL, NULL, NULL); |
spiralray | 0:8d34375d954c | 381 | } |
spiralray | 0:8d34375d954c | 382 | |
chibiegg |
11:16e726ca39c6 | 383 | /* File command */ |
chibiegg |
11:16e726ca39c6 | 384 | uint8_t SakuraIO::startFileDownload(uint16_t fileId){ |
chibiegg |
11:16e726ca39c6 | 385 | return executeCommand(CMD_START_FILE_DOWNLOAD, 2, (uint8_t *)&fileId, NULL, NULL); |
chibiegg |
11:16e726ca39c6 | 386 | } |
chibiegg |
11:16e726ca39c6 | 387 | |
chibiegg |
11:16e726ca39c6 | 388 | uint8_t SakuraIO::cancelFileDownload(){ |
chibiegg |
11:16e726ca39c6 | 389 | return executeCommand(CMD_CANCEL_FILE_DOWNLOAD, 0, NULL, NULL, NULL); |
chibiegg |
11:16e726ca39c6 | 390 | } |
chibiegg |
11:16e726ca39c6 | 391 | |
chibiegg |
11:16e726ca39c6 | 392 | uint8_t SakuraIO::getFileMetaData(uint8_t *status, uint32_t *totalSize, uint64_t *timestamp, uint32_t *crc){ |
chibiegg |
11:16e726ca39c6 | 393 | uint8_t response[17] = {0x00}; |
chibiegg |
11:16e726ca39c6 | 394 | uint8_t responseLength = 17; |
chibiegg |
11:16e726ca39c6 | 395 | uint8_t ret = executeCommand(CMD_GET_FILE_METADATA, 0, NULL, &responseLength, response); |
chibiegg |
11:16e726ca39c6 | 396 | *status = response[0]; |
chibiegg |
11:16e726ca39c6 | 397 | *totalSize = *(uint32_t *)(response+1); |
chibiegg |
11:16e726ca39c6 | 398 | *timestamp = *(uint64_t *)(response+5); |
chibiegg |
11:16e726ca39c6 | 399 | *crc = *(uint32_t *)(response+13); |
chibiegg |
11:16e726ca39c6 | 400 | return ret; |
chibiegg |
11:16e726ca39c6 | 401 | } |
chibiegg |
11:16e726ca39c6 | 402 | |
chibiegg |
11:16e726ca39c6 | 403 | uint8_t SakuraIO::getFileDownloadStatus(uint8_t *status, uint32_t *currentSize){ |
chibiegg |
11:16e726ca39c6 | 404 | uint8_t response[5] = {0x00}; |
chibiegg |
11:16e726ca39c6 | 405 | uint8_t responseLength = 5; |
chibiegg |
11:16e726ca39c6 | 406 | uint8_t ret = executeCommand(CMD_GET_FILE_DOWNLOAD_STATUS, 0, NULL, &responseLength, response); |
chibiegg |
11:16e726ca39c6 | 407 | *status = response[0]; |
chibiegg |
11:16e726ca39c6 | 408 | *currentSize = *(uint32_t *)(response+1); |
chibiegg |
11:16e726ca39c6 | 409 | return ret; |
chibiegg |
11:16e726ca39c6 | 410 | } |
chibiegg |
11:16e726ca39c6 | 411 | |
chibiegg |
11:16e726ca39c6 | 412 | uint8_t SakuraIO::getFileData(uint8_t *size, uint8_t *data){ |
chibiegg |
11:16e726ca39c6 | 413 | return executeCommand(CMD_GET_FILE_DATA, 1, size, size, data); |
chibiegg |
11:16e726ca39c6 | 414 | } |
chibiegg |
11:16e726ca39c6 | 415 | |
spiralray | 0:8d34375d954c | 416 | /* Operation command */ |
spiralray | 0:8d34375d954c | 417 | |
spiralray | 0:8d34375d954c | 418 | uint16_t SakuraIO::getProductID(){ |
spiralray | 0:8d34375d954c | 419 | uint8_t response[2] = {0x00}; |
spiralray | 0:8d34375d954c | 420 | uint8_t responseLength = 2; |
spiralray | 0:8d34375d954c | 421 | uint8_t ret = executeCommand(CMD_GET_PRODUCT_ID, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 422 | if(ret != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 423 | return 0x00; |
spiralray | 0:8d34375d954c | 424 | } |
spiralray | 0:8d34375d954c | 425 | return *((uint16_t *)response); |
spiralray | 0:8d34375d954c | 426 | } |
spiralray | 0:8d34375d954c | 427 | |
spiralray | 0:8d34375d954c | 428 | uint8_t SakuraIO::getUniqueID(char *data){ |
spiralray | 0:8d34375d954c | 429 | uint8_t response[11] = {0x00}; |
spiralray | 0:8d34375d954c | 430 | uint8_t responseLength = 10; |
spiralray | 0:8d34375d954c | 431 | uint8_t ret = executeCommand(CMD_GET_UNIQUE_ID, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 432 | if(ret != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 433 | return ret; |
spiralray | 0:8d34375d954c | 434 | } |
spiralray | 0:8d34375d954c | 435 | for(uint8_t i=0; i<responseLength; i++){ |
spiralray | 0:8d34375d954c | 436 | data[i] = (char)response[i]; |
spiralray | 0:8d34375d954c | 437 | } |
spiralray | 0:8d34375d954c | 438 | data[responseLength] = 0x00; |
spiralray | 0:8d34375d954c | 439 | return ret; |
spiralray | 0:8d34375d954c | 440 | } |
spiralray | 0:8d34375d954c | 441 | |
spiralray | 0:8d34375d954c | 442 | uint8_t SakuraIO::getFirmwareVersion(char *data){ |
spiralray | 0:8d34375d954c | 443 | uint8_t response[33] = {0x00}; |
spiralray | 0:8d34375d954c | 444 | uint8_t responseLength = 32; |
spiralray | 0:8d34375d954c | 445 | uint8_t ret = executeCommand(CMD_GET_FIRMWARE_VERSION, 0, NULL, &responseLength, response); |
spiralray | 0:8d34375d954c | 446 | if(ret != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 447 | return ret; |
spiralray | 0:8d34375d954c | 448 | } |
spiralray | 0:8d34375d954c | 449 | for(uint8_t i=0; i<responseLength; i++){ |
spiralray | 0:8d34375d954c | 450 | data[i] = (char)response[i]; |
spiralray | 0:8d34375d954c | 451 | } |
spiralray | 0:8d34375d954c | 452 | data[responseLength] = 0x00; |
spiralray | 0:8d34375d954c | 453 | return ret; |
spiralray | 0:8d34375d954c | 454 | } |
spiralray | 0:8d34375d954c | 455 | |
spiralray | 0:8d34375d954c | 456 | uint8_t SakuraIO::unlock(){ |
spiralray | 0:8d34375d954c | 457 | uint8_t request[4] = {0x53, 0x6B, 0x72, 0x61}; |
spiralray | 0:8d34375d954c | 458 | return executeCommand(CMD_UNLOCK, 4, request, NULL, NULL); |
spiralray | 0:8d34375d954c | 459 | } |
spiralray | 0:8d34375d954c | 460 | |
spiralray | 0:8d34375d954c | 461 | uint8_t SakuraIO::updateFirmware(){ |
spiralray | 0:8d34375d954c | 462 | return executeCommand(CMD_UPDATE_FIRMWARE, 0, 0, NULL, NULL); |
spiralray | 0:8d34375d954c | 463 | } |
spiralray | 0:8d34375d954c | 464 | |
spiralray | 0:8d34375d954c | 465 | uint8_t SakuraIO::getFirmwareUpdateStatus(){ |
spiralray | 0:8d34375d954c | 466 | uint8_t response[1] = {0x00}; |
spiralray | 0:8d34375d954c | 467 | uint8_t responseLength = 1; |
spiralray | 0:8d34375d954c | 468 | if(executeCommand(CMD_GET_UPDATE_FIRMWARE_STATUS, 0, 0, &responseLength, response) != CMD_ERROR_NONE){ |
spiralray | 0:8d34375d954c | 469 | return 0xff; |
spiralray | 0:8d34375d954c | 470 | } |
spiralray | 0:8d34375d954c | 471 | return response[0]; |
spiralray | 0:8d34375d954c | 472 | } |
spiralray | 0:8d34375d954c | 473 | |
spiralray | 0:8d34375d954c | 474 | uint8_t SakuraIO::reset(){ |
spiralray | 0:8d34375d954c | 475 | return executeCommand(CMD_SOFTWARE_RESET, 0, 0, NULL, NULL); |
spiralray | 0:8d34375d954c | 476 | } |