Index: webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c =================================================================== --- webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 76) +++ webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 77) @@ -1373,15 +1373,8 @@ - /* convert day to binary coded hex */ - if (day > 15) - { - req_day_yield[8] = 0x31; /* hex MSB day is 1 */ - day = day - 16; /* decrease day (is now remainder */ - } - else - { - req_day_yield[8] = 0x30; /* hex MSB day is 0 */ - } - req_day_yield[9] = 0x30 + day; /* hex LSB day */ + convert_uchar_to_2_byte_hexencoding(day, &req_day_yield[8], &req_day_yield[9]); + + + newChkSum = calculate_crc8( (&(req_day_yield[0])), (sizeof(req_day_yield)-1)); @@ -1403,24 +1396,9 @@ req_hour_yield[5] = 0x30 + channel; // channel - if (hour >= 0x10) /* >= 16 */ - { - hourMSB = 1; - } - else - { - hourMSB = 0; - } - hourLSB = hour - (hourMSB * 0x10); - - if (hourLSB <= 9) - { - req_hour_yield[9] = 0x30 + hourLSB; // minute LSB (binary coded hex) - } - else - { - req_hour_yield[9] = 0x40 + hourLSB - 0xA; // minute LSB (binary coded hex, 0xA --> 0x40, 0xF -> 0x45) - } - - req_hour_yield[8] = 0x30 + hourMSB; // minute MSB (binary coded hex), 30 or 31 here. + + convert_uchar_to_2_byte_hexencoding(hour, &req_hour_yield[8], &req_hour_yield[9]); + + + @@ -1463,2 +1441,73 @@ } /* prepare_yield_query_minute() */ + +void convert_uchar_to_2_byte_hexencoding(unsigned char inValue, unsigned char * outMSB, unsigned char * outLSB) +{ + + *outLSB = convertSingleDigit(inValue & 0xF); + *outMSB = convertSingleDigit(((inValue >> 4) & 0xF)); +} + +unsigned char convertSingleDigit(unsigned char inValue) +{ + unsigned char retVal; + + switch (inValue) + { + case 0x0: + retVal = 0x30 + 0; + break; + case 0x1: + retVal = 0x30 + 1; + break; + case 0x2: + retVal = 0x30 + 2; + break; + case 0x3: + retVal = 0x30 + 3; + break; + case 0x4: + retVal = 0x30 + 4; + break; + case 0x5: + retVal = 0x30 + 5; + break; + case 0x6: + retVal = 0x30 + 6; + break; + case 0x7: + retVal = 0x30 + 7; + break; + case 0x8: + retVal = 0x30 + 8; + break; + case 0x9: + retVal = 0x30 + 9; + break; + + case 0xA: + retVal = 0x41 + 0; + break; + case 0xB: + retVal = 0x41 + 1; + break; + case 0xC: + retVal = 0x41 + 2; + break; + case 0xD: + retVal = 0x41 + 3; + break; + case 0xE: + retVal = 0x41 + 4; + break; + case 0xF: + retVal = 0x41 + 5; + break; + + default: + retVal = 0x78; /* erro: 'x' */ + + } + return retVal; + +} /* convertSingleDigit() */ Index: webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h =================================================================== --- webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 70) +++ webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 77) @@ -1,4 +1,8 @@ void initMeterItems(void); + +void convert_uchar_to_2_byte_hexencoding(unsigned char inValue, unsigned char * outMSB, unsigned char * outLSB); +unsigned char convertSingleDigit(unsigned char inValue); + portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned char CheckSumStartByte);