Interplan IM920 library, 920MHz module
Dependents: IM920_sample IM920_SDlog IM920_sample IM920_sample3 ... more
IM920.cpp
00001 /* Copyright (C) 2014 Suga, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 #include "IM920.h" 00019 00020 IM920::IM920 (PinName tx, PinName rx, PinName busy, PinName reset, int baud) : _im(tx, rx) { 00021 00022 memset(&_state, 0, sizeof(_state)); 00023 _state.data = new CircBuffer<char>(CFG_DATA_SIZE); 00024 00025 initUart(busy, reset, baud); 00026 setReset(true); 00027 wait_ms(100); 00028 setReset(false); 00029 } 00030 00031 int IM920::init () { 00032 00033 cmdRDID(); 00034 cmdRDNN(); 00035 cmdSTPO(3); // 10dBm 00036 cmdSTRT(2); // 1.25kbps 00037 return 0; 00038 } 00039 00040 void IM920::poll () { 00041 00042 if (_state.received && _state.buf != NULL) 00043 if (!_state.data->isEmpty()) { 00044 _func.call(); 00045 if (_state.data->isEmpty()) { 00046 _state.received = false; 00047 } 00048 } 00049 } 00050 00051 int IM920::send (char *buf, int len) { 00052 00053 if (len > 64) len = 64; 00054 00055 return sendData(buf, len); 00056 } 00057 00058 int IM920::recv (char *buf, int len) { 00059 int i; 00060 00061 if (_state.data == NULL) return 0; 00062 while (!_state.received && _state.mode != MODE_COMMAND); 00063 _state.received = false; 00064 for (i = 0; i < len; i ++) { 00065 if (_state.data->dequeue(&buf[i]) == false) break; 00066 } 00067 return i; 00068 }
Generated on Sat Jul 16 2022 00:47:33 by 1.7.2