an old afLib which supports both SPI and UART
Embed:
(wiki syntax)
Show/hide line numbers
iafLib.h
00001 /** 00002 * Copyright 2015 Afero, Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /** 00018 * afLib public interface 00019 * 00020 * This file defines everything your application should need for commuinicating with the Afero ASR-1 radio module. 00021 * Is there is anything missing from this file, please post a request on the developer forum and we will see what 00022 * we can do. 00023 */ 00024 #ifndef AFLIB_IAFLIB_H 00025 #define AFLIB_IAFLIB_H 00026 00027 #include "mbed.h" 00028 #define Stream Serial 00029 #include "afErrors.h" 00030 #include "afSPI.h" 00031 #include "afUART.h" 00032 #include "afTransport.h" 00033 00034 #define afMINIMUM_TIME_BETWEEN_REQUESTS 1000 00035 00036 #define MAX_ATTRIBUTE_SIZE 255 00037 00038 typedef void (*isr)(); 00039 typedef bool (*AttrSetHandler)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value); 00040 typedef void (*AttrNotifyHandler)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value); 00041 00042 class iafLib { 00043 public: 00044 /** 00045 * create 00046 * 00047 * Create an instance of the afLib object. The afLib is a singleton. Calling this method multiple 00048 * times will return the same instance. 00049 * 00050 * @param attrSet Callback for notification of attribute set requests 00051 * @param attrNotify Callback for notification of attribute set request completions 00052 * @param theLog An instance of a Stream object that will be used for debug prints 00053 * @param theTransport An instance of an afTransport object to be used for communications with the ASR-1 00054 * @param attrNotify Callback for notification of attribute set request completions 00055 * @return iafLib * Instance of iafLib 00056 */ 00057 static iafLib * create(AttrSetHandler attrSet, AttrNotifyHandler attrNotify, Stream *theLog, afTransport *theTransport); 00058 00059 static iafLib * create(PinName mcuInterrupt, isr isrWrapper, AttrSetHandler attrSet, AttrNotifyHandler attrNotify, Stream *theLog, afTransport *theTransport); 00060 00061 /** 00062 * loop 00063 * 00064 * Called by the loop() method in your sketch to give afLib some CPU time 00065 */ 00066 virtual void loop(void) = 0; 00067 00068 /** 00069 * getAttribute 00070 * 00071 * Request the value of an attribute be returned from the ASR-1. 00072 * Value will be returned in the attrNotify callback. 00073 */ 00074 virtual int getAttribute(const uint16_t attrId) = 0; 00075 00076 /** 00077 * setAttribute 00078 * 00079 * Request setting an attribute. 00080 * For MCU attributes, the attribute value will be updated. 00081 * For IO attributes, the attribute value will be updated, and then onAttrSetComplete will be called. 00082 */ 00083 virtual int setAttributeBool(const uint16_t attrId, const bool value) = 0; 00084 00085 virtual int setAttribute8(const uint16_t attrId, const int8_t value) = 0; 00086 00087 virtual int setAttribute16(const uint16_t attrId, const int16_t value) = 0; 00088 00089 virtual int setAttribute32(const uint16_t attrId, const int32_t value) = 0; 00090 00091 virtual int setAttribute64(const uint16_t attrId, const int64_t value) = 0; 00092 00093 virtual int setAttributeStr(const uint16_t attrId, const char *value) = 0; 00094 00095 virtual int setAttributeCStr(const uint16_t attrId, const uint16_t valueLen, const char *value) = 0; 00096 00097 virtual int setAttributeBytes(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value) = 0; 00098 00099 /** 00100 * isIdle 00101 * 00102 * Call to find out of the ASR-1 is currently handling a request. 00103 * 00104 * @return true if an operation is in progress 00105 */ 00106 virtual bool isIdle() = 0; 00107 00108 /** 00109 * mcuISR 00110 * 00111 * Called by your sketch to pass the interrupt along to afLib. 00112 */ 00113 virtual void mcuISR() = 0; 00114 }; 00115 #endif //AFLIB_IAFLIB_H
Generated on Wed Jul 13 2022 19:00:06 by
1.7.2