image start offset
This commit is contained in:
@ -55,7 +55,7 @@ typedef int32_t https_client_ret_t;
|
||||
typedef struct HTTPS_Client HTTPS_Client_t;
|
||||
|
||||
https_client_ret_t https_clientInitialize();
|
||||
https_client_ret_t https_clientRetrieveData();
|
||||
https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32BytesRead);
|
||||
https_client_ret_t https_clientDeinitialize();
|
||||
|
||||
#endif /* H_HTTPS_CLIENT */
|
||||
|
@ -15,7 +15,8 @@
|
||||
|
||||
#include "https_client.h"
|
||||
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
|
||||
|
||||
esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
|
||||
|
||||
#endif /* H_MESH_OTA */
|
||||
|
@ -6,37 +6,147 @@
|
||||
* 999.999.999
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote){
|
||||
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote) {
|
||||
|
||||
char u8LocalTmp[12];
|
||||
char u8RemoteTmp[12];
|
||||
|
||||
|
||||
char* pu8saveptrLocal;
|
||||
char* pu8saveptrRemote;
|
||||
|
||||
|
||||
strcpy(u8LocalTmp, pu8Local);
|
||||
strcpy(u8RemoteTmp, pu8Remote);
|
||||
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptrLocal);
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote) ;
|
||||
|
||||
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
|
||||
uint8_t u8Index = 0;
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false)){
|
||||
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false)) {
|
||||
|
||||
u8Index++;
|
||||
|
||||
|
||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||
{
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
|
||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal);
|
||||
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote) ;
|
||||
}
|
||||
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
|
||||
{
|
||||
/*
|
||||
Offset value
|
||||
0 = E9
|
||||
48 = first digit of version number
|
||||
*/
|
||||
|
||||
esp_err_t errReturn = ESP_OK;
|
||||
|
||||
*pu32StartOffset = 0U;
|
||||
|
||||
uint32_t u32DataIndex = 0;
|
||||
uint32_t u32FirstDotOffset = 0;
|
||||
uint32_t u32SecondDotOffset = 0;
|
||||
uint8_t u8FirstDotIndex = 0;
|
||||
uint8_t u8SecondDotIndex = 0;
|
||||
|
||||
while((u32DataIndex < *pu32DataLenght) && (*pu32StartOffset == 0))
|
||||
{
|
||||
//search for magic byte
|
||||
|
||||
if(pu8Data[u32DataIndex] == 0xe9)
|
||||
{
|
||||
//magic byte found
|
||||
|
||||
printf("\n magic byte found: %i\n", u32DataIndex);
|
||||
|
||||
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
|
||||
{
|
||||
//search first dot in version number
|
||||
if((u32DataIndex+49+u8FirstDotIndex) < *pu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
||||
{
|
||||
//first do found
|
||||
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
|
||||
printf("First dot offset: %i\n", u32FirstDotOffset);
|
||||
}
|
||||
}
|
||||
u8FirstDotIndex++;
|
||||
}
|
||||
|
||||
while ((u8SecondDotIndex < 3) && (u32SecondDotOffset == 0) && (u32FirstDotOffset != 0))
|
||||
{
|
||||
|
||||
//search first dot in version number
|
||||
if((u32FirstDotOffset+(u8SecondDotIndex+1)) < *pu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32FirstDotOffset+(u8SecondDotIndex+1))] == 0x2e))
|
||||
{
|
||||
//second do found
|
||||
u32SecondDotOffset = (u32FirstDotOffset+(u8SecondDotIndex+1));
|
||||
printf("Second dot offset: %i\n", u32SecondDotOffset);
|
||||
}
|
||||
}
|
||||
u8SecondDotIndex++;
|
||||
}
|
||||
|
||||
if((u32FirstDotOffset != 0) && (u32SecondDotOffset != 0))
|
||||
{
|
||||
//image start found based on magic byte and version number systax
|
||||
*pu32StartOffset = u32DataIndex; //store image start offset
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is propably not the magic byte --> reset
|
||||
u32FirstDotOffset = 0;
|
||||
u32SecondDotOffset = 0;
|
||||
u8FirstDotIndex = 0;
|
||||
u8SecondDotIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
u32DataIndex++;
|
||||
//putchar(pu8Data[i]);
|
||||
printf("%x ", pu8Data[u32DataIndex]);
|
||||
}
|
||||
|
||||
if(*pu32StartOffset == 0)
|
||||
{
|
||||
errReturn = ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
return errReturn;
|
||||
}
|
||||
|
||||
esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
|
||||
{
|
||||
strcpy(pc8RemoteVersionNumber, "999.999.999"); //init value
|
||||
|
||||
uint32_t u32StartOffset;
|
||||
|
||||
esp_err_t err = errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset);
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
|
||||
printf("\n Image start found: %i\n", u32StartOffset);
|
||||
|
||||
//extract image version
|
||||
|
||||
printf("remote version number %s\n", pc8RemoteVersionNumber);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return err;
|
||||
}
|
144
components/mesh_ota/mesh_ota.c.orig
Normal file
144
components/mesh_ota/mesh_ota.c.orig
Normal file
@ -0,0 +1,144 @@
|
||||
#include "mesh_ota.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 999.999.999
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote) {
|
||||
|
||||
char u8LocalTmp[12];
|
||||
char u8RemoteTmp[12];
|
||||
|
||||
char* pu8saveptrLocal;
|
||||
char* pu8saveptrRemote;
|
||||
|
||||
strcpy(u8LocalTmp, pu8Local);
|
||||
strcpy(u8RemoteTmp, pu8Remote);
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptrLocal);
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote) ;
|
||||
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
uint8_t u8Index = 0;
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false)) {
|
||||
|
||||
u8Index++;
|
||||
|
||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||
{
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal);
|
||||
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote) ;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
|
||||
{
|
||||
|
||||
*pu32StartOffset = 0U;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
0 = E9
|
||||
48 = erstes Digit
|
||||
|
||||
*/
|
||||
|
||||
uint32_t u32DataIndex = 0;
|
||||
|
||||
uint32_t u32FirstDotOffset = 0;
|
||||
uint32_t u32SecondDotOffset = 0;
|
||||
|
||||
uint8_t u8FirstDotIndex = 0;
|
||||
uint8_t u8SecondDotIndex = 0;
|
||||
|
||||
while((u32DataIndex < *pu32DataLenght) && (*pu32StartOffset == 0))
|
||||
{
|
||||
//search for magic byte
|
||||
u32DataIndex++;
|
||||
if(pu8Data[u32DataIndex] == 0xe9)
|
||||
{
|
||||
//magic byte found
|
||||
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
|
||||
{
|
||||
//search first dot in version number
|
||||
u8FirstDotIndex++;
|
||||
if((u32DataIndex+49+u8FirstDotIndex) > pu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
||||
{
|
||||
//first do found
|
||||
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
|
||||
printf("First dot offset: %i\n", u32FirstDotOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ((u8SecondtDotIndex < 3) && (u32SecondDotOffset == 0) && (u32FirstDotOffset != 0))
|
||||
{
|
||||
u8FSecondDotIndex++;
|
||||
//search first dot in version number
|
||||
if((u32FirstDotOffset+(u8FSecondDotIndex+1)) > pu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32FirstDotOffset+(u8FSecondDotIndex+1))] == 0x2e))
|
||||
{
|
||||
//second do found
|
||||
u32SecondDotOffset = (u32FirstDotOffset+(u8FSecondDotIndex+1));
|
||||
printf("Second dot offset: %i\n", u32SecondDotOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((u32FirstDotOffset != 0) && (u32SecondDotOffset != 0))
|
||||
{
|
||||
//image start found based on magic byte and version number systax
|
||||
*pu32StartOffset = u32DataIndex; //store image start offset
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is propably not the magic byte --> reset
|
||||
u32FirstDotOffset = 0;
|
||||
u32SecondDotOffset = 0;
|
||||
|
||||
u8FirstDotIndex = 0;
|
||||
u8SecondDotIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//putchar(pu8Data[i]);
|
||||
printf("%x ", pu8Data[u32DataIndex]);
|
||||
}
|
||||
|
||||
printf("\n END: %i\n", *pu32StartOffset);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
|
||||
{
|
||||
strcpy(pc8RemoteVersionNumber, "999.999.999"); //init value
|
||||
|
||||
uint32_t u32StartOffset;
|
||||
|
||||
errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset);
|
||||
|
||||
|
||||
printf("remote version number %s\n", pc8RemoteVersionNumber);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
Reference in New Issue
Block a user