mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 20:56:35 +00:00
Add ArduinoHexParse library for specific page size
This commit is contained in:
parent
7ff3e22ae7
commit
8976021389
3
lib/ArduinoHexParse/README.md
Normal file
3
lib/ArduinoHexParse/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# ArduinoHexParse
|
||||||
|
|
||||||
|
Parse hex files created by Arduino for Uno/Mini/Nano
|
25
lib/ArduinoHexParse/keywords.txt
Normal file
25
lib/ArduinoHexParse/keywords.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map for ArduinoHexParse
|
||||||
|
# (esp8266)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Datatypes (KEYWORD1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
ArduinoHexParse KEYWORD1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
ArduinoHexParse KEYWORD2
|
||||||
|
ParseLine KEYWORD2
|
||||||
|
GetFlashPage KEYWORD2
|
||||||
|
GetLoadAddress KEYWORD2
|
||||||
|
IsFlashPageReady KEYWORD2
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants (LITERAL1)
|
||||||
|
#######################################
|
||||||
|
|
12
lib/ArduinoHexParse/library.json
Normal file
12
lib/ArduinoHexParse/library.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "ArduinoHexParse",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Parse hex files created by Arduino for Uno/Mini/Nano",
|
||||||
|
"repository":
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/arendst/Sonoff-Tasmota/lib/ArduinoHexParse"
|
||||||
|
},
|
||||||
|
"frameworks": "arduino",
|
||||||
|
"platforms": "espressif8266"
|
||||||
|
}
|
9
lib/ArduinoHexParse/library.properties
Normal file
9
lib/ArduinoHexParse/library.properties
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
name=ArduinoHexParse
|
||||||
|
version=0.0.1
|
||||||
|
author=Andre Thomas
|
||||||
|
maintainer=Andre Thomas <andre1024@gmail.com>
|
||||||
|
sentence=Parse hex files created by Arduino for Uno/Mini/Nano
|
||||||
|
paragraph=
|
||||||
|
category=Signal Input/Output
|
||||||
|
url=
|
||||||
|
architectures=esp8266
|
134
lib/ArduinoHexParse/src/ArduinoHexParse.cpp
Normal file
134
lib/ArduinoHexParse/src/ArduinoHexParse.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2019 Andre Thomas and Theo Arends
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "ArduinoHexParse.h"
|
||||||
|
|
||||||
|
ArduinoHexParse::ArduinoHexParse(void)
|
||||||
|
{
|
||||||
|
loadAddress[0] = 0;
|
||||||
|
loadAddress[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArduinoHexParse::ParseLine(byte* hexline)
|
||||||
|
{
|
||||||
|
recordType = GetRecordType(hexline);
|
||||||
|
if (0 == recordType) {
|
||||||
|
address = GetAddress(hexline);
|
||||||
|
len = GetLength(hexline);
|
||||||
|
GetData(hexline, len);
|
||||||
|
if (128 == PageMemIdx) {
|
||||||
|
if (!firstRun) {
|
||||||
|
loadAddress[1] += 0x40;
|
||||||
|
if (0 == loadAddress[1]) {
|
||||||
|
loadAddress[0] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
firstRun = false;
|
||||||
|
FlashPageReady = true;
|
||||||
|
PageMemIdx = 0;
|
||||||
|
}
|
||||||
|
nextAddress = address + len;
|
||||||
|
}
|
||||||
|
if (1 == recordType) {
|
||||||
|
EndOfFile();
|
||||||
|
FlashPageReady = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ArduinoHexParse::IsFlashPageReady(void)
|
||||||
|
{
|
||||||
|
return FlashPageReady;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte* ArduinoHexParse::GetFlashPage(void)
|
||||||
|
{
|
||||||
|
FlashPageReady = false;
|
||||||
|
return FlashPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte* ArduinoHexParse::GetLoadAddress(void)
|
||||||
|
{
|
||||||
|
return loadAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArduinoHexParse::GetLoadAddress(byte* hexline)
|
||||||
|
{
|
||||||
|
char buff[3];
|
||||||
|
buff[2] = '\0';
|
||||||
|
buff[0] = hexline[3];
|
||||||
|
buff[1] = hexline[4];
|
||||||
|
loadAddress[0] = strtol(buff, 0, 16);
|
||||||
|
buff[0] = hexline[5];
|
||||||
|
buff[1] = hexline[6];
|
||||||
|
loadAddress[1] = strtol(buff, 0, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte* ArduinoHexParse::GetData(byte* hexline, uint32_t len)
|
||||||
|
{
|
||||||
|
uint32_t start = 9;
|
||||||
|
uint32_t end = (len * 2) + start;
|
||||||
|
char buff[3];
|
||||||
|
buff[2] = '\0';
|
||||||
|
for (uint32_t x = start; x < end; x = x+2) {
|
||||||
|
buff[0] = hexline[x];
|
||||||
|
buff[1] = hexline[x+1];
|
||||||
|
FlashPage[PageMemIdx] = strtol(buff, 0, 16);
|
||||||
|
PageMemIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArduinoHexParse::EndOfFile(void)
|
||||||
|
{
|
||||||
|
loadAddress[1] += 0x40;
|
||||||
|
if (0 == loadAddress[1]) {
|
||||||
|
loadAddress[0] += 1;
|
||||||
|
}
|
||||||
|
while (128 > PageMemIdx) { // Fill the remaing space in the memory page with 0xFF
|
||||||
|
FlashPage[PageMemIdx] = 0xFF;
|
||||||
|
PageMemIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ArduinoHexParse::GetAddress(byte* hexline)
|
||||||
|
{
|
||||||
|
char buff[5];
|
||||||
|
buff[0] = hexline[3];
|
||||||
|
buff[1] = hexline[4];
|
||||||
|
buff[2] = hexline[5];
|
||||||
|
buff[3] = hexline[6];
|
||||||
|
buff[4] = '\0';
|
||||||
|
return strtol(buff, 0, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ArduinoHexParse::GetLength(byte* hexline)
|
||||||
|
{
|
||||||
|
char buff[3];
|
||||||
|
buff[0] = hexline[1];
|
||||||
|
buff[1] = hexline[2];
|
||||||
|
buff[2] = '\0';
|
||||||
|
return strtol(buff, 0, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ArduinoHexParse::GetRecordType(byte* hexline)
|
||||||
|
{
|
||||||
|
char buff[3];
|
||||||
|
buff[0] = hexline[7];
|
||||||
|
buff[1] = hexline[8];
|
||||||
|
buff[2] = '\0';
|
||||||
|
return strtol(buff, 0, 16);
|
||||||
|
}
|
47
lib/ArduinoHexParse/src/ArduinoHexParse.h
Normal file
47
lib/ArduinoHexParse/src/ArduinoHexParse.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2019 Andre Thomas and Theo Arends
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARDUINOHEXPARSE_H__
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
class ArduinoHexParse {
|
||||||
|
public:
|
||||||
|
ArduinoHexParse(void);
|
||||||
|
void ParseLine(byte* data);
|
||||||
|
byte* GetFlashPage(void);
|
||||||
|
byte* GetLoadAddress(void);
|
||||||
|
bool IsFlashPageReady(void);
|
||||||
|
private:
|
||||||
|
uint32_t address = 0;
|
||||||
|
uint32_t len = 0;
|
||||||
|
uint32_t nextAddress = 0;
|
||||||
|
uint32_t PageMemIdx = 0;
|
||||||
|
uint32_t recordType = 0;
|
||||||
|
byte FlashPage[128];
|
||||||
|
byte loadAddress[2];
|
||||||
|
bool FlashPageReady = false;
|
||||||
|
bool firstRun = true;
|
||||||
|
uint32_t GetAddress(byte* hexline);
|
||||||
|
uint16_t GetLength(byte* hexline);
|
||||||
|
uint16_t GetRecordType(byte* hexline);
|
||||||
|
byte* GetData(byte* hexline, uint32_t len);
|
||||||
|
void GetLoadAddress(byte* hexline);
|
||||||
|
void EndOfFile(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __ARDUINOHEXPARSE_H__
|
Loading…
x
Reference in New Issue
Block a user