Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of AEB by
BBSerial.cpp
00001 #include "BBSerial.h" 00002 00003 #include "stdio.h" 00004 00005 BBSerial::BBSerial() : 00006 uart(PTC17, PTC16) // tx, rx of uart3 00007 { 00008 uart.baud(9600); 00009 uart.format(8, SerialBase::Odd, 2); 00010 } 00011 00012 00013 void BBSerial::printf(const char* format, ...) { 00014 va_list argptr; 00015 va_start(argptr, format); 00016 00017 char newFormat[200]; 00018 00019 // Add garbage and header in order to resolve first byte error 00020 sprintf(newFormat, "GARBAGEAAAAA%sZZZZZ\n", format); 00021 char buf[200]; 00022 vsprintf(buf, newFormat, argptr); 00023 uart.printf("%s", buf); 00024 00025 va_end(argptr); 00026 } 00027 00028 int BBSerial::scanf(const char* format, ...) { 00029 va_list argptr; 00030 va_start(argptr, format); 00031 00032 char line[200]; 00033 uart.gets(line, 200); 00034 line[199] = '\0'; 00035 00036 int read=0; 00037 00038 int start = 0; 00039 for (int i = 0; i < 10; i++) { 00040 if(strncmp("AAAAA", &line[i], 5) == 0) { 00041 start = i+5; 00042 } 00043 } 00044 char *clean = &line[start]; 00045 00046 int end = strlen(clean)-6; 00047 clean[end] = 0; 00048 00049 if(start < 1) { 00050 read = 0; 00051 } else { 00052 read = vsscanf(clean, format, argptr); 00053 } 00054 00055 va_end(argptr); 00056 return read; 00057 }
Generated on Sun Jul 17 2022 12:07:24 by
1.7.2
