MBSD / Mbed 2 deprecated AEB_TERATERM

Dependencies:   mbed

Fork of AEB by Vincenzo Comito

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BBSerial.cpp Source File

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 }