ryo seki / Mbed 2 deprecated serialSend5_5

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 int irDistance[6];
00017 
00018 extern uint8_t data2[5];
00019 
00020 void dev_rx()
00021 {   
00022     static uint8_t count2 = 0;
00023     static uint8_t RecData[RECEIVE_DATA_NUM];
00024     
00025     RecData[count2] = device.getc();
00026     
00027     if(RecData[KEY2] == KEYCODE2){
00028         count2++;
00029     }else{
00030         count2 = 0;
00031     }
00032     if(count2 >= RECEIVE_DATA_NUM){
00033         if(RecData[CHECK2] == CHECKCODE2){
00034             //mbedleds = 15;
00035             data[0] = RecData[DATA1];
00036             data[1] = RecData[DATA2];
00037             data[2] = RecData[DATA3];
00038             data[3] = RecData[DATA4];
00039             irDistance[0] = (RecData[DISTANCE1] << 8) + RecData[DISTANCE1_2];
00040             irDistance[1] = (RecData[DISTANCE2] << 8) + RecData[DISTANCE2_2];
00041             irDistance[2] = (RecData[DISTANCE3] << 8) + RecData[DISTANCE3_2];
00042             irDistance[3] = (RecData[DISTANCE4] << 8) + RecData[DISTANCE4_2];
00043             irDistance[4] = (RecData[DISTANCE5] << 8) + RecData[DISTANCE5_2];
00044             irDistance[5] = (RecData[DISTANCE6] << 8) + RecData[DISTANCE6_2];
00045             //pc.printf("%d\n",data[2]);
00046         }
00047         count2 = 0;
00048     }  
00049 }
00050 
00051 void dev_tx()
00052 {
00053     static uint8_t count = 0;
00054     static uint8_t SendData0[SEND_DATA_NUM];
00055     
00056     if(count >= SEND_DATA_NUM){
00057         xbee = data2[0];
00058         SendData0[KEY]      = KEYCODE;
00059         SendData0[DIRECTIONN] = direction;
00060         SendData0[DISTANCE] = AveDistance;
00061         SendData0[SONIC1_1] = ultrasonicVal[0];
00062         SendData0[SONIC1_2] = (ultrasonicVal[0] >> 8);
00063         SendData0[SONIC2_1] = ultrasonicVal[1];
00064         SendData0[SONIC2_2] = (ultrasonicVal[1] >> 8);
00065         SendData0[SONIC3_1] = ultrasonicVal[2];
00066         SendData0[SONIC3_2] = (ultrasonicVal[2] >> 8);
00067         SendData0[SONIC4_1] = ultrasonicVal[3];
00068         SendData0[SONIC4_2] = (ultrasonicVal[3] >> 8);
00069         SendData0[IR_FOUND] = IR_found;
00070         SendData0[XBEE]     = xbee;
00071         SendData0[CHECK]    = CHECKCODE;
00072         
00073         //pc.printf("%d\t%d\t%d\t%d\n",SendData0[DIRECTIONN],SendData0[DISTANCE],SendData0[IR_FOUND],SendData0[CHECK]);
00074         
00075         count = 0;
00076     }
00077     device.putc(SendData0[count]);
00078     
00079     count++;
00080 }