Skip to content

Commit

Permalink
Logging updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
nethomas1968 authored Jun 6, 2023
1 parent 1621776 commit 0357ef5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions HanshowFlasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ int main(int argc, char** argv)
usage(argv[0]);
return 0;
}

if (debugLevel > 0) log.enable(NOSHOW_DATE_TIME); // Logger must be enabled before use. Use "true" to see date/time in the log file.

log.setLogLevel(debugLevel);
log.enable(NOSHOW_DATE_TIME); // Logger must be enabled before use. Use "true" to see date/time in the log file.

log << argv[0] << ": START" << endl;

Expand Down
4 changes: 4 additions & 0 deletions Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ class Logger {
void doLog(const char *text);
void logToConsole(bool b) { m_bLogToConsole = b; }

void setLogLevel(uint8_t l) { m_LogLevel = l; }
uint8_t getLogLevel() { return m_LogLevel; }

private:
bool checkFileExists(string filename);
const string getCurrentDateTime();

bool m_bShowDateTime;
bool m_bLogToConsole;
uint8_t m_LogLevel;
};

#endif
17 changes: 8 additions & 9 deletions MCUTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ MCUTools::MCUTools(Serial *s, uint32_t delay)

void MCUTools::flashWriteEnable() // send flash cmd 0x06 write enable to flash
{
if (m_pLogger != nullptr) *m_pLogger << "flashWriteEnable" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "flashWriteEnable" << endl;
flashByteCmd(0x06);
}

void MCUTools::flashWakeUp() // send flash cmd 0xab to wakeup flash
{
if (m_pLogger != nullptr) *m_pLogger << "flashWakeUp" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "flashWakeUp" << endl;
flashByteCmd(0xab);
}

void MCUTools::flashEraseAll()
{
if (m_pLogger != nullptr) *m_pLogger << "flashEraseAll" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "flashEraseAll" << endl;
flashByteCmd(0x60);
}

Expand Down Expand Up @@ -78,7 +78,7 @@ bool MCUTools::writeFlashBlk(uint32_t addr, unsigned char *data, uint32_t length
unsigned char val[2];
unsigned char *pkt;

if (m_pLogger != nullptr) *m_pLogger << "writeFlashBlk" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "writeFlashBlk" << endl;

flashWriteEnable();

Expand Down Expand Up @@ -119,7 +119,7 @@ void MCUTools::sectorErase(uint32_t addr)
unsigned char data[2];
unsigned char *pkt;

if (m_pLogger != nullptr) *m_pLogger << "sectorErase" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "sectorErase" << endl;

flashWriteEnable();

Expand Down Expand Up @@ -158,7 +158,7 @@ void MCUTools::flashUnlock()
unsigned char data[2];
unsigned char *pkt;

if (m_pLogger != nullptr) *m_pLogger << "flashUnlock" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "flashUnlock" << endl;

data[0] = 0x00; // cns low
pkt = sws_wr_addr(0x0d, data, 1);
Expand Down Expand Up @@ -187,7 +187,7 @@ void MCUTools::softResetMCU()
{
unsigned char data = 0x20;

if (m_pLogger != nullptr) *m_pLogger << "softResetMCU" << endl;
if (m_pLogger != nullptr && m_pLogger->getLogLevel() > 0) *m_pLogger << "softResetMCU" << endl;

if (m_pSerial->getSerial() >= 0) {
unsigned char *pkt = sws_wr_addr(0x06f, &data, 1); // Must be free'd when done.
Expand Down Expand Up @@ -229,7 +229,7 @@ void MCUTools::flashWrite(string filePath)
addr = 0;
sblk = MAX_BLOCK_SIZE; // max spi-flash fifo = 256.

cout << "Len = " << len << endl;
if (m_pLogger != nullptr) *m_pLogger << "Len = " << len << endl;

while (len > 0) {
if ((addr & 0x0FFF) == 0) {
Expand Down Expand Up @@ -276,7 +276,6 @@ void MCUTools::activate()
// 2 CPU Stop.
//ssize_t num = write(m_pSerial->getSerial(), pkt, (1+6)*10);
write(m_pSerial->getSerial(), pkt, (1+6)*10);
//cout << "activate:" << ((1+6)*10) << "/" << num << endl;
gettimeofday(&now, NULL);
tDiff = ((now.tv_sec - start.tv_sec) * 1000000 + now.tv_usec - start.tv_usec) / 1000;
loopsDone++;
Expand Down

0 comments on commit 0357ef5

Please sign in to comment.