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.
Fork of FBRDash by
PCComms.cpp
00001 #include "PCComms.h" 00002 #include "mbed.h" 00003 #include "State.h" 00004 00005 #define BUFFER_LENGTH 10 00006 00007 PCComms::PCComms(State* _values) : Comms(_values) 00008 { 00009 pc = new Serial(USBTX, USBRX); 00010 00011 pc->attach(this, &PCComms::receive, Serial::RxIrq); 00012 } 00013 00014 void PCComms::send(char message) 00015 { 00016 pc->putc(message); 00017 } 00018 00019 void PCComms::receive() 00020 { 00021 unsigned char packet_id; 00022 unsigned char data_length; 00023 00024 unsigned char buffer[BUFFER_LENGTH]; 00025 00026 int i; 00027 00028 if(pc->readable()) 00029 { 00030 if(pc->getc() == 0xFF && pc->getc() == 0xFF) //Handshake(ish) 00031 { 00032 packet_id = pc->getc(); 00033 data_length = pc->getc(); 00034 00035 for(i = 0; i < data_length && i < BUFFER_LENGTH; i++) 00036 { 00037 buffer[i] = pc->getc(); 00038 } 00039 00040 process_packet(packet_id, data_length, buffer); 00041 } 00042 } 00043 }
Generated on Wed Jul 13 2022 14:23:01 by
1.7.2
