Release candidate version. The pointer in GAS Pressure display is changed to a triangle.
Dependencies: UniGraphic mbed vt100
Please note, at 2-Mar-2018 the current version of mbed-lib has a defect in Ticker.
https://os.mbed.com/forum/bugs-suggestions/topic/29287/
So, mbed lib version 157 is intentionally being used.
Please do not update mbed library until the problem in the above URL is fixed.
In this version, format of GAS Pressure Display has been changed.
moto
afLib/StatusCommand.cpp@0:774324cbc5a6, 2018-03-02 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Mar 02 07:56:09 2018 +0000
- Revision:
- 0:774324cbc5a6
Release candidate version. GAS Pressure pointer is now a triangle.; Some source file clean-up was done.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:774324cbc5a6 | 1 | /** |
Rhyme | 0:774324cbc5a6 | 2 | * Copyright 2015 Afero, Inc. |
Rhyme | 0:774324cbc5a6 | 3 | * |
Rhyme | 0:774324cbc5a6 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rhyme | 0:774324cbc5a6 | 5 | * you may not use this file except in compliance with the License. |
Rhyme | 0:774324cbc5a6 | 6 | * You may obtain a copy of the License at |
Rhyme | 0:774324cbc5a6 | 7 | * |
Rhyme | 0:774324cbc5a6 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rhyme | 0:774324cbc5a6 | 9 | * |
Rhyme | 0:774324cbc5a6 | 10 | * Unless required by applicable law or agreed to in writing, software |
Rhyme | 0:774324cbc5a6 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rhyme | 0:774324cbc5a6 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rhyme | 0:774324cbc5a6 | 13 | * See the License for the specific language governing permissions and |
Rhyme | 0:774324cbc5a6 | 14 | * limitations under the License. |
Rhyme | 0:774324cbc5a6 | 15 | */ |
Rhyme | 0:774324cbc5a6 | 16 | |
Rhyme | 0:774324cbc5a6 | 17 | #include "StatusCommand.h" |
Rhyme | 0:774324cbc5a6 | 18 | |
Rhyme | 0:774324cbc5a6 | 19 | #define SERIAL_PRINT_DBG_ASR_ON 0 |
Rhyme | 0:774324cbc5a6 | 20 | |
Rhyme | 0:774324cbc5a6 | 21 | StatusCommand::StatusCommand(uint16_t bytesToSend) { |
Rhyme | 0:774324cbc5a6 | 22 | _cmd = 0x30; |
Rhyme | 0:774324cbc5a6 | 23 | _bytesToSend = bytesToSend; |
Rhyme | 0:774324cbc5a6 | 24 | _bytesToRecv = 0; |
Rhyme | 0:774324cbc5a6 | 25 | } |
Rhyme | 0:774324cbc5a6 | 26 | |
Rhyme | 0:774324cbc5a6 | 27 | StatusCommand::StatusCommand() { |
Rhyme | 0:774324cbc5a6 | 28 | _cmd = 0x30; |
Rhyme | 0:774324cbc5a6 | 29 | _bytesToSend = 0; |
Rhyme | 0:774324cbc5a6 | 30 | _bytesToRecv = 0; |
Rhyme | 0:774324cbc5a6 | 31 | } |
Rhyme | 0:774324cbc5a6 | 32 | |
Rhyme | 0:774324cbc5a6 | 33 | StatusCommand::~StatusCommand() { |
Rhyme | 0:774324cbc5a6 | 34 | } |
Rhyme | 0:774324cbc5a6 | 35 | |
Rhyme | 0:774324cbc5a6 | 36 | uint16_t StatusCommand::getSize() { |
Rhyme | 0:774324cbc5a6 | 37 | return sizeof(_cmd) + sizeof(_bytesToSend) + sizeof(_bytesToRecv); |
Rhyme | 0:774324cbc5a6 | 38 | } |
Rhyme | 0:774324cbc5a6 | 39 | |
Rhyme | 0:774324cbc5a6 | 40 | uint16_t StatusCommand::getBytes(int *bytes) { |
Rhyme | 0:774324cbc5a6 | 41 | int index = 0; |
Rhyme | 0:774324cbc5a6 | 42 | |
Rhyme | 0:774324cbc5a6 | 43 | bytes[index++] = (_cmd); |
Rhyme | 0:774324cbc5a6 | 44 | bytes[index++] = (_bytesToSend & 0xff); |
Rhyme | 0:774324cbc5a6 | 45 | bytes[index++] = ((_bytesToSend >> 8) & 0xff); |
Rhyme | 0:774324cbc5a6 | 46 | bytes[index++] = (_bytesToRecv & 0xff); |
Rhyme | 0:774324cbc5a6 | 47 | bytes[index++] = ((_bytesToRecv >> 8) & 0xff); |
Rhyme | 0:774324cbc5a6 | 48 | |
Rhyme | 0:774324cbc5a6 | 49 | return index; |
Rhyme | 0:774324cbc5a6 | 50 | } |
Rhyme | 0:774324cbc5a6 | 51 | |
Rhyme | 0:774324cbc5a6 | 52 | uint8_t StatusCommand::calcChecksum() { |
Rhyme | 0:774324cbc5a6 | 53 | uint8_t result = 0; |
Rhyme | 0:774324cbc5a6 | 54 | |
Rhyme | 0:774324cbc5a6 | 55 | result += (_cmd); |
Rhyme | 0:774324cbc5a6 | 56 | result += (_bytesToSend & 0xff); |
Rhyme | 0:774324cbc5a6 | 57 | result += ((_bytesToSend >> 8) & 0xff); |
Rhyme | 0:774324cbc5a6 | 58 | result += (_bytesToRecv & 0xff); |
Rhyme | 0:774324cbc5a6 | 59 | result += ((_bytesToRecv >> 8) & 0xff); |
Rhyme | 0:774324cbc5a6 | 60 | |
Rhyme | 0:774324cbc5a6 | 61 | return result; |
Rhyme | 0:774324cbc5a6 | 62 | } |
Rhyme | 0:774324cbc5a6 | 63 | |
Rhyme | 0:774324cbc5a6 | 64 | void StatusCommand::setChecksum(uint8_t checksum) { |
Rhyme | 0:774324cbc5a6 | 65 | _checksum = checksum; |
Rhyme | 0:774324cbc5a6 | 66 | } |
Rhyme | 0:774324cbc5a6 | 67 | |
Rhyme | 0:774324cbc5a6 | 68 | uint8_t StatusCommand::getChecksum() { |
Rhyme | 0:774324cbc5a6 | 69 | uint8_t result = 0; |
Rhyme | 0:774324cbc5a6 | 70 | |
Rhyme | 0:774324cbc5a6 | 71 | result += (_cmd); |
Rhyme | 0:774324cbc5a6 | 72 | result += (_bytesToSend & 0xff); |
Rhyme | 0:774324cbc5a6 | 73 | result += ((_bytesToSend >> 8) & 0xff); |
Rhyme | 0:774324cbc5a6 | 74 | result += (_bytesToRecv & 0xff); |
Rhyme | 0:774324cbc5a6 | 75 | result += ((_bytesToRecv >> 8) & 0xff); |
Rhyme | 0:774324cbc5a6 | 76 | |
Rhyme | 0:774324cbc5a6 | 77 | return result; |
Rhyme | 0:774324cbc5a6 | 78 | } |
Rhyme | 0:774324cbc5a6 | 79 | |
Rhyme | 0:774324cbc5a6 | 80 | void StatusCommand::setAck(bool ack) { |
Rhyme | 0:774324cbc5a6 | 81 | _cmd = ack ? 0x31 : 0x30; |
Rhyme | 0:774324cbc5a6 | 82 | } |
Rhyme | 0:774324cbc5a6 | 83 | |
Rhyme | 0:774324cbc5a6 | 84 | void StatusCommand::setBytesToSend(uint16_t bytesToSend) { |
Rhyme | 0:774324cbc5a6 | 85 | _bytesToSend = bytesToSend; |
Rhyme | 0:774324cbc5a6 | 86 | } |
Rhyme | 0:774324cbc5a6 | 87 | |
Rhyme | 0:774324cbc5a6 | 88 | uint16_t StatusCommand::getBytesToSend() { |
Rhyme | 0:774324cbc5a6 | 89 | return _bytesToSend; |
Rhyme | 0:774324cbc5a6 | 90 | } |
Rhyme | 0:774324cbc5a6 | 91 | |
Rhyme | 0:774324cbc5a6 | 92 | void StatusCommand::setBytesToRecv(uint16_t bytesToRecv) { |
Rhyme | 0:774324cbc5a6 | 93 | _bytesToRecv = bytesToRecv; |
Rhyme | 0:774324cbc5a6 | 94 | } |
Rhyme | 0:774324cbc5a6 | 95 | |
Rhyme | 0:774324cbc5a6 | 96 | uint16_t StatusCommand::getBytesToRecv() { |
Rhyme | 0:774324cbc5a6 | 97 | return _bytesToRecv; |
Rhyme | 0:774324cbc5a6 | 98 | } |
Rhyme | 0:774324cbc5a6 | 99 | |
Rhyme | 0:774324cbc5a6 | 100 | bool StatusCommand::equals(StatusCommand *statusCommand) { |
Rhyme | 0:774324cbc5a6 | 101 | return (_cmd == statusCommand->_cmd && _bytesToSend == statusCommand->_bytesToSend && |
Rhyme | 0:774324cbc5a6 | 102 | _bytesToRecv == statusCommand->_bytesToRecv); |
Rhyme | 0:774324cbc5a6 | 103 | } |
Rhyme | 0:774324cbc5a6 | 104 | |
Rhyme | 0:774324cbc5a6 | 105 | bool StatusCommand::isValid() { |
Rhyme | 0:774324cbc5a6 | 106 | return (_checksum == calcChecksum()) && (_cmd == 0x30 || _cmd == 0x31); |
Rhyme | 0:774324cbc5a6 | 107 | } |
Rhyme | 0:774324cbc5a6 | 108 | |
Rhyme | 0:774324cbc5a6 | 109 | void StatusCommand::dumpBytes() { |
Rhyme | 0:774324cbc5a6 | 110 | #if SERIAL_PRINT_DBG_ASR_ON |
Rhyme | 0:774324cbc5a6 | 111 | int len = getSize(); |
Rhyme | 0:774324cbc5a6 | 112 | int bytes[len]; |
Rhyme | 0:774324cbc5a6 | 113 | getBytes(bytes); |
Rhyme | 0:774324cbc5a6 | 114 | |
Rhyme | 0:774324cbc5a6 | 115 | printf("len : %d\n",len); |
Rhyme | 0:774324cbc5a6 | 116 | printf("data : "); |
Rhyme | 0:774324cbc5a6 | 117 | for (int i = 0; i < len; i++) { |
Rhyme | 0:774324cbc5a6 | 118 | if (i > 0) { |
Rhyme | 0:774324cbc5a6 | 119 | printf(", "); |
Rhyme | 0:774324cbc5a6 | 120 | } |
Rhyme | 0:774324cbc5a6 | 121 | int b = bytes[i] & 0xff; |
Rhyme | 0:774324cbc5a6 | 122 | printf("0x%02x", b) ; |
Rhyme | 0:774324cbc5a6 | 123 | } |
Rhyme | 0:774324cbc5a6 | 124 | printf("\n") ; |
Rhyme | 0:774324cbc5a6 | 125 | #endif |
Rhyme | 0:774324cbc5a6 | 126 | } |
Rhyme | 0:774324cbc5a6 | 127 | |
Rhyme | 0:774324cbc5a6 | 128 | void StatusCommand::dump() { |
Rhyme | 0:774324cbc5a6 | 129 | #if SERIAL_PRINT_DBG_ASR_ON |
Rhyme | 0:774324cbc5a6 | 130 | printf("cmd : %s\n",_cmd == 0x30 ? "STATUS" : "STATUS_ACK"); |
Rhyme | 0:774324cbc5a6 | 131 | printf("bytes to send : %d\n",_bytesToSend); |
Rhyme | 0:774324cbc5a6 | 132 | printf("bytes to receive : %d\n",_bytesToRecv); |
Rhyme | 0:774324cbc5a6 | 133 | #endif |
Rhyme | 0:774324cbc5a6 | 134 | } |
Rhyme | 0:774324cbc5a6 | 135 |