Kiyoshi Hayakawa
/
lux-1data-Xbee-API
KEIS
main.cpp@0:acb42df924ce, 2013-10-02 (annotated)
- Committer:
- khayakawa
- Date:
- Wed Oct 02 03:53:32 2013 +0000
- Revision:
- 0:acb42df924ce
KEIS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
khayakawa | 0:acb42df924ce | 1 | /* PC=router divce, mbed=cordinator */ |
khayakawa | 0:acb42df924ce | 2 | /* */ |
khayakawa | 0:acb42df924ce | 3 | /* */ |
khayakawa | 0:acb42df924ce | 4 | |
khayakawa | 0:acb42df924ce | 5 | #include "mbed.h" |
khayakawa | 0:acb42df924ce | 6 | #include "C12832_lcd.h" |
khayakawa | 0:acb42df924ce | 7 | |
khayakawa | 0:acb42df924ce | 8 | Serial pc(USBTX, USBRX); // tx, rx |
khayakawa | 0:acb42df924ce | 9 | Serial device(p9, p10); // tx, rx |
khayakawa | 0:acb42df924ce | 10 | C12832_LCD lcd; |
khayakawa | 0:acb42df924ce | 11 | DigitalOut myled(LED1); |
khayakawa | 0:acb42df924ce | 12 | DigitalIn fire(p14); |
khayakawa | 0:acb42df924ce | 13 | int pkt_phase=0; |
khayakawa | 0:acb42df924ce | 14 | int pkt_count=0; |
khayakawa | 0:acb42df924ce | 15 | char* ch[16]={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}; |
khayakawa | 0:acb42df924ce | 16 | char v_val[2]; |
khayakawa | 0:acb42df924ce | 17 | int num_Xbee=0; |
khayakawa | 0:acb42df924ce | 18 | |
khayakawa | 0:acb42df924ce | 19 | void dev_rx () { |
khayakawa | 0:acb42df924ce | 20 | char val; |
khayakawa | 0:acb42df924ce | 21 | int tmp1,tmp2; |
khayakawa | 0:acb42df924ce | 22 | |
khayakawa | 0:acb42df924ce | 23 | myled=1; |
khayakawa | 0:acb42df924ce | 24 | val=device.getc(); |
khayakawa | 0:acb42df924ce | 25 | pkt_count++; |
khayakawa | 0:acb42df924ce | 26 | if(pkt_phase==0 && val==0x7E){ |
khayakawa | 0:acb42df924ce | 27 | pkt_phase=1; |
khayakawa | 0:acb42df924ce | 28 | pkt_count=1; |
khayakawa | 0:acb42df924ce | 29 | } |
khayakawa | 0:acb42df924ce | 30 | |
khayakawa | 0:acb42df924ce | 31 | if(pkt_phase==1 && pkt_count==4){ |
khayakawa | 0:acb42df924ce | 32 | if( val==0x92 ){ |
khayakawa | 0:acb42df924ce | 33 | pkt_phase=2; |
khayakawa | 0:acb42df924ce | 34 | }else{ |
khayakawa | 0:acb42df924ce | 35 | pkt_count=0; |
khayakawa | 0:acb42df924ce | 36 | pkt_phase=0; |
khayakawa | 0:acb42df924ce | 37 | } |
khayakawa | 0:acb42df924ce | 38 | } |
khayakawa | 0:acb42df924ce | 39 | |
khayakawa | 0:acb42df924ce | 40 | if(pkt_phase==2 && pkt_count==12){ |
khayakawa | 0:acb42df924ce | 41 | if( val==0x77){ |
khayakawa | 0:acb42df924ce | 42 | pkt_phase=3; |
khayakawa | 0:acb42df924ce | 43 | }else{ |
khayakawa | 0:acb42df924ce | 44 | pkt_count=0; |
khayakawa | 0:acb42df924ce | 45 | pkt_phase=0; |
khayakawa | 0:acb42df924ce | 46 | } |
khayakawa | 0:acb42df924ce | 47 | } |
khayakawa | 0:acb42df924ce | 48 | |
khayakawa | 0:acb42df924ce | 49 | if(pkt_phase==3 && pkt_count==22){ |
khayakawa | 0:acb42df924ce | 50 | pkt_phase=4; |
khayakawa | 0:acb42df924ce | 51 | v_val[0]=val; |
khayakawa | 0:acb42df924ce | 52 | } |
khayakawa | 0:acb42df924ce | 53 | |
khayakawa | 0:acb42df924ce | 54 | if(pkt_phase==4 && pkt_count==23){ |
khayakawa | 0:acb42df924ce | 55 | pkt_phase=0; |
khayakawa | 0:acb42df924ce | 56 | pkt_count=0; |
khayakawa | 0:acb42df924ce | 57 | v_val[1]=val; |
khayakawa | 0:acb42df924ce | 58 | lcd.locate(0,3); |
khayakawa | 0:acb42df924ce | 59 | lcd.printf("v_val1:%x%x ",v_val[0],v_val[1]); |
khayakawa | 0:acb42df924ce | 60 | } |
khayakawa | 0:acb42df924ce | 61 | |
khayakawa | 0:acb42df924ce | 62 | |
khayakawa | 0:acb42df924ce | 63 | tmp1 = val/16; |
khayakawa | 0:acb42df924ce | 64 | tmp2 = val%16; |
khayakawa | 0:acb42df924ce | 65 | pc.printf("%s%s",ch[tmp1],ch[tmp2]); |
khayakawa | 0:acb42df924ce | 66 | //wait(.2); |
khayakawa | 0:acb42df924ce | 67 | myled=0; |
khayakawa | 0:acb42df924ce | 68 | |
khayakawa | 0:acb42df924ce | 69 | |
khayakawa | 0:acb42df924ce | 70 | } |
khayakawa | 0:acb42df924ce | 71 | |
khayakawa | 0:acb42df924ce | 72 | int main() { |
khayakawa | 0:acb42df924ce | 73 | |
khayakawa | 0:acb42df924ce | 74 | lcd.cls(); |
khayakawa | 0:acb42df924ce | 75 | lcd.locate(0,0); |
khayakawa | 0:acb42df924ce | 76 | myled=0; |
khayakawa | 0:acb42df924ce | 77 | |
khayakawa | 0:acb42df924ce | 78 | // int sd_data_on[20]={0x7E,0x00,0x10,0x17,0x01,0x00,0x13,0xA2,0x00,0x40,0x92,0xFF,0x77,0xFF,0xFE,0x02,0x44,0x32,0x05,0x70}; |
khayakawa | 0:acb42df924ce | 79 | // int sd_data_off[20]={0x7E,0x00,0x10,0x17,0x01,0x00,0x13,0xA2,0x00,0x40,0x92,0xFF,0x77,0xFF,0xFE,0x02,0x44,0x32,0x04,0x71}; |
khayakawa | 0:acb42df924ce | 80 | |
khayakawa | 0:acb42df924ce | 81 | device.attach(&dev_rx, Serial::RxIrq); |
khayakawa | 0:acb42df924ce | 82 | |
khayakawa | 0:acb42df924ce | 83 | |
khayakawa | 0:acb42df924ce | 84 | |
khayakawa | 0:acb42df924ce | 85 | } |