C'est le projet bro
Embed:
(wiki syntax)
Show/hide line numbers
DO.cpp
00001 #include "rtos.h" 00002 #include "mbed.h" 00003 #include "DO.h" 00004 #include "config.h" 00005 00006 Queue <void,16> queueBitReception; 00007 Queue <char,16> queueCharReception; 00008 extern Serial pc; 00009 00010 Timer timer; 00011 00012 void receiveChar() 00013 { 00014 char res; 00015 while(1) { 00016 res=0x00; 00017 for(int i =0; i<8; i++) { 00018 osEvent evt = queueBitReception.get(); 00019 if(evt.status == osEventMessage) { 00020 res = res | (((char)evt.value.p)<<i); 00021 } 00022 } 00023 queueCharReception.put((char*)res); 00024 } 00025 00026 } 00027 00028 void receiveBit() 00029 { 00030 timer.start(); 00031 int oldTime; 00032 bool bitType=false; 00033 oldTime = timer.read_ms(); 00034 while(1) { 00035 Thread::signal_wait(0x01); 00036 if(timer.read_ms()-oldTime<(T-(T*0.15))*1000){ 00037 Thread::signal_wait(0x01); 00038 } 00039 else { 00040 bitType=!bitType; 00041 } 00042 if(bitType) { 00043 pc.putc(0x31); 00044 queueBitReception.put((void*)0x01); 00045 } else { 00046 pc.putc(0x30); 00047 queueBitReception.put((void*)0x00); 00048 } 00049 oldTime=timer.read_ms(); 00050 } 00051 } 00052 00053 00054 char calcCRC16(char* trame) 00055 { 00056 char length = trame[2]; 00057 int CRC16 = 0xFFFF; 00058 for(char i =0x00; i<length; i++) { 00059 CRC16 = CRC16 ^ trame[3+i]; 00060 for(int j = 0 ; j<8 ; j++) { 00061 if((CRC16 & 0x1)==0x01) { 00062 CRC16 = CRC16/2 ^ 0xA001; 00063 } else { 00064 CRC16 = CRC16/2; 00065 } 00066 } 00067 } 00068 return CRC16 & 0x00FF ; 00069 } 00070 00071 00072 void receiveData() 00073 { 00074 osEvent evt; 00075 char reception; 00076 while(1) { 00077 evt = queueCharReception.get(); 00078 if(evt.status == osEventMessage) { 00079 reception = (char)evt.value.p; 00080 if(reception == START) { 00081 do { 00082 evt = queueCharReception.get(); 00083 if(evt.status == osEventMessage) { 00084 reception = (char)evt.value.p; 00085 pc.putc(reception); 00086 } 00087 }while(reception!=STOP); 00088 } 00089 } 00090 } 00091 }
Generated on Wed Jul 13 2022 06:55:34 by
1.7.2