![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
明石高専ロボ研 mbedライブラリ
Dependencies: mbed
Diff: scrp_slave.cpp
- Revision:
- 7:4ad54efe2fdd
- Parent:
- 5:a7894e6982ea
- Child:
- 8:82727add54ce
diff -r 678c6b604ac7 -r 4ad54efe2fdd scrp_slave.cpp --- a/scrp_slave.cpp Thu Nov 12 16:44:10 2020 +0000 +++ b/scrp_slave.cpp Sun Dec 06 08:09:01 2020 +0000 @@ -3,33 +3,37 @@ #define STX 0x41 #define DMY 0xff -ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,uint32_t addr):address_(addr){ +ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,uint32_t addr) + :port1(TX1,RX1,115200),port2(port1),address_(addr){ mode_ = 0; - init(TX1,RX1); + init(); } -ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,uint32_t addr):address_(addr){ +ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,uint32_t addr) + :port1(TX1,RX1,115200),port2(port1),address_(addr){ mode_ = 1; rede_ = new DigitalOut(REDE1,0); - init(TX1,RX1); + init(); } -ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,PinName TX2,PinName RX2,uint32_t addr):address_(addr){ +ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,PinName TX2,PinName RX2,uint32_t addr) + :port1(TX1,RX1,115200),port2(TX2,RX2,115200),address_(addr){ mode_ = 2; - serial_[1] = new Serial(TX2,RX2,115200); - serial_[1]->attach(callback(this,&ScrpSlave::port2),Serial::RxIrq); - init(TX1,RX1); + serial_[1] = &port2; + serial_[1]->attach(callback(this,&ScrpSlave::receive2),Serial::RxIrq); + init(); } -ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,PinName TX2,PinName RX2,uint32_t addr):address_(addr){ +ScrpSlave::ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,PinName TX2,PinName RX2,uint32_t addr) + :port1(TX1,RX1,115200),port2(TX2,RX2,115200),address_(addr){ mode_ = 3; rede_ = new DigitalOut(REDE1,0); - serial_[1] = new Serial(TX2,RX2,115200); - serial_[1]->attach(callback(this,&ScrpSlave::port2),Serial::RxIrq); - init(TX1,RX1); + serial_[1] = &port2; + serial_[1]->attach(callback(this,&ScrpSlave::receive2),Serial::RxIrq); + init(); } -void ScrpSlave::init(PinName TX,PinName RX){ +void ScrpSlave::init(){ for(int i = 0;i<2;i++){ wait_data_[i] = false; stx_flag_[i] = false; @@ -39,8 +43,8 @@ for(int i = 1;i<256;++i){ procs_[i] = NULL; } - serial_[0] = new Serial(TX,RX,115200); - serial_[0]->attach(callback(this,&ScrpSlave::port1),Serial::RxIrq); + serial_[0] = &port1; + serial_[0]->attach(callback(this,&ScrpSlave::receive1),Serial::RxIrq); if(address_ < 255){ my_id_ = address_; return; @@ -58,11 +62,11 @@ } } -void ScrpSlave::port1(){ +void ScrpSlave::receive1(){ check(0); } -void ScrpSlave::port2(){ +void ScrpSlave::receive2(){ check(1); } @@ -239,12 +243,8 @@ } ScrpSlave::~ScrpSlave(){ - delete serial_[0]; delete flash_; if(mode_%2 == 1){ delete rede_; } - if(mode_ >= 2){ - delete serial_[1]; - } } \ No newline at end of file