smlparser.h
bool parsePacket(const uint8_t *pPacket, int packetLength) {
      _pPacket = pPacket;
      _packetLength = packetLength;

      int pos = 0;

      while (pos < packetLength) {
         if (pPacket[pos] == SML_END_OF_MESSAGE) {
            break;
         }
         int messageStart = pos;
         getLength(pos);      // Skip list identifier of message
         int messageBody = getNextElement(pos, 3);
         getNextElement(pos); // Skip to crc
         int messageLength = pos - messageStart;
         uint16_t crc16Expected = (uint16_t)getNextIntValue(pos);

         // Check crc
         _crc16.init();
         _crc16.calc(pPacket + messageStart, messageLength);
         if (crc16Expected == _crc16.getCrc()) {
            if (parseMessageBody(messageBody)) {
               break;
            }
            // Skip 'end of message'
            ++pos;
         }
         else {
            //printf("Parser: Warning %04x != %04x\n", crc16Expected, _crc16.getCrc());
            ++_parseErrors;
            return false;
            break;
         }
      }
      ++_parsedOk;
      return true;
   }
/**
    * @brief Parse a SML packet
    * @param pPacket       Packet to parse
    * @param packetLength  Length of the packet in bytes
    * @return true, if the packet could be parsed successfully
    */
@brief Parse a SML packet
@param pPacket       Packet to parse
@param packetLength  Length of the packet in bytes
@return true, if the packet could be parsed successfully
@brief Parse a SML packet @param pPacket Packet to parse @param packetLength Length of the packet in bytes @return true if the packet could be parsed successfully
bool parsePacket(const uint8_t *pPacket, int packetLength) {
      _pPacket = pPacket;
      _packetLength = packetLength;
      int pos = 0;
      while (pos < packetLength) {
         if (pPacket[pos] == SML_END_OF_MESSAGE) {
            break;
         }
         int messageStart = pos;
         getLength(pos);      
         int messageBody = getNextElement(pos, 3);
         getNextElement(pos); 
         int messageLength = pos - messageStart;
         uint16_t crc16Expected = (uint16_t)getNextIntValue(pos);
         _crc16.init();
         _crc16.calc(pPacket + messageStart, messageLength);
         if (crc16Expected == _crc16.getCrc()) {
            if (parseMessageBody(messageBody)) {
               break;
            }
            ++pos;
         }
         else {
            ++_parseErrors;
            return false;
            break;
         }
      }
      ++_parsedOk;
      return true;
   }
bool parsePacket ( const uint8_t * pPacket , int packetLength ) { _pPacket = pPacket ; _packetLength = packetLength ; int pos = 0 ; while ( pos < packetLength ) { if ( pPacket [ pos ] == SML_END_OF_MESSAGE ) { break ; } int messageStart = pos ; getLength ( pos ) ; int messageBody = getNextElement ( pos , 3 ) ; getNextElement ( pos ) ; int messageLength = pos - messageStart ; uint16_t crc16Expected = ( uint16_t ) getNextIntValue ( pos ) ; _crc16 . init ( ) ; _crc16 . calc ( pPacket + messageStart , messageLength ) ; if ( crc16Expected == _crc16 . getCrc ( ) ) { if ( parseMessageBody ( messageBody ) ) { break ; } ++ pos ; } else { ++ _parseErrors ; return false ; break ; } } ++ _parsedOk ; return true ; }
@brief Parse a SML packet
 @param pPacket       Packet to parse
 @param packetLength  Length of the packet in bytes
 @return true, if the packet could be parsed successfully
@brief Parse a SML packet @param pPacket Packet to parse @param packetLength Length of the packet in bytes @return true if the packet could be parsed successfully
// Skip list identifier of message // Skip to crc // Check crc // Skip 'end of message' //printf("Parser: Warning %04x != %04x\n", crc16Expected, _crc16.getCrc());