/*! \file tsip.c \brief TSIP (Trimble Standard Interface Protocol) function library. */ //***************************************************************************** // // File Name : 'tsip.c' // Title : TSIP (Trimble Standard Interface Protocol) function library // Author : Pascal Stang - Copyright (C) 2002-2003 // Created : 2002.08.27 // Revised : 2003.07.17 // Version : 0.1 // Target MCU : Atmel AVR Series // Editor Tabs : 4 // // NOTE: This code is currently below version 1.0, and therefore is considered // to be lacking in some functionality or documentation, or may not be fully // tested. Nonetheless, you can expect most functions to work. // // This code is distributed under the GNU Public License // which can be found at http://www.gnu.org/licenses/gpl.txt // //***************************************************************************** #ifndef WIN32 #include #include #include #include #endif #include "global.h" #include "buffer.h" #include "rprintf.h" #include "uart2.h" #include "gps.h" #include "tsip.h" // Program ROM constants // Global variables extern GpsInfoType GpsInfo; #define BUFFERSIZE 0x40 u08 TsipPacket[BUFFERSIZE]; u08 debug; // function pointer to single byte output routine static void (*TsipTxByteFunc)(unsigned char c); void tsipInit(void (*txbytefunc)(unsigned char c)) { // set transmit function // (this function will be used for all SendPacket commands) TsipTxByteFunc = txbytefunc; // set debug status debug = 0; // compose GPS receiver configuration packet u08 packet[4]; packet[0] = BV(POS_LLA); packet[1] = BV(VEL_ENU); packet[2] = 0; packet[3] = 0; // send configuration tsipSendPacket(TSIPTYPE_SET_IO_OPTIONS, 4, packet); } void tsipSendPacket(u08 tsipType, u08 dataLength, u08* data) { u08 i; u08 dataIdx = 0; // start of packet TsipPacket[dataIdx++] = DLE; // packet type TsipPacket[dataIdx++] = tsipType; // add packet data for(i=0; idatalength > 1) { // look for a potential start of TSIP packet if(bufferGetAtIndex(rxBuffer,0) == DLE) { // make sure the next byte is not DLE or ETX data = bufferGetAtIndex(rxBuffer,1); if((data != DLE) && (data != ETX)) { // found potential start startFlag = TRUE; // done looking for start break; } } else // not DLE, dump character from buffer bufferGetFromFront(rxBuffer); } // if we detected a start, look for end of packet if(startFlag) { for(i=1; i<(rxBuffer->datalength)-1; i++) { // check for potential end of TSIP packet if((bufferGetAtIndex(rxBuffer,i) == DLE) && (bufferGetAtIndex(rxBuffer,i+1) == ETX)) { // have a packet end // dump initial DLE bufferGetFromFront(rxBuffer); // copy data to TsipPacket TsipPacketIdx = 0; for(j=0; j<(i-1); j++) { data = bufferGetFromFront(rxBuffer); if(data == DLE) { if(bufferGetAtIndex(rxBuffer,0) == DLE) { // found double-DLE escape sequence, skip one of them bufferGetFromFront(rxBuffer); j++; } } TsipPacket[TsipPacketIdx++] = data; } // dump ending DLE+ETX bufferGetFromFront(rxBuffer); bufferGetFromFront(rxBuffer); // found a packet if(debug) { rprintf("Rx TSIP packet type: 0x%x len: %d rawlen: %d\r\n", TsipPacket[0], TsipPacketIdx, i); for(k=0; k