LM005A Lora Module test
Dependents: LoRaTest OnenetTest
Diff: LM005A/LM005A.h
- Revision:
- 0:5b5a1b5f1ae4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM005A/LM005A.h Thu Apr 19 13:15:25 2018 +0000 @@ -0,0 +1,161 @@ +/* LM005AInterface Example + * Copyright (c) 2015 MAXIUM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LM005A_H +#define LM005A_H + +#include "ATCmdParser.h" + +/** LM005AInterface class. + This is an interface to a LM005A radio. + */ +class LM005A +{ +public: + LM005A(PinName tx, PinName rx, bool debug=false); + bool init(void); + /** + * Check firmware version of LM005A + * + * @return firmware version string + */ + const char * get_firmware_version(void); + + /** + * 设置终端入网激活模式 + * + * @param mode 终端入网激活模式 0-OTA, 1-ABP + * @return true only if LM005A was setup correctly + */ + int set_mode(int mode); + /** + * 设置终端CLASS模式 + * + * @param class_mode 终端入网CLASS模式 0-OTA, 1-ABP + * @return true only if LM005A was setup correctly + */ + int set_band(int gap,int band); + /** + * 设置终端CLASS模式 + * + * @param class_mode 终端入网CLASS模式 0-OTA, 1-ABP + * @return true only if LM005A was setup correctly + */ + int set_class(int class_mode); + /** + * 设置终端发射功率 + * + * @param power 终端终端发射功率 (20,17,16,14,12,10,7,5,2) In DB + * @return true + */ +int set_power(int power); + /** + * Get EUI + * @param type 0 deveui 1 appeui + * @return null-teriminated EUI or null if no IP address is assigned + */ + const char *getEUI(int type); + + /** + * Get device address + * eui + * @return null-teriminated Device address or null if no IP address is assigned + */ + const char *getDeviceAddress(void); + /** + * Reset LM005A + * + * @return true only if LM005A resets successfully + */ + + bool reset(void); + + /** + * jion LM005A to Network + * + * @param ap the name of the AP + * @param passPhrase the password of AP + * @return NSAPI_ERROR_OK only if LM005A is connected successfully + */ + bool join(); + + /** + * Send data + * + * @param port 端口 ack 重发标志 + * @param data data to be sent + * @param amount amount of data to be sent - max 1024 + * @return true only if data sent successfully + */ + bool send(int port,int ack, const void *data, uint32_t amount); + /** + * Send data hex + * + * @param port 端口 ack 重发标志 + * @param data data to be sent + * @param amount amount of data to be sent in hex + * @return true only if data sent successfully + */ + bool sendhex(int port,int ack, const void *data, uint32_t amount); + /** + * Receives data from an open socket + * + * @param id id to receive from + * @param data placeholder for returned information + * @param amount number of bytes to be received + * @return the number of bytes received + */ + int32_t recv(int id, void *data, uint32_t amount); + + /** + * Allows timeout to be changed between commands + * + * @param timeout_ms timeout of the connection + */ + void setTimeout(uint32_t timeout_ms); + + + /** + * Attach a function to call whenever network state has changed + * + * @param func A pointer to a void function, or 0 to set as none + */ + void attach(Callback<void()> func); + + /** + * Attach a function to call whenever network state has changed + * + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to call + */ + template <typename T, typename M> + void attach(T *obj, M method) { + attach(Callback<void()>(obj, method)); + } + +private: + UARTSerial _serial; + ATCmdParser _parser; + char buffer[256]; + char rBuffer[256]; + int rIndex; + int rCounter; + int _connect_error; + bool _fail; + void _packet_handler(); +}; + +#endif