nsp specific components for the NSP version of the impact endpoint
Dependents: mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp
NSPio.cpp@0:e1c4378df3fe, 2014-03-26 (annotated)
- Committer:
- ansond
- Date:
- Wed Mar 26 19:51:29 2014 +0000
- Revision:
- 0:e1c4378df3fe
- Child:
- 28:b6a7959c8be0
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:e1c4378df3fe | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 0:e1c4378df3fe | 2 | * |
ansond | 0:e1c4378df3fe | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:e1c4378df3fe | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:e1c4378df3fe | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:e1c4378df3fe | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:e1c4378df3fe | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:e1c4378df3fe | 8 | * |
ansond | 0:e1c4378df3fe | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:e1c4378df3fe | 10 | * substantial portions of the Software. |
ansond | 0:e1c4378df3fe | 11 | * |
ansond | 0:e1c4378df3fe | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:e1c4378df3fe | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:e1c4378df3fe | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:e1c4378df3fe | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:e1c4378df3fe | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:e1c4378df3fe | 17 | */ |
ansond | 0:e1c4378df3fe | 18 | |
ansond | 0:e1c4378df3fe | 19 | #include "NSPio.h" |
ansond | 0:e1c4378df3fe | 20 | |
ansond | 0:e1c4378df3fe | 21 | // default constructor |
ansond | 0:e1c4378df3fe | 22 | NSPio::NSPio(ErrorHandler *error_handler,Resource *resource,sn_send_observation_t obs_sender) : MBEDio(error_handler,resource) { |
ansond | 0:e1c4378df3fe | 23 | this->m_obs_sender = obs_sender; |
ansond | 0:e1c4378df3fe | 24 | this->m_mbed_io = NULL; |
ansond | 0:e1c4378df3fe | 25 | } |
ansond | 0:e1c4378df3fe | 26 | |
ansond | 0:e1c4378df3fe | 27 | // wrapping a generic MBEDio within a NSPio so that we can do things like NSP observation... |
ansond | 0:e1c4378df3fe | 28 | NSPio::NSPio(MBEDio *mbed_io,sn_send_observation_t obs_sender) : MBEDio(mbed_io->logger(),mbed_io->resource()) { |
ansond | 0:e1c4378df3fe | 29 | this->m_obs_sender = obs_sender; |
ansond | 0:e1c4378df3fe | 30 | this->m_mbed_io = mbed_io; |
ansond | 0:e1c4378df3fe | 31 | if (this->m_mbed_io != NULL && this->m_mbed_io->resource() != NULL) this->m_mbed_io->resource()->setIO(this); |
ansond | 0:e1c4378df3fe | 32 | } |
ansond | 0:e1c4378df3fe | 33 | |
ansond | 0:e1c4378df3fe | 34 | // destructor |
ansond | 0:e1c4378df3fe | 35 | NSPio::~NSPio() { |
ansond | 0:e1c4378df3fe | 36 | } |
ansond | 0:e1c4378df3fe | 37 | |
ansond | 0:e1c4378df3fe | 38 | // send an observation |
ansond | 0:e1c4378df3fe | 39 | void NSPio::sendObservation() { if (this->m_obs_sender != NULL) (this->m_obs_sender)(); } |
ansond | 0:e1c4378df3fe | 40 | |
ansond | 0:e1c4378df3fe | 41 | // update |
ansond | 0:e1c4378df3fe | 42 | void NSPio::update() { if (this->m_mbed_io != NULL) this->m_mbed_io->update(); } |
ansond | 0:e1c4378df3fe | 43 | |
ansond | 0:e1c4378df3fe | 44 | // get the float value (refreshes the value) |
ansond | 0:e1c4378df3fe | 45 | float NSPio::floatValue() { |
ansond | 0:e1c4378df3fe | 46 | if (this->m_mbed_io != NULL) return this->m_mbed_io->floatValue(); |
ansond | 0:e1c4378df3fe | 47 | return MBEDio::floatValue(); |
ansond | 0:e1c4378df3fe | 48 | } |
ansond | 0:e1c4378df3fe | 49 | |
ansond | 0:e1c4378df3fe | 50 | // get the int value (refreshes the value) |
ansond | 0:e1c4378df3fe | 51 | int NSPio::intValue() { |
ansond | 0:e1c4378df3fe | 52 | if (this->m_mbed_io != NULL) return this->m_mbed_io->intValue(); |
ansond | 0:e1c4378df3fe | 53 | return MBEDio::intValue(); |
ansond | 0:e1c4378df3fe | 54 | } |
ansond | 0:e1c4378df3fe | 55 | |
ansond | 0:e1c4378df3fe | 56 | // get the string value (refreshes the value) |
ansond | 0:e1c4378df3fe | 57 | char *NSPio::stringValue() { |
ansond | 0:e1c4378df3fe | 58 | if (this->m_mbed_io != NULL) return this->m_mbed_io->stringValue(); |
ansond | 0:e1c4378df3fe | 59 | return MBEDio::stringValue(); |
ansond | 0:e1c4378df3fe | 60 | } |