Library to control the mp3-tf-16p

Dependents:   LaserSensor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LAS_TB.cpp Source File

LAS_TB.cpp

00001 #include "mbed.h"
00002 #include "LAS_TB.h"
00003 
00004 LAS_TB::LAS_TB(PinName PinTX, PinName PinRX) : SerialPort(PinTX,PinRX)
00005 {
00006     //constructor.
00007     SerialPort.baud(115200);
00008     SerialPort.attach(callback(this,&LAS_TB::Rx_interrupt), Serial::RxIrq);
00009     
00010     //Dit verzenden we naar de LAS-TB. Bevat het order get measured....
00011     Stack[0] = 0x55;    //Sync byte.
00012     Stack[1] = 0x08;    //Order (Get measerued values from L-LAS-RAM.)
00013     Stack[2] = 0x00;    //ARG LO.
00014     Stack[3] = 0x00;    //ARG HI.
00015     Stack[4] = 0x00;    //LEN LO.
00016     Stack[5] = 0x00;    //LEN HI.
00017     Stack[6] = 0xAA;    //CRC8 HEAD.
00018     Stack[7] = 0x76;    //CRC8 DATA.
00019 }
00020 
00021 union Converter
00022 {
00023     int32_t um;     // occupies 4 bytes
00024     uint8_t byteArray[4]; // occupies 4 bytes
00025 }; 
00026 
00027 //Vragen om een meting.
00028 void LAS_TB::MeasurementRequest()
00029 {
00030     SendStack();
00031 }
00032 
00033 //Wordt uitgevoerd bij ontvangen bericht.
00034 void LAS_TB::Rx_interrupt()
00035 {
00036     while (SerialPort.readable())
00037     {
00038         for (int i = 0; i < 71; i++)
00039         {
00040             ReceivedStack[i] = ReceivedStack[i+1];
00041         }
00042         ReceivedStack[71] = SerialPort.getc();
00043         
00044         //Hoe weten we dat het bericht goed is?
00045         if (ReceivedStack[0] == 0x55 && ReceivedStack[1] == 0x08 && ReceivedStack[4] == 64)
00046         {
00047             int32_t temp = ReceivedStack[16];
00048             
00049             umvalue = temp << 24;
00050             temp = ReceivedStack[17];
00051             umvalue += temp << 16;
00052             temp = ReceivedStack[18];
00053             umvalue += temp << 8;
00054             temp = ReceivedStack[19];
00055             umvalue += temp;       
00056         }
00057     }
00058 }
00059 
00060 //Het sturen van data.
00061 //Sends the stack of data to the sensor module.
00062 void LAS_TB::SendStack()
00063 {
00064         
00065     for (int i = 0; i < 10; i++)
00066     {
00067         SerialPort.putc(Stack[i]);
00068     }
00069     
00070 }