Skip to content

Commit

Permalink
[Mega] Allow compile with 2.4.0 core library (#772)
Browse files Browse the repository at this point in the history
Last few days, lots of issues reported by users who installed the 2.4.0 core libraries.
e.g. #769 and #763
It appeared the default PlatformIO Espressif 8266 1.6.0 libs now include the 2.4.0 core libraries.
Now I have to find a way to get my own environment back to the 2.3.0 core libs and see how I can get PlatformIO Espressif 8266 library back to version 1.5.0
  • Loading branch information
TD-er authored and psy0rz committed Jan 25, 2018
1 parent 8aea298 commit c149888
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 101 deletions.
8 changes: 4 additions & 4 deletions lib/IRremoteESP8266/IRKelvinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ bool ICACHE_FLASH_ATTR IRKelvinatorAC::getPower() {

// Set the temp. in deg C
void ICACHE_FLASH_ATTR IRKelvinatorAC::setTemp(uint8_t temp) {
temp = max(KELVINATOR_MIN_TEMP, temp);
temp = min(KELVINATOR_MAX_TEMP, temp);
temp = max(static_cast<uint8_t>(KELVINATOR_MIN_TEMP), temp);
temp = min(static_cast<uint8_t>(KELVINATOR_MAX_TEMP), temp);
remote_state[1] = (remote_state[1] & 0xF0U) | (temp - KELVINATOR_MIN_TEMP);
remote_state[9] = remote_state[1]; // Duplicate to the 2nd command chunk.
}
Expand All @@ -106,12 +106,12 @@ uint8_t ICACHE_FLASH_ATTR IRKelvinatorAC::getTemp() {

// Set the speed of the fan, 0-5, 0 is auto, 1-5 is the speed
void ICACHE_FLASH_ATTR IRKelvinatorAC::setFan(uint8_t fan) {
fan = min(KELVINATOR_FAN_MAX, fan); // Bounds check
fan = min(static_cast<uint8_t>(KELVINATOR_FAN_MAX), fan); // Bounds check

// Only change things if we need to.
if (fan != getFan()) {
// Set the basic fan values.
uint8_t fan_basic = min(KELVINATOR_BASIC_FAN_MAX, fan);
uint8_t fan_basic = min(static_cast<uint8_t>(KELVINATOR_BASIC_FAN_MAX), fan);
remote_state[0] = (remote_state[0] & KELVINATOR_BASIC_FAN_MASK) |
(fan_basic << KELVINATOR_FAN_OFFSET);
remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk.
Expand Down
6 changes: 3 additions & 3 deletions lib/IRremoteESP8266/IRMitsubishiAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ bool ICACHE_FLASH_ATTR IRMitsubishiAC::getPower() {

// Set the temp. in deg C
void ICACHE_FLASH_ATTR IRMitsubishiAC::setTemp(uint8_t temp) {
temp = max(MITSUBISHI_AC_MIN_TEMP, temp);
temp = min(MITSUBISHI_AC_MAX_TEMP, temp);
temp = max(static_cast<uint8_t>(MITSUBISHI_AC_MIN_TEMP), temp);
temp = min(static_cast<uint8_t>(MITSUBISHI_AC_MAX_TEMP), temp);
remote_state[7] = temp - MITSUBISHI_AC_MIN_TEMP;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ void ICACHE_FLASH_ATTR IRMitsubishiAC::setMode(uint8_t mode) {

// Set the requested vane operation mode of the a/c unit.
void ICACHE_FLASH_ATTR IRMitsubishiAC::setVane(uint8_t mode) {
mode = max(mode, B111); // bounds check
mode = max(mode, static_cast<uint8_t>(B111)); // bounds check
mode |= B1000;
mode <<= 3;
remote_state[9] |= mode;
Expand Down
14 changes: 7 additions & 7 deletions lib/IRremoteESP8266/IRremoteESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void ICACHE_FLASH_ATTR IRsend::sendNEC (unsigned long data, int nbits,
// Footer
mark(NEC_BIT_MARK);
// Gap to next command.
space(max(0, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
space(max(0ul, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));

// Optional command repeat sequence.
for (unsigned int i = 0; i < repeat; i++) {
Expand All @@ -164,7 +164,7 @@ void ICACHE_FLASH_ATTR IRsend::sendNEC (unsigned long data, int nbits,
space(NEC_RPT_SPACE);
mark(NEC_BIT_MARK);
// Gap till next command.
space(max(0, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
space(max(0ul, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ void ICACHE_FLASH_ATTR IRsend::sendSony(unsigned long data, int nbits,
// Footer
// The Sony protocol requires us to wait 45ms from start of a code to the
// start of the next one. A 10ms minimum gap is also required.
space(max(10000, 45000 - usecs.elapsed()));
space(max(10000u, 45000 - usecs.elapsed()));
}
// A space() is always performed last, so no need to turn off the LED.
}
Expand Down Expand Up @@ -367,7 +367,7 @@ void ICACHE_FLASH_ATTR IRsend::sendRCMM(uint32_t data, uint8_t nbits) {
mark(RCMM_BIT_MARK);
// Protocol requires us to wait at least RCMM_RPT_LENGTH usecs from the start
// or RCMM_MIN_GAP usecs.
space(max(RCMM_RPT_LENGTH - usecs.elapsed(), RCMM_MIN_GAP));
space(max(RCMM_RPT_LENGTH - usecs.elapsed(), static_cast<uint32_t>(RCMM_MIN_GAP)));
}

void ICACHE_FLASH_ATTR IRsend::sendPanasonic(unsigned int address,
Expand Down Expand Up @@ -415,7 +415,7 @@ void ICACHE_FLASH_ATTR IRsend::sendJVC(unsigned long data, int nbits,
// Footer
mark(JVC_BIT_MARK);
// Wait till the end of the repeat time window before we send another code.
space(max(0, JVC_RPT_LENGTH - usecs.elapsed()));
space(max(0u, JVC_RPT_LENGTH - usecs.elapsed()));
usecs.reset();
}
// No need to turn off the LED as we will always end with a space().
Expand Down Expand Up @@ -647,7 +647,7 @@ void ICACHE_FLASH_ATTR IRsend::sendSherwood(unsigned long data, int nbits,
unsigned int repeat) {
// Sherwood remote codes appear to be NEC codes with a manditory repeat code.
// i.e. repeat should be >= 1.
sendNEC(data, nbits, max(1, repeat));
sendNEC(data, nbits, max(1u, repeat));
}

void ICACHE_FLASH_ATTR IRsend::sendMitsubishiAC(unsigned char data[]) {
Expand Down Expand Up @@ -911,7 +911,7 @@ bool ICACHE_FLASH_ATTR IRrecv::decode(decode_results *results,
// Nr. of ticks.
uint32_t IRrecv::ticksLow(uint32_t usecs, uint8_t tolerance) {
// max() used to ensure the result can't drop below 0 before the cast.
return((uint32_t) max(usecs * (1.0 - tolerance/100.)/USECPERTICK, 0));
return((uint32_t) max(usecs * (1.0 - tolerance/100.)/USECPERTICK, 0.0));
}

// Calculate the upper bound of the nr. of ticks.
Expand Down
123 changes: 36 additions & 87 deletions src/Misc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -733,32 +733,35 @@ boolean str2ip(const char *string, byte* IP)

/********************************************************************************************\
check the program memory hash
The const MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere... needs to remain unchanged as it will be replaced by
The const MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere... needs to remain unchanged as it will be replaced by
- 16 bytes md5 hash, followed by
- 4 * uint32_t start of memory segment 1-4
- 4 * uint32_t end of memory segment 1-4
currently there are only two segemts included in the hash. Unused segments have start adress 0.
Execution time 520kb @80Mhz: 236ms
Returns: 0 if hash compare fails, number of checked bytes otherwise.
The reference hash is calculated by a .py file and injected into the binary.
Caution: currently the hash sits in an unchecked segment. If it ever moves to a checked segment, make sure
it is excluded from the calculation !
\*********************************************************************************************/
void dump (uint32_t addr){
Serial.print (addr,HEX);
Serial.print(": ");
for (uint32_t a = addr; a<addr+16; a++)
{
Serial.print ( pgm_read_byte(a),HEX);
Serial.print (" ");
}
Serial.println("");
}
Caution: currently the hash sits in an unchecked segment. If it ever moves to a checked segment, make sure
it is excluded from the calculation !
\*********************************************************************************************/
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0)
void dump (uint32_t addr) { //Seems already included in core 2.4 ...
Serial.print (addr, HEX);
Serial.print(": ");
for (uint32_t a = addr; a < addr + 16; a++)
{
Serial.print ( pgm_read_byte(a), HEX);
Serial.print (" ");
}
Serial.println("");
}
#endif

uint32_t progMemMD5check(){
#define BufSize 10
#define BufSize 10
const char CRCdummy[16+32+1] = "MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere..."; // 16Bytes MD5, 32 Bytes Segment boundaries, 1Byte 0-termination. DO NOT MODIFY !
uint32_t calcBuffer[BufSize];
uint32_t md5NoOfBytes = 0;
uint32_t calcBuffer[BufSize];
uint32_t md5NoOfBytes = 0;
memcpy (calcBuffer,CRCdummy,16); // is there still the dummy in memory ? - the dummy needs to be replaced by the real md5 after linking.
if( memcmp (calcBuffer, "MD5_MD5_MD5_MD5_",16)==0){ // do not memcmp with CRCdummy directly or it will get optimized away.
addLog(LOG_LEVEL_INFO, F("CRC : No program memory checksum found. Check output of crc2.py"));
Expand All @@ -767,12 +770,12 @@ uint32_t progMemMD5check(){
MD5Builder md5;
md5.begin();
for (int l = 0; l<4; l++){ // check max segments, if the pointer is not 0
uint32_t *ptrStart = (uint32_t *)&CRCdummy[16+l*4];
uint32_t *ptrEnd = (uint32_t *)&CRCdummy[16+4*4+l*4];
uint32_t *ptrStart = (uint32_t *)&CRCdummy[16+l*4];
uint32_t *ptrEnd = (uint32_t *)&CRCdummy[16+4*4+l*4];
if ((*ptrStart) == 0) break; // segment not used.
for (uint32_t i = *ptrStart; i< (*ptrEnd) ; i=i+sizeof(calcBuffer)){ // "<" includes last byte
for (uint32_t i = *ptrStart; i< (*ptrEnd) ; i=i+sizeof(calcBuffer)){ // "<" includes last byte
for (int buf = 0; buf < BufSize; buf ++){
calcBuffer[buf] = pgm_read_dword((void*)i+buf*4); // read 4 bytes
calcBuffer[buf] = pgm_read_dword((uint32_t*)i+buf*4); // read 4 bytes
md5NoOfBytes+=sizeof(calcBuffer[0]);
}
md5.add((uint8_t *)&calcBuffer[0],(*ptrEnd-i)<sizeof(calcBuffer) ? (*ptrEnd-i):sizeof(calcBuffer) ); // add buffer to md5. At the end not the whole buffer. md5 ptr to data in ram.
Expand All @@ -785,11 +788,11 @@ uint32_t progMemMD5check(){
return md5NoOfBytes;
}
addLog(LOG_LEVEL_INFO, F("CRC : program checksum ...FAIL"));
return 0;
return 0;
}



/********************************************************************************************\
Save settings to SPIFFS
\*********************************************************************************************/
Expand All @@ -801,26 +804,26 @@ String SaveSettings(void)
md5.add((uint8_t *)&Settings, sizeof(Settings)-16);
md5.calculate();
md5.getBytes(Settings.md5);

String err;
err=SaveToFile((char*)FILE_CONFIG, 0, (byte*)&Settings, sizeof(struct SettingsStruct));
if (err.length())
return(err);


memcpy( SecuritySettings.ProgmemMd5, thisBinaryMd5, 16);
md5.begin();
md5.add((uint8_t *)&SecuritySettings, sizeof(SecuritySettings)-16);
md5.calculate();
md5.getBytes(SecuritySettings.md5);
err=SaveToFile((char*)FILE_SECURITY, 0, (byte*)&SecuritySettings, sizeof(struct SecurityStruct));

// dump((uint32_t)SecuritySettings.md5);
// dump((uint32_t)SecuritySettings.ProgmemMd5);
// dump((uint32_t)Settings.md5);
// dump((uint32_t)Settings.ProgmemMd5);
// dump((uint32_t)thisBinaryMd5);

return (err);
}

Expand All @@ -832,7 +835,7 @@ String LoadSettings()
String err;
uint8_t calculatedMd5[16];
MD5Builder md5;

err=LoadFromFile((char*)FILE_CONFIG, 0, (byte*)&Settings, sizeof( SettingsStruct));
if (err.length())
return(err);
Expand All @@ -843,13 +846,13 @@ String LoadSettings()
md5.getBytes(calculatedMd5);
if (memcmp (calculatedMd5, Settings.md5,16)==0){
addLog(LOG_LEVEL_INFO, F("CRC : Settings CRC ...OK"));
if (memcmp(Settings.ProgmemMd5, thisBinaryMd5, 16)!=0)
addLog(LOG_LEVEL_INFO, F("CRC : binary has changed since last save of Settings"));
if (memcmp(Settings.ProgmemMd5, thisBinaryMd5, 16)!=0)
addLog(LOG_LEVEL_INFO, F("CRC : binary has changed since last save of Settings"));
}
else{
addLog(LOG_LEVEL_ERROR, F("CRC : Settings CRC ...FAIL"));
}


err=LoadFromFile((char*)FILE_SECURITY, 0, (byte*)&SecuritySettings, sizeof( SecurityStruct));
md5.begin();
Expand All @@ -858,8 +861,8 @@ String LoadSettings()
md5.getBytes(calculatedMd5);
if (memcmp (calculatedMd5, SecuritySettings.md5, 16)==0){
addLog(LOG_LEVEL_INFO, F("CRC : SecuritySettings CRC ...OK "));
if (memcmp(SecuritySettings.ProgmemMd5,thisBinaryMd5, 16)!=0)
addLog(LOG_LEVEL_INFO, F("CRC : binary has changed since last save of Settings"));
if (memcmp(SecuritySettings.ProgmemMd5,thisBinaryMd5, 16)!=0)
addLog(LOG_LEVEL_INFO, F("CRC : binary has changed since last save of Settings"));
}
else{
addLog(LOG_LEVEL_ERROR, F("CRC : SecuritySettings CRC ...FAIL"));
Expand Down Expand Up @@ -1508,60 +1511,6 @@ uint32_t getChecksum(byte* buffer, size_t size)
}


String getDayString()
{
String reply;
if (day() < 10)
reply += F("0");
reply += day();
return reply;
}
String getMonthString()
{
String reply;
if (month() < 10)
reply += F("0");
reply += month();
return reply;
}
String getYearString()
{
String reply = String(year());
return reply;
}
String getYearStringShort()
{
String dummy = String(year());
String reply = dummy.substring(2);
return reply;
}


String getHourString()
{
String reply;
if (hour() < 10)
reply += F("0");
reply += String(hour());
return reply;
}
String getMinuteString()
{
String reply;
if (minute() < 10)
reply += F("0");
reply += minute();
return reply;
}
String getSecondString()
{
String reply;
if (second() < 10)
reply += F("0");
reply += second();
return reply;
}


/********************************************************************************************\
Parse string template
Expand Down

0 comments on commit c149888

Please sign in to comment.