PLANET-Q ES920LR Library

Dependents:   IZU2020_GROUND_STATION IZU2020_AVIONICS IZU2020_AVIONICS

Committer:
tanahashi
Date:
Tue Dec 17 09:06:01 2019 +0000
Revision:
0:064d3711be83
Child:
1:a5114a32febe
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tanahashi 0:064d3711be83 1 #include "mbed.h"
tanahashi 0:064d3711be83 2 #include "PQES920LR.h"
tanahashi 0:064d3711be83 3
tanahashi 0:064d3711be83 4 ES920LR::ES920LR(Serial &serial)
tanahashi 0:064d3711be83 5 {
tanahashi 0:064d3711be83 6 _serial = &serial;
tanahashi 0:064d3711be83 7 _serial->attach(callback(this, &ES920LR::receive), Serial::RxIrq);
tanahashi 0:064d3711be83 8 memset(tx_buf, '\0', 52);
tanahashi 0:064d3711be83 9 memset(rx_buf, '\0', 52);
tanahashi 0:064d3711be83 10 index = 0;
tanahashi 0:064d3711be83 11 flag = 0;
tanahashi 0:064d3711be83 12 response = false;
tanahashi 0:064d3711be83 13 }
tanahashi 0:064d3711be83 14
tanahashi 0:064d3711be83 15 void ES920LR::send(char *data, int size)
tanahashi 0:064d3711be83 16 {
tanahashi 0:064d3711be83 17 if(size > 50) {
tanahashi 0:064d3711be83 18 size = 50;
tanahashi 0:064d3711be83 19 }
tanahashi 0:064d3711be83 20
tanahashi 0:064d3711be83 21 tx_buf[0] = size;
tanahashi 0:064d3711be83 22 for(int i = 0; i < size; i++) {
tanahashi 0:064d3711be83 23 tx_buf[1 + i] = data[i];
tanahashi 0:064d3711be83 24 }
tanahashi 0:064d3711be83 25 for (int i = 0; i < 1 + size; i++) {
tanahashi 0:064d3711be83 26 _serial->putc(tx_buf[i]);
tanahashi 0:064d3711be83 27 }
tanahashi 0:064d3711be83 28
tanahashi 0:064d3711be83 29 flag = 0;
tanahashi 0:064d3711be83 30 response = true;
tanahashi 0:064d3711be83 31 }
tanahashi 0:064d3711be83 32
tanahashi 0:064d3711be83 33 void ES920LR::attach(void(*func_ptr)(char*))
tanahashi 0:064d3711be83 34 {
tanahashi 0:064d3711be83 35 func = func_ptr;
tanahashi 0:064d3711be83 36 }
tanahashi 0:064d3711be83 37
tanahashi 0:064d3711be83 38 void ES920LR::receive()
tanahashi 0:064d3711be83 39 {
tanahashi 0:064d3711be83 40 if(flag == 0) {
tanahashi 0:064d3711be83 41 rx_size = _serial->getc();
tanahashi 0:064d3711be83 42 memset(rx_buf, '\0', 52);
tanahashi 0:064d3711be83 43 index = 0;
tanahashi 0:064d3711be83 44 flag = 1;
tanahashi 0:064d3711be83 45 }
tanahashi 0:064d3711be83 46 if(flag == 1) {
tanahashi 0:064d3711be83 47 rx_buf[index] = _serial->getc();
tanahashi 0:064d3711be83 48 if(index == rx_size - 1) {
tanahashi 0:064d3711be83 49 if(!response) {
tanahashi 0:064d3711be83 50 if(func != NULL) {
tanahashi 0:064d3711be83 51 (*func)(rx_buf);
tanahashi 0:064d3711be83 52 }
tanahashi 0:064d3711be83 53 } else {
tanahashi 0:064d3711be83 54 response = false;
tanahashi 0:064d3711be83 55 }
tanahashi 0:064d3711be83 56 flag = 0;
tanahashi 0:064d3711be83 57 } else {
tanahashi 0:064d3711be83 58 index ++;
tanahashi 0:064d3711be83 59 }
tanahashi 0:064d3711be83 60 }
tanahashi 0:064d3711be83 61
tanahashi 0:064d3711be83 62 }