
wifi test
Dependencies: X_NUCLEO_IKS01A2 mbed-http
easy-connect/wnc14a2a-driver/WNC14A2AInterface/WNCDebug.h@0:24d3eb812fd4, 2018-09-05 (annotated)
- Committer:
- JMF
- Date:
- Wed Sep 05 14:28:24 2018 +0000
- Revision:
- 0:24d3eb812fd4
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:24d3eb812fd4 | 1 | /** |
JMF | 0:24d3eb812fd4 | 2 | * copyright (c) 2017-2018, James Flynn |
JMF | 0:24d3eb812fd4 | 3 | * SPDX-License-Identifier: Apache-2.0 |
JMF | 0:24d3eb812fd4 | 4 | */ |
JMF | 0:24d3eb812fd4 | 5 | |
JMF | 0:24d3eb812fd4 | 6 | /* |
JMF | 0:24d3eb812fd4 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
JMF | 0:24d3eb812fd4 | 8 | * you may not use this file except in compliance with the License. |
JMF | 0:24d3eb812fd4 | 9 | * You may obtain a copy of the License at |
JMF | 0:24d3eb812fd4 | 10 | * |
JMF | 0:24d3eb812fd4 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
JMF | 0:24d3eb812fd4 | 12 | * |
JMF | 0:24d3eb812fd4 | 13 | * Unless required by applicable law or agreed to in writing, software |
JMF | 0:24d3eb812fd4 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
JMF | 0:24d3eb812fd4 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JMF | 0:24d3eb812fd4 | 16 | * |
JMF | 0:24d3eb812fd4 | 17 | * See the License for the specific language governing permissions and |
JMF | 0:24d3eb812fd4 | 18 | * limitations under the License. |
JMF | 0:24d3eb812fd4 | 19 | */ |
JMF | 0:24d3eb812fd4 | 20 | |
JMF | 0:24d3eb812fd4 | 21 | /** |
JMF | 0:24d3eb812fd4 | 22 | * @file WNCDebug.h |
JMF | 0:24d3eb812fd4 | 23 | * @brief A debug class that coordinates the output of debug messages to |
JMF | 0:24d3eb812fd4 | 24 | * either stdio or a serial port based on instantiation. |
JMF | 0:24d3eb812fd4 | 25 | * |
JMF | 0:24d3eb812fd4 | 26 | * @author James Flynn |
JMF | 0:24d3eb812fd4 | 27 | * |
JMF | 0:24d3eb812fd4 | 28 | * @date 1-Feb-2018 |
JMF | 0:24d3eb812fd4 | 29 | * |
JMF | 0:24d3eb812fd4 | 30 | */ |
JMF | 0:24d3eb812fd4 | 31 | |
JMF | 0:24d3eb812fd4 | 32 | #ifndef __WNCDEBUG__ |
JMF | 0:24d3eb812fd4 | 33 | #define __WNCDEBUG__ |
JMF | 0:24d3eb812fd4 | 34 | #include <stdio.h> |
JMF | 0:24d3eb812fd4 | 35 | #include "WNCIO.h" |
JMF | 0:24d3eb812fd4 | 36 | |
JMF | 0:24d3eb812fd4 | 37 | /** WNCDebug class |
JMF | 0:24d3eb812fd4 | 38 | * Used to write debug data to the user designated IO. Currently |
JMF | 0:24d3eb812fd4 | 39 | * The class expects either a stdio element (defaults to stderr) or |
JMF | 0:24d3eb812fd4 | 40 | * a pointer to a WncIO object. |
JMF | 0:24d3eb812fd4 | 41 | */ |
JMF | 0:24d3eb812fd4 | 42 | |
JMF | 0:24d3eb812fd4 | 43 | class WNCDebug |
JMF | 0:24d3eb812fd4 | 44 | { |
JMF | 0:24d3eb812fd4 | 45 | public: |
JMF | 0:24d3eb812fd4 | 46 | //! Create class with either stdio or a pointer to a uart |
JMF | 0:24d3eb812fd4 | 47 | WNCDebug( FILE * fd = stderr ): m_puart(NULL) {m_stdiofp=fd;}; |
JMF | 0:24d3eb812fd4 | 48 | WNCDebug( WncIO * uart): m_stdiofp(NULL) {m_puart=uart;}; |
JMF | 0:24d3eb812fd4 | 49 | ~WNCDebug() {}; |
JMF | 0:24d3eb812fd4 | 50 | |
JMF | 0:24d3eb812fd4 | 51 | //! standard printf() functionallity |
JMF | 0:24d3eb812fd4 | 52 | int printf( char * fmt, ...) { |
JMF | 0:24d3eb812fd4 | 53 | char buffer[256]; |
JMF | 0:24d3eb812fd4 | 54 | int ret=0; |
JMF | 0:24d3eb812fd4 | 55 | va_list args; |
JMF | 0:24d3eb812fd4 | 56 | va_start (args, fmt); |
JMF | 0:24d3eb812fd4 | 57 | vsnprintf(buffer, sizeof(buffer), fmt, args); |
JMF | 0:24d3eb812fd4 | 58 | prt.lock(); |
JMF | 0:24d3eb812fd4 | 59 | if( m_stdiofp ) |
JMF | 0:24d3eb812fd4 | 60 | ret=fputs(buffer,m_stdiofp); |
JMF | 0:24d3eb812fd4 | 61 | else |
JMF | 0:24d3eb812fd4 | 62 | ret=m_puart->puts(buffer); |
JMF | 0:24d3eb812fd4 | 63 | prt.unlock(); |
JMF | 0:24d3eb812fd4 | 64 | va_end (args); |
JMF | 0:24d3eb812fd4 | 65 | return ret; |
JMF | 0:24d3eb812fd4 | 66 | } |
JMF | 0:24d3eb812fd4 | 67 | |
JMF | 0:24d3eb812fd4 | 68 | //! standard putc() functionallity |
JMF | 0:24d3eb812fd4 | 69 | int putc( int c ) { |
JMF | 0:24d3eb812fd4 | 70 | int ret=0; |
JMF | 0:24d3eb812fd4 | 71 | prt.lock(); |
JMF | 0:24d3eb812fd4 | 72 | if( m_stdiofp ) |
JMF | 0:24d3eb812fd4 | 73 | ret=fputc(c, m_stdiofp); |
JMF | 0:24d3eb812fd4 | 74 | else |
JMF | 0:24d3eb812fd4 | 75 | ret=m_puart->putc(c); |
JMF | 0:24d3eb812fd4 | 76 | prt.unlock(); |
JMF | 0:24d3eb812fd4 | 77 | return ret; |
JMF | 0:24d3eb812fd4 | 78 | } |
JMF | 0:24d3eb812fd4 | 79 | |
JMF | 0:24d3eb812fd4 | 80 | //! standard puts() functionallity |
JMF | 0:24d3eb812fd4 | 81 | int puts( const char * str ) { |
JMF | 0:24d3eb812fd4 | 82 | int ret=0; |
JMF | 0:24d3eb812fd4 | 83 | prt.lock(); |
JMF | 0:24d3eb812fd4 | 84 | if( m_stdiofp ) |
JMF | 0:24d3eb812fd4 | 85 | ret=fputs(str,m_stdiofp); |
JMF | 0:24d3eb812fd4 | 86 | else |
JMF | 0:24d3eb812fd4 | 87 | ret=m_puart->puts(str); |
JMF | 0:24d3eb812fd4 | 88 | prt.unlock(); |
JMF | 0:24d3eb812fd4 | 89 | return ret; |
JMF | 0:24d3eb812fd4 | 90 | } |
JMF | 0:24d3eb812fd4 | 91 | |
JMF | 0:24d3eb812fd4 | 92 | private: |
JMF | 0:24d3eb812fd4 | 93 | std::FILE *m_stdiofp; |
JMF | 0:24d3eb812fd4 | 94 | WncIO *m_puart; |
JMF | 0:24d3eb812fd4 | 95 | Mutex prt; |
JMF | 0:24d3eb812fd4 | 96 | }; |
JMF | 0:24d3eb812fd4 | 97 | |
JMF | 0:24d3eb812fd4 | 98 | #endif |
JMF | 0:24d3eb812fd4 | 99 |