Ajout de l'encodage de la température exterieure

This commit is contained in:
anschrammh 2020-05-10 11:22:29 +02:00
parent 9d972a4acf
commit 8d6c48d458
2 changed files with 11 additions and 5 deletions

View File

@ -2,7 +2,7 @@
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;
_length = (numOfRow * numOfColumn * 2)/* x2 car il faut deux octets pour une température*/ + 7/*pour la date, le numero de trame et le nombre de lignes et de colonnes*/ + 1/*pour le charactère de fin de ligne*/ + 2/*pour la température exterieure*/;
_payload = (uint8_t *) calloc(_length, sizeof(uint8_t));
}
@ -25,7 +25,7 @@ boolean PayloadFormatter::endSession()
return ret;
}
int16_t PayloadFormatter::buildPayload(uint8_t **buffer, DateTime *dateTime, double *tempArray, uint8_t numOfRow, uint8_t numOfColumn)
int16_t PayloadFormatter::buildPayload(uint8_t **buffer, DateTime *dateTime, double externTemp, double *tempArray, uint8_t numOfRow, uint8_t numOfColumn)
{
*buffer = _payload;
if(_currentPayload == _totalPayloads || !_totalPayloads)
@ -53,8 +53,14 @@ int16_t PayloadFormatter::buildPayload(uint8_t **buffer, DateTime *dateTime, dou
_payload[5] = dateTime->hour();
_payload[6] = dateTime->minute();
//Partie temperature
for(int i(7),j(0); j < (_numOfRow * _numOfColumn); i+=2, j++)
//Octets 7 et 8 pour la température extérieure
//Format Q10.6
int16_t q10_6_extern = round(externTemp * pow(2,6));
_payload[7] = q10_6_extern >> 8;
_payload[8] = q10_6_extern;
//Partie temperature interne
for(int i(9),j(0); j < (_numOfRow * _numOfColumn); i+=2, j++)
{
//Format Q10.6
int16_t q10_6 = round(tempArray[j] * pow(2,6));

View File

@ -9,7 +9,7 @@ class PayloadFormatter
PayloadFormatter(uint8_t numOfRow, uint8_t numOfColumn);
~PayloadFormatter();
int16_t buildPayload(uint8_t **buffer, DateTime *dateTime, double *tempArray, uint8_t numOfRow = -1, uint8_t numOfColumn = -1);
int16_t buildPayload(uint8_t **buffer, DateTime *dateTime, double externTemp, double *tempArray, uint8_t numOfRow = -1, uint8_t numOfColumn = -1);
void startSession(uint8_t totalPackets);
boolean endSession();