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