wifi test
Dependencies: X_NUCLEO_IKS01A2 mbed-http
easy-connect/wnc14a2a-driver/WNC14A2AInterface/WNCIO.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 WNCIO.h |
JMF | 0:24d3eb812fd4 | 23 | * @brief A class that WNCInterface uses for input/output |
JMF | 0:24d3eb812fd4 | 24 | * |
JMF | 0:24d3eb812fd4 | 25 | * @author James Flynn |
JMF | 0:24d3eb812fd4 | 26 | * |
JMF | 0:24d3eb812fd4 | 27 | * @date 1-Feb-2018 |
JMF | 0:24d3eb812fd4 | 28 | * |
JMF | 0:24d3eb812fd4 | 29 | */ |
JMF | 0:24d3eb812fd4 | 30 | |
JMF | 0:24d3eb812fd4 | 31 | #ifndef __WNCIO__ |
JMF | 0:24d3eb812fd4 | 32 | #define __WNCIO__ |
JMF | 0:24d3eb812fd4 | 33 | #include <stdio.h> |
JMF | 0:24d3eb812fd4 | 34 | #include "mbed.h" |
JMF | 0:24d3eb812fd4 | 35 | |
JMF | 0:24d3eb812fd4 | 36 | /** WncIO class |
JMF | 0:24d3eb812fd4 | 37 | * Used to read/write the WNC UART using FILE I/O. |
JMF | 0:24d3eb812fd4 | 38 | */ |
JMF | 0:24d3eb812fd4 | 39 | |
JMF | 0:24d3eb812fd4 | 40 | class WncIO |
JMF | 0:24d3eb812fd4 | 41 | { |
JMF | 0:24d3eb812fd4 | 42 | public: |
JMF | 0:24d3eb812fd4 | 43 | //! Create class with either stdio or a pointer to a uart |
JMF | 0:24d3eb812fd4 | 44 | WncIO( UARTSerial * uart): m_puart(uart) {;} |
JMF | 0:24d3eb812fd4 | 45 | ~WncIO() {}; |
JMF | 0:24d3eb812fd4 | 46 | |
JMF | 0:24d3eb812fd4 | 47 | //! standard printf() functionallity |
JMF | 0:24d3eb812fd4 | 48 | int printf( char * fmt, ...) { |
JMF | 0:24d3eb812fd4 | 49 | char buffer[256]; |
JMF | 0:24d3eb812fd4 | 50 | int ret=0; |
JMF | 0:24d3eb812fd4 | 51 | va_list args; |
JMF | 0:24d3eb812fd4 | 52 | va_start (args, fmt); |
JMF | 0:24d3eb812fd4 | 53 | vsnprintf(buffer, sizeof(buffer), fmt, args); |
JMF | 0:24d3eb812fd4 | 54 | prt.lock(); |
JMF | 0:24d3eb812fd4 | 55 | ret=m_puart->write(buffer,strlen(buffer)); |
JMF | 0:24d3eb812fd4 | 56 | prt.unlock(); |
JMF | 0:24d3eb812fd4 | 57 | va_end (args); |
JMF | 0:24d3eb812fd4 | 58 | return ret; |
JMF | 0:24d3eb812fd4 | 59 | } |
JMF | 0:24d3eb812fd4 | 60 | |
JMF | 0:24d3eb812fd4 | 61 | //! standard putc() functionallity |
JMF | 0:24d3eb812fd4 | 62 | int putc( int c ) { |
JMF | 0:24d3eb812fd4 | 63 | int ret=0; |
JMF | 0:24d3eb812fd4 | 64 | prt.lock(); |
JMF | 0:24d3eb812fd4 | 65 | ret=m_puart->write((const void*)&c,1); |
JMF | 0:24d3eb812fd4 | 66 | prt.unlock(); |
JMF | 0:24d3eb812fd4 | 67 | return ret; |
JMF | 0:24d3eb812fd4 | 68 | } |
JMF | 0:24d3eb812fd4 | 69 | |
JMF | 0:24d3eb812fd4 | 70 | //! standard puts() functionallity |
JMF | 0:24d3eb812fd4 | 71 | int puts( const char * str ) { |
JMF | 0:24d3eb812fd4 | 72 | int ret=0; |
JMF | 0:24d3eb812fd4 | 73 | prt.lock(); |
JMF | 0:24d3eb812fd4 | 74 | ret=m_puart->write(str,strlen(str)); |
JMF | 0:24d3eb812fd4 | 75 | prt.unlock(); |
JMF | 0:24d3eb812fd4 | 76 | return ret; |
JMF | 0:24d3eb812fd4 | 77 | } |
JMF | 0:24d3eb812fd4 | 78 | |
JMF | 0:24d3eb812fd4 | 79 | //! return true when data is available, false otherwise |
JMF | 0:24d3eb812fd4 | 80 | bool readable( void ) { |
JMF | 0:24d3eb812fd4 | 81 | return m_puart->readable(); |
JMF | 0:24d3eb812fd4 | 82 | } |
JMF | 0:24d3eb812fd4 | 83 | |
JMF | 0:24d3eb812fd4 | 84 | //! get the next character available from the uart |
JMF | 0:24d3eb812fd4 | 85 | int getc( void ) { |
JMF | 0:24d3eb812fd4 | 86 | char c; |
JMF | 0:24d3eb812fd4 | 87 | m_puart->read( &c, 1 ); |
JMF | 0:24d3eb812fd4 | 88 | return c; |
JMF | 0:24d3eb812fd4 | 89 | } |
JMF | 0:24d3eb812fd4 | 90 | |
JMF | 0:24d3eb812fd4 | 91 | //! set the uart baud rate |
JMF | 0:24d3eb812fd4 | 92 | void baud( int baud ) { |
JMF | 0:24d3eb812fd4 | 93 | m_puart->set_baud(baud); |
JMF | 0:24d3eb812fd4 | 94 | } |
JMF | 0:24d3eb812fd4 | 95 | |
JMF | 0:24d3eb812fd4 | 96 | private: |
JMF | 0:24d3eb812fd4 | 97 | UARTSerial *m_puart; |
JMF | 0:24d3eb812fd4 | 98 | Mutex prt; |
JMF | 0:24d3eb812fd4 | 99 | }; |
JMF | 0:24d3eb812fd4 | 100 | |
JMF | 0:24d3eb812fd4 | 101 | #endif |
JMF | 0:24d3eb812fd4 | 102 |