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.
Dependents: IZU2020_GROUND_STATION IZU2020_AVIONICS IZU2020_AVIONICS
PQES920LR.cpp
00001 #include "mbed.h" 00002 #include "PQES920LR.h" 00003 00004 ES920LR::ES920LR (Serial &serial) 00005 { 00006 _serial = &serial; 00007 _serial->attach(callback(this, &ES920LR::receive), Serial::RxIrq); 00008 memset(tx_buf, '\0', 52); 00009 memset(rx_buf, '\0', 52); 00010 index = 0; 00011 flag = 0; 00012 response = false; 00013 } 00014 00015 void ES920LR::send (char *data, int size) 00016 { 00017 if(size > 50) { 00018 size = 50; 00019 } 00020 00021 tx_buf[0] = size; 00022 for(int i = 0; i < size; i++) { 00023 tx_buf[1 + i] = data[i]; 00024 } 00025 for (int i = 0; i < 1 + size; i++) { 00026 _serial->putc(tx_buf[i]); 00027 } 00028 00029 flag = 0; 00030 response = true; 00031 } 00032 00033 void ES920LR::attach (void(*func_ptr)(char*)) 00034 { 00035 func = func_ptr; 00036 } 00037 00038 void ES920LR::receive() 00039 { 00040 if(flag == 0) { 00041 rx_size = _serial->getc(); 00042 memset(rx_buf, '\0', 52); 00043 index = 0; 00044 flag = 1; 00045 } 00046 if(flag == 1) { 00047 rx_buf[index] = _serial->getc(); 00048 if(index == rx_size - 1) { 00049 if(!response) { 00050 if(func != NULL) { 00051 (*func)(rx_buf); 00052 } 00053 } else { 00054 response = false; 00055 } 00056 flag = 0; 00057 } else { 00058 index ++; 00059 } 00060 } 00061 00062 }
Generated on Wed Jul 13 2022 11:31:18 by
1.7.2