ATParser for EMW3162 wifi module

Dependents:   EMWConfig

Committer:
Maggie17
Date:
Wed Nov 02 03:38:46 2016 +0000
Revision:
0:1b9f0bcf0b2b
ATParse for EMW3162 wifi module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Maggie17 0:1b9f0bcf0b2b 1 /*
Maggie17 0:1b9f0bcf0b2b 2 * Copyright (c) 2014-2015 ARM Limited. All rights reserved.
Maggie17 0:1b9f0bcf0b2b 3 * SPDX-License-Identifier: Apache-2.0
Maggie17 0:1b9f0bcf0b2b 4 * Licensed under the Apache License, Version 2.0 (the License); you may
Maggie17 0:1b9f0bcf0b2b 5 * not use this file except in compliance with the License.
Maggie17 0:1b9f0bcf0b2b 6 * You may obtain a copy of the License at
Maggie17 0:1b9f0bcf0b2b 7 *
Maggie17 0:1b9f0bcf0b2b 8 * http://www.apache.org/licenses/LICENSE-2.0
Maggie17 0:1b9f0bcf0b2b 9 *
Maggie17 0:1b9f0bcf0b2b 10 * Unless required by applicable law or agreed to in writing, software
Maggie17 0:1b9f0bcf0b2b 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Maggie17 0:1b9f0bcf0b2b 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Maggie17 0:1b9f0bcf0b2b 13 * See the License for the specific language governing permissions and
Maggie17 0:1b9f0bcf0b2b 14 * limitations under the License.
Maggie17 0:1b9f0bcf0b2b 15 */
Maggie17 0:1b9f0bcf0b2b 16
Maggie17 0:1b9f0bcf0b2b 17 #include <stdarg.h>
Maggie17 0:1b9f0bcf0b2b 18 #include <stdint.h>
Maggie17 0:1b9f0bcf0b2b 19 #include <stdio.h>
Maggie17 0:1b9f0bcf0b2b 20 #include <string.h>
Maggie17 0:1b9f0bcf0b2b 21
Maggie17 0:1b9f0bcf0b2b 22 #include "mbed_error.h"
Maggie17 0:1b9f0bcf0b2b 23
Maggie17 0:1b9f0bcf0b2b 24 size_t BufferedSerialThunk(void *buf_serial, const void *s, size_t length);
Maggie17 0:1b9f0bcf0b2b 25
Maggie17 0:1b9f0bcf0b2b 26 int BufferedPrintfC(void *stream, int size, const char* format, va_list arg)
Maggie17 0:1b9f0bcf0b2b 27 {
Maggie17 0:1b9f0bcf0b2b 28 int r;
Maggie17 0:1b9f0bcf0b2b 29 char buffer[512];
Maggie17 0:1b9f0bcf0b2b 30 if (size >= 512) {
Maggie17 0:1b9f0bcf0b2b 31 return -1;
Maggie17 0:1b9f0bcf0b2b 32 }
Maggie17 0:1b9f0bcf0b2b 33 memset(buffer, 0, size);
Maggie17 0:1b9f0bcf0b2b 34 r = vsprintf(buffer, format, arg);
Maggie17 0:1b9f0bcf0b2b 35 // this may not hit the heap but should alert the user anyways
Maggie17 0:1b9f0bcf0b2b 36 if(r > (int32_t) size) {
Maggie17 0:1b9f0bcf0b2b 37 error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__, size, r);
Maggie17 0:1b9f0bcf0b2b 38 return 0;
Maggie17 0:1b9f0bcf0b2b 39 }
Maggie17 0:1b9f0bcf0b2b 40 if ( r > 0 ) {
Maggie17 0:1b9f0bcf0b2b 41 BufferedSerialThunk(stream, buffer, r);
Maggie17 0:1b9f0bcf0b2b 42 }
Maggie17 0:1b9f0bcf0b2b 43 return r;
Maggie17 0:1b9f0bcf0b2b 44 }