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.
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include <vector> 00004 #include "sender.h" 00005 00006 #include "Receiver.h" 00007 #include "defines.h" 00008 00009 #include "CRC.h" 00010 00011 DigitalOut myled(LED1); 00012 00013 00014 DigitalOut MO(p22); 00015 Serial pc(USBTX, USBRX); 00016 00017 #ifndef TESTPERIOD 00018 const int us_period = 20; 00019 const int us_timeout = us_period * 5/4; 00020 const int us_prepare = us_period *3/4; 00021 #else 00022 int us_period = 100; 00023 #endif 00024 00025 00026 const unsigned char preamble_byte = 85; 00027 00028 const unsigned char STARTBYTE = 126; 00029 const unsigned char ENDBYTE = 126; 00030 00031 Sender manchesterSender; 00032 00033 void sendMessage() 00034 { 00035 unsigned char c = 0; 00036 vector<unsigned char> message; 00037 while ( c != '\n') 00038 { 00039 while(!pc.readable()) 00040 { 00041 Thread::wait(1); 00042 } 00043 c = pc.getc(); 00044 pc.printf("%c",c); 00045 message.push_back(c); 00046 } 00047 vector<unsigned char> trame = createFrame(message); 00048 00049 manchesterSender.sendMessage(trame); 00050 00051 } 00052 00053 00054 #ifdef TESTPERIOD 00055 const int testCount = 2000; 00056 void sendTestData() 00057 { 00058 vector<unsigned char> trame; 00059 00060 for(int i =0; i < testCount;i++) 00061 { 00062 trame.push_back(106); 00063 } 00064 manchesterSender.sendMessage(trame); 00065 } 00066 00067 int sendMain() 00068 { 00069 pc.printf("Start test"); 00070 int period; 00071 while(true) 00072 { 00073 pc.scanf("%i",&period); 00074 pc.printf("\n\nPeriod = %i\n",period); 00075 us_period = period; 00076 sendTestData(); 00077 } 00078 } 00079 int testMain() 00080 { 00081 ManchesterReceiver r; 00082 pc.printf("Start test"); 00083 int period; 00084 while(true) 00085 { 00086 pc.scanf("%i",&period); 00087 pc.printf("\n\nPeriod = %i\n",period); 00088 us_period = period; 00089 unsigned char val; 00090 bool fail = false; 00091 while(!r.getByte(val)) 00092 { } 00093 if(val!=106) 00094 { 00095 fail = true; 00096 pc.printf("Transmit error"); 00097 } 00098 for(int i = 1; i <testCount ; i++) 00099 { 00100 if(!r.getByte(val)){ 00101 pc.printf("transmitError"); 00102 fail = true; 00103 } 00104 if(val!=106){ 00105 pc.printf("WrongData"); 00106 fail = true; 00107 } 00108 } 00109 pc.printf("\n\nEnd Period = %i\n",period); 00110 } 00111 00112 } 00113 #endif 00114 00115 int consoleCommMain() { 00116 ManchesterReceiver r; 00117 00118 00119 00120 Callback<void()> cb(&r, &ManchesterReceiver::getMessages); 00121 Thread receiving(cb,osPriorityHigh); 00122 00123 pc.printf("\n******************\nStarting to listen\n"); 00124 00125 while(1) 00126 { 00127 sendMessage(); 00128 Thread::wait(1000); 00129 } 00130 } 00131 int sendMessageTest() 00132 { 00133 vector<unsigned char> trame; 00134 00135 for(int i =0; i < 5;i++) 00136 { 00137 trame.push_back(106); 00138 } 00139 00140 00141 trame = createFrame(trame); 00142 while(true) 00143 manchesterSender.sendMessage(trame); 00144 00145 return 0; 00146 } 00147 00148 00149 int main() 00150 { 00151 #ifndef TESTPERIOD 00152 return consoleCommMain(); 00153 #else 00154 return testMain(); 00155 #endif 00156 }
Generated on Tue Jul 12 2022 18:11:54 by
 1.7.2
 1.7.2