ryo seki / Mbed 2 deprecated serialSend5

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uart1.cpp Source File

uart1.cpp

00001 
00002 #include "mbed.h"
00003 #include "uart1.h"
00004 
00005 extern Serial device;
00006 extern BusOut mbedleds;
00007 //extern Serial pc;
00008 extern int direction;
00009 extern int Distance;
00010 extern int IR_found;
00011 extern int AveDistance;
00012 extern uint16_t ultrasonicVal[4];
00013 
00014 uint8_t xbee;
00015 uint8_t data[4];
00016 
00017 extern uint8_t data2[5];
00018 
00019 void dev_rx()
00020 {   
00021     static uint8_t count2 = 0;
00022     static uint8_t RecData[RECEIVE_DATA_NUM];
00023     
00024     
00025     
00026     RecData[count2] = device.getc();
00027     
00028     if(RecData[KEY2] == KEYCODE2){
00029     
00030         count2++;
00031     }else{
00032         count2 = 0;
00033     }
00034     if(count2 >= RECEIVE_DATA_NUM){
00035         if(RecData[CHECK2] == CHECKCODE2){
00036             //pc.printf("a");
00037             //mbedleds = 15;
00038             data[0] = RecData[DATA1];
00039             data[1] = RecData[DATA2];
00040             data[2] = RecData[DATA3];
00041             data[3] = RecData[DATA4];
00042             //pc.printf("%d\n",data[2]);
00043         }
00044         count2 = 0;
00045     }  
00046 }
00047 
00048 void dev_tx()
00049 {
00050     static uint8_t count = 0;
00051     static uint8_t SendData0[SEND_DATA_NUM];
00052     
00053     if(count >= SEND_DATA_NUM){
00054         xbee = data2[0];
00055         SendData0[KEY]      = KEYCODE;
00056         SendData0[DIRECTIONN] = direction;
00057         SendData0[DISTANCE] = AveDistance;
00058         SendData0[SONIC1_1] = ultrasonicVal[0];
00059         SendData0[SONIC1_2] = (ultrasonicVal[0] >> 8);
00060         SendData0[SONIC2_1] = ultrasonicVal[1];
00061         SendData0[SONIC2_2] = (ultrasonicVal[1] >> 8);
00062         SendData0[SONIC3_1] = ultrasonicVal[2];
00063         SendData0[SONIC3_2] = (ultrasonicVal[2] >> 8);
00064         SendData0[SONIC4_1] = ultrasonicVal[3];
00065         SendData0[SONIC4_2] = (ultrasonicVal[3] >> 8);
00066         SendData0[IR_FOUND] = IR_found;
00067         SendData0[XBEE]     = xbee;
00068         SendData0[CHECK]    = CHECKCODE;
00069         
00070         //pc.printf("%d\t%d\t%d\t%d\n",SendData0[DIRECTIONN],SendData0[DISTANCE],SendData0[IR_FOUND],SendData0[CHECK]);
00071         
00072         count = 0;
00073     }
00074     device.putc(SendData0[count]);
00075     
00076     count++;
00077 }