Error Handler/Logger construct for mbed applications
ErrorHandler.h@7:4844475a4135, 2014-09-21 (annotated)
- Committer:
- ansond
- Date:
- Sun Sep 21 07:08:09 2014 +0000
- Revision:
- 7:4844475a4135
- Parent:
- 6:be3ca195f0d1
- Child:
- 8:cc73ab137ae9
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:906788c5813d | 1 | /* Copyright C2014 ARM, MIT License |
ansond | 0:906788c5813d | 2 | * |
ansond | 0:906788c5813d | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:906788c5813d | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:906788c5813d | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:906788c5813d | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:906788c5813d | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:906788c5813d | 8 | * |
ansond | 0:906788c5813d | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:906788c5813d | 10 | * substantial portions of the Software. |
ansond | 0:906788c5813d | 11 | * |
ansond | 0:906788c5813d | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:906788c5813d | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:906788c5813d | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:906788c5813d | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:906788c5813d | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:906788c5813d | 17 | */ |
ansond | 0:906788c5813d | 18 | |
ansond | 0:906788c5813d | 19 | #ifndef _ERROR_HANDLER_H_ |
ansond | 0:906788c5813d | 20 | #define _ERROR_HANDLER_H_ |
ansond | 0:906788c5813d | 21 | |
ansond | 0:906788c5813d | 22 | // our definitions |
ansond | 0:906788c5813d | 23 | #include "Definitions.h" |
ansond | 0:906788c5813d | 24 | |
ansond | 7:4844475a4135 | 25 | // biggest log message length |
ansond | 7:4844475a4135 | 26 | #define MAX_LOG_MESSAGE_PREFIX 128 |
ansond | 7:4844475a4135 | 27 | #define MAX_LOG_MESSAGE (MAX_BUFFER_LENGTH+MAX_LOG_MESSAGE_PREFIX+1) |
ansond | 7:4844475a4135 | 28 | |
ansond | 0:906788c5813d | 29 | // Support for varargs |
ansond | 0:906788c5813d | 30 | #include <stdarg.h> |
ansond | 0:906788c5813d | 31 | |
ansond | 0:906788c5813d | 32 | // LCD Support |
ansond | 0:906788c5813d | 33 | #if _UBLOX_PLATFORM |
ansond | 0:906788c5813d | 34 | #include "C12832.h" |
ansond | 0:906788c5813d | 35 | #define LCDCLASS C12832 |
ansond | 0:906788c5813d | 36 | #endif |
ansond | 0:906788c5813d | 37 | |
ansond | 0:906788c5813d | 38 | #if _NXP_PLATFORM |
ansond | 0:906788c5813d | 39 | #include "C12832_lcd.h" |
ansond | 0:906788c5813d | 40 | #define LCDCLASS C12832_LCD |
ansond | 0:906788c5813d | 41 | #endif |
ansond | 1:8d42444464d3 | 42 | |
ansond | 2:e771ffdf5c1b | 43 | #if _K64F_PLATFORM |
ansond | 2:e771ffdf5c1b | 44 | #define LCDCLASS void // not used |
ansond | 2:e771ffdf5c1b | 45 | #endif |
ansond | 2:e771ffdf5c1b | 46 | |
ansond | 0:906788c5813d | 47 | class ErrorHandler { |
ansond | 0:906788c5813d | 48 | private: |
ansond | 5:7b3bbd74c1b1 | 49 | RawSerial *m_pc; |
ansond | 5:7b3bbd74c1b1 | 50 | LCDCLASS *m_lcd; |
ansond | 5:7b3bbd74c1b1 | 51 | char m_message[MAX_LOG_MESSAGE+1]; |
ansond | 0:906788c5813d | 52 | |
ansond | 0:906788c5813d | 53 | public: |
ansond | 5:7b3bbd74c1b1 | 54 | ErrorHandler(RawSerial *pc,LCDCLASS *lcd); |
ansond | 0:906788c5813d | 55 | virtual ~ErrorHandler(); |
ansond | 0:906788c5813d | 56 | |
ansond | 0:906788c5813d | 57 | void log(const char *format, ...); |
ansond | 6:be3ca195f0d1 | 58 | void logConsole(const char *format, ...); |
ansond | 0:906788c5813d | 59 | |
ansond | 0:906788c5813d | 60 | void turnLEDRed(); |
ansond | 0:906788c5813d | 61 | void turnLEDGreen(); |
ansond | 0:906788c5813d | 62 | void turnLEDBlue(); |
ansond | 0:906788c5813d | 63 | void turnLEDPurple(); |
ansond | 0:906788c5813d | 64 | void turnLEDBlack(); |
ansond | 0:906788c5813d | 65 | void turnLEDYellow(); |
ansond | 0:906788c5813d | 66 | void turnLEDOrange(); |
ansond | 0:906788c5813d | 67 | |
ansond | 1:8d42444464d3 | 68 | void blinkTransportTxLED(); |
ansond | 1:8d42444464d3 | 69 | void blinkTransportRxLED(); |
ansond | 1:8d42444464d3 | 70 | |
ansond | 0:906788c5813d | 71 | private: |
ansond | 0:906788c5813d | 72 | void setRGBLED(float H, float S, float V); |
ansond | 1:8d42444464d3 | 73 | void blinkLED(DigitalOut led); |
ansond | 0:906788c5813d | 74 | }; |
ansond | 0:906788c5813d | 75 | |
ansond | 0:906788c5813d | 76 | #endif // _ERROR_HANDLER_H_ |