IRC Helicopter "HonyBee" Propo decode test program
これは、赤外線コントロールヘリコプター"HonyBee"のPropoからの送信データを解析して、PCに表示させるテストプログラムです。 詳しくは、 http://suupen-make.blogspot.jp/2013/06/irc-helicopter-honybeembedtest-program.html を参照してください。
Diff: main.cpp
- Revision:
- 0:f9e49220c97a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jun 23 07:28:06 2013 +0000 @@ -0,0 +1,189 @@ +/** + * HonyBee Propo Decode test program + * 130623 + * + * Writer:suupen + * + * <circuit diagram> + * VU(mbed) + * | + * |Vcc + * --- (PL-IRM2161) IR Reciver + * | |Vout + * | |--- p5(mbed) + * | | + * --- + * |GND + * | + * GND(mbed) + * + * <PC termnal soft> + * tera term + * baudrate:38400[bps] + * data:8[bit] + * parity:none + * stopbit:1[bit] + */ + + +//#define PROPO_RAW_DATA // ari: zyusin data hyoji nasi:HonyBee kaiseki data hyoji +//#define HONYBEE_NORMALIZE // ari: HonyBee data seikika hyoji nasi: HonyBee data tujyo hyoji + +#include "mbed.h" +#include "ReceiverIR.h" + +#ifndef PROPO_RAW_DATA +#include "CodecHonyBee.h" +#include "DecodeHonyBee.h" +#endif // PROPO_RAW_DATA + +void display_format(RemoteIR::Format format); +void display_binary(uint8_t *buf, uint8_t cnt); + +Serial pc(USBTX,USBRX); + + +ReceiverIR ir_rx(p5); + +RemoteIR::Format format; + +#ifndef PROPO_RAW_DATA +DecodeHonyBee HonyBee; +CodecHonyBee::honyBeePropo_t HonyBeeData; + +#ifdef HONYBEE_NORMALIZE +CodecHonyBee::normalizePropo_t normalize; +#endif // HONYBEE_NORMALIZE + +#endif // PROPO_RAW_DATA + + +uint8_t buf[32]; +int bitcount; + +DigitalOut myled(LED1); +DigitalOut led2(LED2); +DigitalIn irtest(p20); + + +int main(){ + pc.baud(38400); + while(1){ + + myled =~myled; + led2 = irtest; + + + + #ifdef PROPO_RAW_DATA + if (ir_rx.getState() == ReceiverIR::Received) { + bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); + + display_format(format); + display_binary(buf, ((bitcount + 7) / 8)); + } + else{ +#if 0 + switch(ir_rx.getState()){ + + case ReceiverIR::Idle: + printf("Idele\n"); + break; + case ReceiverIR::Receiving: + printf("Receiveing\n"); + break; + case ReceiverIR::Received: + printf("Received\n"); + break; + } +#endif + } +#endif // PROPO_RAW_DATA + +#ifndef PROPO_RAW_DATA + if (ir_rx.getState() == ReceiverIR::Received) { + bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); +#ifdef HONYBEE_NORMALIZE + bool ans = HonyBee.normalize(buf, &normalize); + if(ans == true){ + printf("count = %02x band = %1d slottle = %f trim = %f ladder = %f elevator = %f\n",normalize.count,normalize.band,normalize.slottle,normalize.trim,normalize.ladder, normalize.elevator); + } + else{ + printf("NG\n"); + } +#else // ~HONYBEE_NORMALIZE + bool ans = HonyBee.decode(buf, &HonyBeeData); + if(ans == true){ + printf("count = %02x band = %02x slottle = %03d trim = %03d ladder = %03d \n",HonyBeeData.count,HonyBeeData.band,HonyBeeData.slottle,HonyBeeData.trim,HonyBeeData.ladder); + } + else{ + printf("NG\n"); + } +#endif// HONYBEE_NORMALIZE + + } +#endif // PROPO_RAW_DATA + + } + +} + +/** + * Display a format of a data. + */ +void display_format(RemoteIR::Format format) { + switch (format) { + case RemoteIR::UNKNOWN: + pc.printf("????????"); + break; + case RemoteIR::NEC: + pc.printf("NEC "); + break; + case RemoteIR::NEC_REPEAT: + pc.printf("NEC (R)"); + break; + case RemoteIR::AEHA: + pc.printf("AEHA "); + break; + case RemoteIR::AEHA_REPEAT: + pc.printf("AEHA (R)"); + break; + case RemoteIR::SONY: //HONEY_BEE: + pc.printf("SONY or HONEY_BEE "); + break; + +#ifdef Swift_PROTCOL + case RemoteIR::Swift: + pc.printf("Swift "); + break; +#endif // Swift_PROPO + default: + pc.printf("unknown "); + break; + } +} + +void display_binary(uint8_t *buf, uint8_t cnt){ + uint8_t i; + uint8_t bitcnt; + uint8_t dat; + uint16_t checkbit; + + for(i = 0; i < cnt; i++){ + checkbit = 0x0080; + dat = *(buf + i); + printf("%02x:",dat); + for(bitcnt = 0; bitcnt < 8; bitcnt++){ + if( checkbit & dat){printf("1");} + else {printf("0");} + + checkbit = checkbit >> 1; + if(bitcnt == 3){printf(" ");} + } + printf(" "); + } + printf("\n"); +} + + +