Bibliothèque PayLoadFormatter renommée en PayloadFormatter + optimisation du calcul en format q10.6
This commit is contained in:
		
							parent
							
								
									7774ef334e
								
							
						
					
					
						commit
						62ac65125b
					
				
							
								
								
									
										68
									
								
								lib/PayloadFormatter/PayloadFormatter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								lib/PayloadFormatter/PayloadFormatter.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,68 @@
 | 
			
		||||
#include "PayloadFormatter.h"
 | 
			
		||||
 | 
			
		||||
PayloadFormatter::PayloadFormatter(uint8_t numOfRow, uint8_t numOfColumn) : _totalPayloads(0), _currentPayload(0), _numOfRow(numOfRow), _numOfColumn(numOfColumn), _payload(NULL), _length(0)
 | 
			
		||||
{
 | 
			
		||||
  _length = numOfRow * numOfColumn * 2 + 7 + 1;
 | 
			
		||||
  _payload = (uint8_t *) calloc(_length, sizeof(uint8_t));
 | 
			
		||||
}
 | 
			
		||||
PayloadFormatter::~PayloadFormatter()
 | 
			
		||||
{
 | 
			
		||||
  free(_payload);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PayloadFormatter::startSession(uint8_t totalPayloads)
 | 
			
		||||
{
 | 
			
		||||
  _totalPayloads = totalPayloads;
 | 
			
		||||
  _currentPayload = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
boolean PayloadFormatter::endSession()
 | 
			
		||||
{
 | 
			
		||||
  boolean ret = _currentPayload == _totalPayloads;
 | 
			
		||||
  if(ret)_totalPayloads = 0;
 | 
			
		||||
  
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int16_t PayloadFormatter::buildPayload(uint8_t **buffer, DateTime *dateTime, double *tempArray)
 | 
			
		||||
{
 | 
			
		||||
  *buffer = _payload;
 | 
			
		||||
  if(_currentPayload == _totalPayloads || !_totalPayloads)
 | 
			
		||||
  {
 | 
			
		||||
      *_payload = '\0';
 | 
			
		||||
      return 0;
 | 
			
		||||
  }
 | 
			
		||||
    
 | 
			
		||||
  _currentPayload++;
 | 
			
		||||
 | 
			
		||||
  //Octet avec nombre de trames et numero de la trame
 | 
			
		||||
  _payload[0] = _totalPayloads;
 | 
			
		||||
  _payload[0] &= 0x0F;//Permet  de mettre à 0 les overflow
 | 
			
		||||
  _payload[0] |= _currentPayload << 4;
 | 
			
		||||
 | 
			
		||||
  //Octet avec nombre de ligne et nombre de colonne de capteurs
 | 
			
		||||
  _payload[1] = _numOfRow;
 | 
			
		||||
  _payload[1] &= 0x0F;//Permet  de mettre à 0 les overflow
 | 
			
		||||
  _payload[1] |= _numOfColumn << 4;
 | 
			
		||||
 | 
			
		||||
  //5 octets de dates
 | 
			
		||||
  _payload[2] = dateTime->year() - 2000;
 | 
			
		||||
  _payload[3] = dateTime->month();
 | 
			
		||||
  _payload[4] = dateTime->day();
 | 
			
		||||
  _payload[5] = dateTime->hour();
 | 
			
		||||
  _payload[6] = dateTime->minute();
 | 
			
		||||
 | 
			
		||||
  //Partie temperature
 | 
			
		||||
  for(int i(7),j(0); j < (_numOfRow * _numOfColumn); i+=2, j++)
 | 
			
		||||
  {
 | 
			
		||||
    //Format Q10.6
 | 
			
		||||
    int16_t q10_6 = round(tempArray[j] * pow(2,6));
 | 
			
		||||
    
 | 
			
		||||
    _payload[i] = q10_6 >> 8;
 | 
			
		||||
    _payload[i+1] = q10_6;
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  _payload[_length-1] = '\0';
 | 
			
		||||
  return _length - 1;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								lib/PayloadFormatter/PayloadFormatter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								lib/PayloadFormatter/PayloadFormatter.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
#ifndef PAYLOADFORMATTER_H
 | 
			
		||||
#define PAYLOADFORMATTER_H
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include "RTClib.h" //Nécessaire afin d'utiliser l'object DateTime
 | 
			
		||||
 | 
			
		||||
class PayloadFormatter
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    PayloadFormatter(uint8_t numOfRow, uint8_t numOfColumn);
 | 
			
		||||
    ~PayloadFormatter();
 | 
			
		||||
 | 
			
		||||
    int16_t buildPayload(uint8_t **buffer, DateTime *dateTime, double *tempArray);
 | 
			
		||||
    void startSession(uint8_t totalPackets);
 | 
			
		||||
    boolean endSession();
 | 
			
		||||
    
 | 
			
		||||
  protected:
 | 
			
		||||
  private:
 | 
			
		||||
  
 | 
			
		||||
    uint8_t _totalPayloads;
 | 
			
		||||
    uint8_t _currentPayload;
 | 
			
		||||
    uint8_t _numOfRow;
 | 
			
		||||
    uint8_t _numOfColumn;
 | 
			
		||||
    uint8_t *_payload;
 | 
			
		||||
    uint8_t _length;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif //PAYLOADFOMATTER_H
 | 
			
		||||
							
								
								
									
										9
									
								
								lib/PayloadFormatter/PayloadFormatter.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								lib/PayloadFormatter/PayloadFormatter.ino
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
void setup() {
 | 
			
		||||
  // put your setup code here, to run once:
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  // put your main code here, to run repeatedly:
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user