Xbee s2b for lpc11u24
Dependencies: DigiLogger
Fork of XBeeLib by
IO/IOSampleZB.cpp
- Committer:
- spastor
- Date:
- 2015-05-08
- Revision:
- 0:fcaad0dfa051
- Child:
- 3:8662ebe83570
File content as of revision 0:fcaad0dfa051:
#include "XBeeLib.h" #include "IO/IOSampleZB.h" #define IO_SAMPLE_ZB_MIN_SIZE (2 + 1 + 2) using namespace XBeeLib; IOSampleZB::IOSampleZB(const uint8_t* const raw_data, size_t size) { assert(size >= IO_SAMPLE_ZB_MIN_SIZE); assert(size <= sizeof _sampled_data); _digital_mask = UINT16(raw_data[1], raw_data[2]); _analog_mask = raw_data[3]; _sampled_data_size = size - 4; memcpy(&_sampled_data[0], &raw_data[4], _sampled_data_size); } IOSampleZB::~IOSampleZB() { } RadioStatus IOSampleZB::get_dio(XBeeZB::IoLine line, DioVal* const dio_value) const { const uint16_t mask = 1 << line; if (mask & _digital_mask) { const uint16_t digital_channels = get_digital_channels(); *dio_value = digital_channels & mask ? High : Low; return Success; } return Failure; } RadioStatus IOSampleZB::get_adc(XBeeZB::IoLine line, uint16_t* const val) const { const uint8_t line_mask = 1 << line; const bool adc_present = line_mask & _analog_mask; if (!adc_present) { return Failure; } uint8_t analog_data_idx = _digital_mask == 0 ? 0 : 2; uint8_t line_sample = 0; while (analog_data_idx < _sampled_data_size) { if (_analog_mask & (1 << line_sample)) { if (line_sample == line) { /* Write the analog value */ *val = UINT16(_sampled_data[analog_data_idx], _sampled_data[analog_data_idx + 1]); break; } analog_data_idx += 2; } line_sample++; } return Success; } inline uint16_t IOSampleZB::get_digital_channels(void) const { if (_digital_mask == 0) { return 0; } return UINT16(_sampled_data[0], _sampled_data[1]); }