1 /*
2  * MSPBSL_Connection 5xx
3  *
4  * A class file to impliment the high-level communication interface for 5xx BSL connections
5  *
6  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
7  *
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *
13  *    Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  *    Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the
19  *    distribution.
20  *
21  *    Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37 */
38 
39 #include <pch.h>
40 
41 #include "MSPBSL_Connection5xx.h"
42 #include "MSPBSL_PhysicalInterfaceSerialUART.h"
43 #include "MSPBSL_PacketHandler.h"
44 
45 using namespace std;
46 
47 string BUG_DESIGNATOR = "BUG:";
48 string bugList = "";
49 
50 /***************************************************************************//**
51 * MSPBSL_Connection5xx Class Constructor.
52 *
53 * Creates a 5/6xx General Connection using the supplied parameters
54 *
55 * \param initString an initialization string for the connection
56 *
57 * \return a MSPBSL_Connection5xx class
58 ******************************************************************************/
MSPBSL_Connection5xx(string initString)59 MSPBSL_Connection5xx::MSPBSL_Connection5xx(string initString)
60 {
61 	// currently no bugs
62 	if( initString.find(BUG_DESIGNATOR) != string::npos)
63 	{
64 		int bugStart = initString.find(BUG_DESIGNATOR)+BUG_DESIGNATOR.size();
65 		int bugEnd = initString.find(' ',  bugStart );
66 		bugList.append(initString.substr( bugStart, bugEnd-bugStart));
67 	}// found buglist
68 
69 }
70 
71 /***************************************************************************//**
72 * MSPBSL_Connection5xx Class Destructor.
73 *
74 ******************************************************************************/
~MSPBSL_Connection5xx(void)75 MSPBSL_Connection5xx::~MSPBSL_Connection5xx(void)
76 {
77 }
78 
79 /***************************************************************************//**
80 * The 5/6xx Standard Set PC Command
81 *
82 * Creates a databuffer containing a standard 5/6xx Set PC Command, and passes
83 * this on to the Packet Handler layer for sending
84 *
85 * \param addr a 32-bit address where the device should begin to execute
86 *
87 * \return the result of packet handler's Packet Transmission.  Note: This only
88 *         means the caller knows if the packet was sucessfully sent to the BSL,
89 *         not whether the desired address is executing correctly
90 ******************************************************************************/
setPC(uint32_t addr)91 uint16_t MSPBSL_Connection5xx::setPC(uint32_t addr)
92 {
93   uint8_t command[4];
94   command[0]=SET_PC_COMMAND;
95   command[1]=((addr)&0xFF);                  // AL
96   command[2]=((addr>>8)&0xFF);               // AM
97   command[3]=((addr>>16)&0xFF);              // AH
98   thePacketHandler->TX_Packet(command, 4);
99   return ACK;
100 }
101 
102 /***************************************************************************//**
103 * The 5/6xx Standard Toggle Info Command
104 *
105 * Creates a databuffer containing a standard 5/6xx Toggle Info Command, and passes
106 * this on to the Packet Handler layer for sending
107 *
108 * \return the value returned by the connected BSL, or underlying connection layers
109 ******************************************************************************/
toggleInfo(void)110 uint16_t MSPBSL_Connection5xx::toggleInfo(void)
111 {
112   uint8_t command[1];
113   command[0]=TOGGLE_INFO_LOCK_COMMAND;
114   return sendPacketExpectMessage(command, 1);
115 }
116 
117 /***************************************************************************//**
118 * The 5/6xx Standard Erase Segment Command
119 *
120 * Creates a databuffer containing a standard 5/6xx Erase Segment Command, and passes
121 * this on to the Packet Handler layer for sending
122 *
123 * \param addr a 32-bit address which is in the desired segment to erase
124 *
125 * \return the value returned by the connected BSL, or underlying connection layers
126 ******************************************************************************/
eraseSegment(uint32_t addr)127 uint16_t MSPBSL_Connection5xx::eraseSegment(uint32_t addr)
128 {
129   uint8_t command[4];
130   command[0]=ERASE_SEGMENT_COMMAND;
131   command[1]=((addr)&0xFF);                  // AL
132   command[2]=((addr>>8)&0xFF);               // AM
133   command[3]=((addr>>16)&0xFF);              // AH
134   return sendPacketExpectMessage(command, 4);
135 }
136 
137 /***************************************************************************//**
138 * The 5/6xx Standard Get Buffer Size Command
139 *
140 * Creates a databuffer containing a standard 5/6xx Get Buffer Size Command, and passes
141 * this on to the Packet Handler layer for sending
142 *
143 * \param bufSize a reference to a 16 bit variable in which to write the buffer size
144 *
145 * \return the value returned by the connected BSL, or underlying connection layers
146 ******************************************************************************/
TX_BufferSize(uint16_t * bufSize)147 uint16_t MSPBSL_Connection5xx::TX_BufferSize(uint16_t* bufSize)
148 {
149   uint16_t retValue;
150   uint8_t command[4];
151   uint8_t rxBuf[4];
152   command[0]=TX_BUFFER_SIZE_COMMAND;
153   retValue = thePacketHandler->TX_Packet(command, 1);
154   if( retValue == OPERATION_SUCCESSFUL )
155   {
156 	  retValue = thePacketHandler->RX_Packet(rxBuf, 4);
157 	  if (retValue == OPERATION_SUCCESSFUL )
158 	  {
159 		  if( command[0] == MESSAGE_RESPONSE ) // we have a message
160 		  {
161 			  retValue = command[1];   // return the message
162 		  }
163 		  else if( command[0] == DATA_RESPONSE ) // we have the size
164 		  {
165 			  //parse buffer
166 			  *bufSize = ((uint32_t)command[2])<<8;
167 			  *bufSize |= ((uint32_t)command[1]);
168 			  retValue = OPERATION_SUCCESSFUL;
169 		  }
170 		  else
171 		  {
172 			  retValue = UNEXPECTED_VALUE; // panic
173 		  }
174 	  }
175   }
176   return retValue;
177 
178 }
179 
180 /***************************************************************************//**
181 * The 5/6xx Standard RX Data Block Fast Command
182 *
183 * Creates a databuffer containing a standard 5/6xx RX Data Block Fast Command, and passes
184 * this on to the Packet Handler layer for sending.  Note: This command tells the BSL
185 * to Receive a data block, so it will send data from the Host
186 *
187 * \param data an array of unsigned bytes to send
188 * \param startAddr the start address in device memory to begin writing these bytes
189 * \param numBytes the number of bytes in the array
190 *
191 * \return the value returned by the connected BSL, or underlying connection layers
192 *         Note: This only means the caller knows if the packet was sucessfully
193 *         sent to the BSL, not whether the data was correctly written
194 ******************************************************************************/
RX_DataBlockFast(const uint8_t * data,uint32_t startAddr,uint32_t numBytes)195 uint16_t MSPBSL_Connection5xx::RX_DataBlockFast(const uint8_t* data, uint32_t startAddr, uint32_t numBytes )
196 {
197 	uint16_t retValue = ACK;
198 	uint32_t currentStartAddr = startAddr;
199 	uint16_t currentPacketNumBytes;
200 	uint32_t numBytesRemaining = numBytes;
201 	uint16_t currentBytePointer = 0;
202 	uint16_t maxPacketSize = thePacketHandler->getMaxDataSize()-4;
203 	while( numBytesRemaining > 0)
204 	{
205 		if( numBytesRemaining > maxPacketSize )
206 		{
207 			currentPacketNumBytes = maxPacketSize;
208 		}
209 		else
210 		{
211 			currentPacketNumBytes = (uint16_t)numBytesRemaining;  // cast is safe since max Packet size is less than 16 bts
212 		}
213 		uint8_t* txDataBuf = NULL;
214 		txDataBuf = new uint8_t[currentPacketNumBytes+4];
215 		txDataBuf[0] = RX_DATA_BLOCK_FAST_COMMAND;
216 		txDataBuf[1] = ((currentStartAddr)&0xFF);      // AL
217 		txDataBuf[2] = ((currentStartAddr>>8)&0xFF);   // AM
218 		txDataBuf[3] = ((currentStartAddr>>16)&0xFF);  // AH
219 		for( uint16_t i = 0; i < currentPacketNumBytes; i++,currentBytePointer++ )
220 		{
221 			txDataBuf[i+4] = data[currentBytePointer];
222 
223 		}
224 		retValue = sendPacketExpectNothing(txDataBuf, currentPacketNumBytes+4);
225 		delete [] txDataBuf;
226 		currentStartAddr += currentPacketNumBytes;
227 		numBytesRemaining -= currentPacketNumBytes;
228 		if( retValue != ACK )
229 		{
230 			return retValue;
231 		}
232 	} // while
233 
234 	return retValue;
235 
236 }
237 
238 /***************************************************************************//**
239 * The 5/6xx Standard RX Data Block Command
240 *
241 * Creates a databuffer containing a standard 5/6xx RX Data Block Command, and passes
242 * this on to the Packet Handler layer for sending.  Note: This command tells the BSL
243 * to Receive a data block, so it will send data from the Host
244 *
245 * \param data an array of unsigned bytes to send
246 * \param startAddr the start address in device memory to begin writing these bytes
247 * \param numBytes the number of bytes in the array
248 *
249 * \return the value returned by the connected BSL, or underlying connection layers
250 ******************************************************************************/
RX_DataBlock(uint8_t * data,uint32_t startAddr,uint32_t numBytes)251 uint16_t MSPBSL_Connection5xx::RX_DataBlock(uint8_t* data, uint32_t startAddr, uint32_t numBytes)
252 {
253     uint16_t retValue = ACK;
254 	uint32_t currentStartAddr = startAddr;
255 	uint16_t currentPacketNumBytes;
256 	uint16_t numBytesRemaining = numBytes;
257 	uint16_t currentBytePointer = 0;
258 	uint16_t maxPacketSize = thePacketHandler->getMaxDataSize()-4;
259 	while( numBytesRemaining > 0)
260 	{
261 		if( numBytesRemaining > maxPacketSize )
262 		{
263 			currentPacketNumBytes = maxPacketSize;
264 		}
265 		else
266 		{
267 			currentPacketNumBytes = (uint16_t)numBytesRemaining;  // cast is safe since max Packet size is less than 16 bts
268 		}
269 		uint8_t* txDataBuf = NULL;
270 		txDataBuf = new uint8_t[currentPacketNumBytes+4];
271 		txDataBuf[0] = RX_DATA_BLOCK_COMMAND;
272 		txDataBuf[1] = ((currentStartAddr)&0xFF);      // AL
273 		txDataBuf[2] = ((currentStartAddr>>8)&0xFF);   // AM
274 		txDataBuf[3] = ((currentStartAddr>>16)&0xFF);  // AH
275 		for( uint16_t i = 0; i < currentPacketNumBytes; i++,currentBytePointer++ )
276 		{
277 			txDataBuf[i+4] = data[currentBytePointer];
278 
279 		}
280 		retValue = sendPacketExpectMessage(txDataBuf, currentPacketNumBytes+4);
281 		delete [] txDataBuf;
282 		currentStartAddr += currentPacketNumBytes;
283 		numBytesRemaining -= currentPacketNumBytes;
284 		if( retValue != ACK )
285 		{
286 			return retValue;
287 		}
288 	} // while
289 
290 	return retValue;
291 
292 }
293 
294 /***************************************************************************//**
295 * The 5/6xx Standard TX Data Block Command
296 *
297 * Sends one or more TX Data Block Commands in order to write all data in the
298 * supplied array down to memory as requested
299 *
300 * \param data an array of unsigned bytes to send
301 * \param startAddr the start address in device memory to begin writing these bytes
302 * \param numBytes the number of bytes in the array
303 *
304 * \return the value returned by the connected BSL, or underlying connection layers
305 ******************************************************************************/
TX_DataBlock(uint8_t * data,uint32_t startAddr,uint32_t numBytes)306 uint16_t MSPBSL_Connection5xx::TX_DataBlock( uint8_t* data, uint32_t startAddr, uint32_t numBytes)
307 {
308   // to do: handle "large" streaming data blocks being TXed
309 
310   uint16_t retValue = ACK;
311   uint16_t maxPacketSize = thePacketHandler->getMaxDataSize();
312   uint16_t maxBytesRXed = maxPacketSize-1;          // the packet size minus data header = max data
313   uint16_t totalBytesRxed = 0;
314   uint16_t bytesReceived;
315   uint8_t  command[6];
316   uint16_t TimeOut = 3;
317   vector<uint8_t> rxDataBuf(maxPacketSize);
318 
319   if( numBytes > (uint32_t)0xFFFF )  // if we are requesting over a 16 byte number, we must break it up
320   {
321 	  retValue |= TX_DataBlock( (data+0xFFFF), (startAddr+0xFFFF), (numBytes-0xFFFF) );  // use recursion to grab the remaining upper locations
322 	  numBytes = 0xFFFF;
323   }
324 
325   command[0]=TX_DATA_BLOCK_COMMAND;
326   command[1]=((startAddr)&0xFF);                  // AL
327   command[2]=((startAddr>>8)&0xFF);               // AM
328   command[3]=((startAddr>>16)&0xFF);              // AH
329   command[4]=((numBytes)&0xFF);                   // Bytes_Low
330   command[5]=((numBytes>>8)&0xFF);                // Bytes_High
331 
332   retValue |= thePacketHandler->TX_Packet(command, 6);
333   if( retValue == 0x00 )
334   {
335 	  uint16_t bytesExpected;
336 	  if( numBytes > maxBytesRXed)
337 	  {
338 		  bytesExpected = maxBytesRXed;
339 	  }
340 	  else
341 	  {
342 		  bytesExpected = numBytes;
343 	  }
344 	  bytesExpected++;   // +1 for the header
345 	  TimeOut = TimeOut * numBytes;
346 	  while( totalBytesRxed < numBytes && TimeOut > 0)  // to do: recompute bytesExpected each loop!
347 	  {
348 		  retValue = thePacketHandler->RX_Packet(&rxDataBuf[0], bytesExpected, &bytesReceived);
349 		  if (retValue == OPERATION_SUCCESSFUL )
350 		  {
351 			  if( rxDataBuf[0] == MESSAGE_RESPONSE ) // we have a message
352 			  {
353 				  // to do: if the message is a buffer size error, switch reading mode to non-streaming
354 				  retValue = rxDataBuf[1];   // return the message
355 			  }
356 			  else if( rxDataBuf[0] == DATA_RESPONSE ) // we have the data
357 			  {
358 				  for( uint16_t i = 1; i < bytesReceived; i++,totalBytesRxed++ )  //i = 1 to skip over data header byte
359 				  {
360 					  data[totalBytesRxed] = rxDataBuf[i];
361 				  }
362 			  }
363 		  }
364 		  TimeOut--;
365 	  } // while
366   }
367   return retValue;
368 
369 }
370 
371 /***************************************************************************//**
372 * The 5/6xx Standard CRC Command
373 *
374 * Creates a databuffer containing a standard 5/6xx CRC Command, and passes
375 * this on to the Packet Handler layer for sending.
376 *
377 * \param CRC_Return 32bit variable reference in which the CRC value will be placed
378 * \param startAddr The start address for CRC computation
379 * \param numBytes The number of bytes to include in CRC computation
380 *
381 * \return the value returned by the connected BSL, or underlying connection layers
382 ******************************************************************************/
CRC_Check(uint16_t * CRC_Return,uint32_t startAddr,uint16_t numBytes)383 uint16_t MSPBSL_Connection5xx::CRC_Check(uint16_t* CRC_Return, uint32_t startAddr, uint16_t numBytes)
384 {
385 
386   uint16_t retValue = ACK;
387   uint8_t command[6];
388   //dataBuffer command(6);
389   command[0]=CRC_CHECK_COMMAND;
390   command[1]=((startAddr)&0xFF);                  // AL
391   command[2]=((startAddr>>8)&0xFF);               // AM
392   command[3]=((startAddr>>16)&0xFF);              // AH
393   command[4]=((numBytes)&0xFF);                   // Bytes_Low
394   command[5]=((numBytes>>8)&0xFF);                // Bytes_High
395 
396   retValue = thePacketHandler->TX_Packet(command, 6);
397   if( retValue == OPERATION_SUCCESSFUL )
398   {
399 	  retValue = thePacketHandler->RX_Packet(command, 3);
400 	  if (retValue == OPERATION_SUCCESSFUL )
401 	  {
402 		  if( command[0] == MESSAGE_RESPONSE ) // we have a message
403 		  {
404 			  retValue = command[1];   // return the message
405 		  }
406 		  else if( command[0] == DATA_RESPONSE ) // we have the CRC
407 		  {
408 
409 			  //parse CRC
410 			  *CRC_Return = ((uint16_t)command[2])<<8;
411 			  *CRC_Return |= ((uint16_t)command[1]);
412 			  retValue = ACK;
413 		  }
414 		  else
415 		  {
416 			  retValue = GENERAL_BSL_CONNECTION_ERROR; // panic
417 		  }
418 	  }
419   }
420   return retValue;
421 
422 }
423 
424 /***************************************************************************//**
425 * The 5/6xx Standard TX BSL Version Command
426 *
427 * Creates a databuffer containing a standard 5/6xx TX BSL Version Command, and passes
428 * this on to the Packet Handler layer for sending.
429 *
430 * \param versionString a reference to a string which will store the returned version
431 *
432 * \return the value returned by the connected BSL, or underlying connection layers
433 ******************************************************************************/
TX_BSL_Version(string & versionString)434 uint16_t MSPBSL_Connection5xx::TX_BSL_Version(string& versionString)
435 {
436 
437   uint16_t retValue = ACK;
438   versionString = "";
439   uint8_t rxedDataPacket[5];
440   uint16_t rxedByteCount;
441   uint8_t commandPacket[1];
442   commandPacket[0] = TX_BSL_VERSION_COMMAND;
443   retValue = thePacketHandler->TX_Packet(commandPacket, 1);
444   if( retValue == OPERATION_SUCCESSFUL )
445   {
446 	  retValue = thePacketHandler->RX_Packet(rxedDataPacket, 5, &rxedByteCount);
447 	  if (retValue == OPERATION_SUCCESSFUL )
448 	  {
449 		  if( rxedDataPacket[0] == MESSAGE_RESPONSE ) // we have a message
450 		  {
451 			  retValue = rxedDataPacket[1];   // return the message
452 		  }
453 		  else if( rxedDataPacket[0] == DATA_RESPONSE ) // we have the Version
454 		  {
455 			  versionString += (uint8_t)(((rxedDataPacket[1]>>4)&0xF)+48);
456 			  versionString += (uint8_t)(((rxedDataPacket[1])&0xF)+48);
457 			  versionString += '.';
458 			  versionString += (uint8_t)(((rxedDataPacket[2]>>4)&0xF)+48);
459 			  versionString += (uint8_t)(((rxedDataPacket[2])&0xF)+48);
460 			  versionString += '.';
461 			  versionString += (uint8_t)(((rxedDataPacket[3]>>4)&0xF)+48);
462 			  versionString += (uint8_t)(((rxedDataPacket[3])&0xF)+48);
463 			  versionString += '.';
464 			  versionString += (uint8_t)(((rxedDataPacket[4]>>4)&0xF)+48);
465 			  versionString += (uint8_t)(((rxedDataPacket[4])&0xF)+48);
466 			  for( int i = 0; i < 11; i++)
467 			  {
468 				  if( (versionString[i] >= 58) && (versionString[i] <= 63))
469 				  {
470 					  versionString[i] += 7;
471 				  }
472 			  }
473 			  retValue = OPERATION_SUCCESSFUL;
474 		  }
475 		  else
476 		  {
477 			  retValue = GENERAL_BSL_CONNECTION_ERROR; // panic
478 		  }
479 	  }
480   }
481   return retValue;
482 
483 	return 0;
484 }
485 
486 /***************************************************************************//**
487 * The 5/6xx Standard RX Password Command
488 *
489 * Creates a databuffer containing a standard 5/6xx RX Password Command, and passes
490 * this on to the Packet Handler layer for sending.  Note: This command accepts
491 * no parameters as it sends a default (32x 0xFF) password
492 *
493 * \return the value returned by the connected BSL, or underlying connection layers
494 ******************************************************************************/
RX_Password(void)495 uint16_t MSPBSL_Connection5xx::RX_Password(void)
496 {
497 	uint8_t standardPassword[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
498 	return RX_Password( standardPassword );
499 
500 }
501 
502 /***************************************************************************//**
503 * The 5/6xx Standard RX Password Command
504 *
505 * Creates a databuffer containing a standard 5/6xx RX Password Command, and passes
506 * this on to the Packet Handler layer for sending.
507 *
508 * \param pass a databuffer containing the device password
509 *
510 * \return the value returned by the connected BSL, or underlying connection layers
511 ******************************************************************************/
RX_Password(uint8_t * password)512 uint16_t MSPBSL_Connection5xx::RX_Password(uint8_t* password)
513 {
514 	uint8_t passwordPacket[33];
515 	passwordPacket[0] = RX_PASSWORD_COMMAND;
516 	for( uint8_t i = 0; i < 32; i++ )
517 	{
518 		passwordPacket[i+1] = password[i];
519 	}
520 
521     return sendPacketExpectMessage(passwordPacket, 33);
522 }
523 
524 /***************************************************************************//**
525 * The 5/6xx Standard Mass Erase Command
526 *
527 * Creates a databuffer containing a standard 5/6xx Mass Erase Command, and passes
528 * this on to the Packet Handler layer for sending.
529 *
530 * \return the value returned by the connected BSL, or underlying connection layers
531 ******************************************************************************/
massErase(void)532 uint16_t MSPBSL_Connection5xx::massErase(void)
533 {
534   uint8_t massEraseCommand[1];
535   massEraseCommand[0] = MASS_ERASE_COMMAND;
536   return sendPacketExpectMessage(massEraseCommand, 1);
537 }
538 
539 /***************************************************************************//**
540 * Sends a Data packet and waits for the BSL to reply with a message
541 *
542 * This function transmits a data packet to the BSL, and will expect that
543 * the BSL should reply with a message
544 *
545 * \param packet an array of unsigned bytes containing the data to send
546 * \param packetSize the number of bytes in the packet
547 *
548 * \return the message or error returned by BSL or underlying layers
549 ******************************************************************************/
sendPacketExpectMessage(uint8_t * packet,uint16_t packetSize)550 uint16_t MSPBSL_Connection5xx::sendPacketExpectMessage(uint8_t* packet, uint16_t packetSize)
551 {
552   uint16_t retValue, tempRX;
553   uint8_t messageBuf[2];
554   retValue = thePacketHandler->TX_Packet(packet, packetSize);
555   if( retValue == OPERATION_SUCCESSFUL )
556   {
557 	  retValue = thePacketHandler->RX_Packet(messageBuf, 2, &tempRX );
558 	  if (retValue == OPERATION_SUCCESSFUL )
559 	  {
560 		  if( messageBuf[0] == MESSAGE_RESPONSE ) // we have a message
561 		  {
562 			  retValue = messageBuf[1];   // return the message
563 		  }
564 		  else
565 		  {
566 			  retValue = GENERAL_BSL_CONNECTION_ERROR; // panic
567 		  }
568 	  }
569   }
570 
571   return retValue;
572 }
573 
574 /***************************************************************************//**
575 * Sends a Data packet and does not expect a message
576 *
577 * This function transmits a data packet to the BSL, and will not expect that
578 * the BSL replies with a message
579 *
580 * \param packet an array of unsigned bytes containing the data to send
581 * \param packetSize the number of bytes in the packet
582 *
583 * \return TX status as returned by the underlying layers (0 for success)
584 ******************************************************************************/
sendPacketExpectNothing(uint8_t * packet,uint16_t packetSize)585 uint16_t MSPBSL_Connection5xx::sendPacketExpectNothing(uint8_t* packet, uint16_t packetSize)
586 {
587   return thePacketHandler->TX_Packet(packet, packetSize);
588 }
589 
590 /***************************************************************************//**
591 * An error description function
592 *
593 * This function is meant to return a string which fully describes an error code
594 * which could be returned from any function within this class
595 *
596 * \param err the 16 bit error code
597 *
598 * \return A string describing the error code
599 ******************************************************************************/
getErrorInformation(uint16_t err)600 string MSPBSL_Connection5xx::getErrorInformation( uint16_t err )
601 {
602 	return MSPBSL_Connection::getErrorInformation( err );
603 }
604