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.
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 if(!uart.readable()) { 00030 return 0; 00031 } 00032 va_list argptr; 00033 va_start(argptr, format); 00034 00035 char line[200]; 00036 uart.gets(line, 200); 00037 line[199] = '\0'; 00038 00039 int read=0; 00040 00041 int start = 0; 00042 for (int i = 0; i < 10; i++) { 00043 if(strncmp("AAAAA", &line[i], 5) == 0) { 00044 start = i+5; 00045 } 00046 } 00047 char *clean = &line[start]; 00048 00049 int end = strlen(clean)-6; 00050 clean[end] = 0; 00051 00052 if(start < 1) { 00053 read = 0; 00054 } else { 00055 read = vsscanf(clean, format, argptr); 00056 } 00057 00058 va_end(argptr); 00059 return read; 00060 }
Generated on Sat Jul 16 2022 02:23:26 by
1.7.2