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