Add updated sources of thomas.

This commit is contained in:
2023-03-29 14:32:22 +02:00
parent 49396c22ee
commit 7f23e3ea46
15 changed files with 2036 additions and 756 deletions

View File

@@ -283,24 +283,28 @@ uint8_t dcBL_restartDC(uint8_t *sendData)
uint8_t dcBL_activatBootloader(uint8_t *sendData)
{
// minimum size of sendData-buffer: 20 byte retval: length
uint8_t nn=0;
//sendData[nn++]='U'; nötig??
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]=2;
sendData[nn++]='c';
sendData[nn++]='4';
sendData[nn++]='5';
sendData[nn++]='b';
sendData[nn++]='3';
sendData[nn++]=3;
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]='U';
sendData[nn++]=0;
sendData[nn++]=0;
return nn;
}
@@ -315,9 +319,11 @@ uint8_t dcBL_getResponse(uint8_t *respBuff, bool display)
{
epi_getRawReceivedData(respBuff);
epi_clrRawReceivedString();
dcBL_writeText("dcBL gotResponse");
if (display)
{
/*
// Antwort ins Fenster schreiben:
QString tmpStr="", myStr="~~> ";
@@ -332,8 +338,8 @@ uint8_t dcBL_getResponse(uint8_t *respBuff, bool display)
myStr.append(" ");
}
dcBL_writeText(myStr);
*/
}
}
return recLen;
}
@@ -355,6 +361,10 @@ uint8_t dcBL_ChkResponse()
recLen=dcBL_getResponse(buf,0);
if (recLen==0)
return 0; // no response by now
qDebug()<<" DCBL_chkResp got answer " << recLen ;
dcBL_writeText("DCBL_chkResp got answer");
if (buf[0]==2 && buf[1]==(dcBL_LastBLcmd | 0x80) )
return 10; // OK
@@ -365,24 +375,28 @@ uint8_t dcBL_ChkResponse()
{
dcBL_writeText("error wrong length");
//exactError=1;
qDebug()<<" DCBL_chkResp wrong length ";
return 10; // OK
}
if (buf[0] !=2)
{
dcBL_writeText("error wrong start");
//exactError=2;
qDebug()<<" DCBL_chkResp wrong start ";
return 10; // OK
}
if (buf[0]==2 && buf[1]=='e' && buf[2]=='0' )
{
dcBL_writeText("error wrong crc");
//exactError=3; // DC reports wrong crc
qDebug()<<" DCBL_chkResp wrong crc";
return 1; // error
}
if (buf[0]==2 && buf[1]==dcBL_LastBLcmd )
{
dcBL_writeText("error wrong cmd");
//exactError=4; // wrong cmd
qDebug()<<" DCBL_chkResp wrong cmd";
return 10; // OK
}
//tmpStr.clear();
@@ -393,6 +407,21 @@ uint8_t dcBL_ChkResponse()
uint8_t dcBL_sendSuccess(uint8_t lastCommand)
{
// return val: 0: no response by now 1:error 10: OK
uint8_t buf[152], recLen;
recLen=dcBL_getResponse(buf,0);
if (recLen==0)
return 0; // no response by now
if (buf[0]==2 && buf[1]==(lastCommand | 0x80) )
return 10; // OK
return 1;
}
// -----------------------------------------------------------------------------------------------
// --- ATB Bin-File Handling ---------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------
@@ -502,7 +531,8 @@ static QByteArray dcBL_AtbBinFile;
static uint32_t dcBL_fileSize;
static uint16_t dcBL_nrOfBlocks;
static uint16_t dcBL_fileCrc;
static uint8_t dcBL_myBuf[257000]; // same content like "dcBL_AtbBinFile" but bytewise
//static uint8_t dcBL_myBuf[2570000]; // same content like "dcBL_AtbBinFile" but bytewise
static uint8_t dcBL_myBuf[300000]; // same content like "dcBL_AtbBinFile" but bytewise
bool dcBL_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl)
{
@@ -514,7 +544,10 @@ bool dcBL_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDisp
dcBL_AtbBinFile=readBinFile;
dcBL_fileSize=fileSize;
if (dcBL_fileSize>258048)
//if (dcBL_fileSize>258048) // 27.3.23TS woher kommt die Zahl???
// das hex file hat 278kB
// hex file nicht erlaubt???
if (dcBL_fileSize>=300000)
return false; // keep last file
ultmp=dcBL_fileSize;
ultmp %=64;
@@ -718,7 +751,7 @@ uint8_t dcBL_getFileBlock(uint16_t blockPointer, uint8_t *buf)
/*
// Kontrolle:
qDebug()<<"dcBL_getFileBlock myBuf: ";
qDebug()<<"dcBL getFileBlock myBuf: ";
int ii=0;
do
{
@@ -729,7 +762,7 @@ uint8_t dcBL_getFileBlock(uint16_t blockPointer, uint8_t *buf)
} while (ii<64);
qDebug()<<"dcBL_getFileBlock myBuf: ";
qDebug()<<"dcBL getFileBlock myBuf: ";
ii=0;
do
{
@@ -809,7 +842,6 @@ QString dcBL_readText(void)
// -------------------------------------------------------------------------
static uint8_t dcBL_step, dcBL_state;
static uint16_t dcBL_BlkCtr, dcBL_cyclCtr, repeatCtr;
@@ -826,8 +858,8 @@ void dcBL_iniChain(void)
pBlResp=0;
for (nn=0;nn<SIZEBLRESP; nn++)
BlResp[nn]="";
dcBL_writeText("**CLEAR**");
//dcBL_writeText("**CLEAR**");
dcBL_writeText("bl chain ini");
}
uint8_t dcBL_startChain(void)
@@ -836,13 +868,15 @@ uint8_t dcBL_startChain(void)
{
dcBL_iniChain();
dcBL_step=1;
epi_clrRawReceivedString();
//epi_clrRawReceivedString();
qDebug()<<"starting chain...";
//qDebug()<<pBlResp;
dcBL_writeText("bl chain start");
}
return 0;
}
uint8_t dcBL_runChain(void)
{
// starting BL
@@ -857,17 +891,14 @@ uint8_t dcBL_runChain(void)
QString tmpStr="";
uint8_t buf[70], sendBuf[160], len, sendLen, gotResp; //, uit8tmp; //, recLen; recBuff[160], ii,
uint8_t buf[70], sendBuf[160], len, sendLen, gotResp, ii, uit8tmp;
//static uint8_t lastBlkLength;
QString stemp=" ";
uint32_t ultmp;
bool ret;
//uint8_t recLen, recBuff[160], ;
//recLen=dcBL_getResponse(recBuff, (dcBL_step<=11)?1:0); // reads all responses
// Antwort nur bis step 11 anzeigen
// wird schon in dcBL_responseOK() gelesen
gotResp=dcBL_ChkResponse();
gotResp=dcBL_ChkResponse(); //zum test hier raus, unten gehts nicht, darf nur 1x
switch (dcBL_step)
{
@@ -904,6 +935,7 @@ uint8_t dcBL_runChain(void)
case 5: // wait for answer: 2 99 52 53 98 51 3
// Problem: kommt von app, nicht vom BL. Also wenn BL schon aktiv ist dann gehts nicht
/*
dcBL_cyclCtr++;
if (recLen>6 && recBuff[0]==2 && recBuff[1]==99 && recBuff[2]==52)
@@ -922,7 +954,7 @@ uint8_t dcBL_runChain(void)
dcBL_state=3;
dcBL_step=0; // stop chain
return 0;
}*/
} */
dcBL_step++;
repeatCtr=0;
@@ -1002,49 +1034,15 @@ uint8_t dcBL_runChain(void)
dcBL_step=0; // stop chain
}
break;
/*
case 10: // send length and crc
len=dcBL_getAtbFileHeader(buf);
sendWRcmd_setSendBlock160(len, buf);
dcBL_writeText("sending header");
dcBL_BlkCtr=0; // normal 0
dcBL_cyclCtr=0;
dcBL_step++;
break;
case 11: // wait for answer 2 178 102 105 3
if (gotResp==ISOK)
{
dcBL_step++;
repeatCtr=0;
return 0;
} else
if (gotResp==ISWRONG)
{
if (++repeatCtr<3)
{
dcBL_step--;
} else
{
dcBL_step=0; // stop chain
}
}
if (++dcBL_cyclCtr>10)
{
dcBL_writeText("cancel");
dcBL_step=0; // stop chain
}
break;
*/
case 12: // send binary 64 byte wise
len=dcBL_getFileBlock(dcBL_BlkCtr, buf); // read from file, len = 0...64
//lastBlkLength=len; // recognize last block or end
sendLen=dcBL_prepareDC_BLcmd(0x22, len, buf, sendBuf); // pack into protocol frame
/*
// Kontrolle:
qDebug()<<"dcBL sending: ";
ii=0;
@@ -1056,7 +1054,7 @@ uint8_t dcBL_runChain(void)
qDebug() << stemp << " "; // Anzeige in hex
} while (ii<100);
*/
sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes
delay(100);
@@ -1174,12 +1172,199 @@ uint8_t dcBL_runChain(void)
case 18:
dcBL_step=0;
break;
}
return 0;
}
void dcBL_iniLoading(void)
{
dcBL_iniChain();
}
void dcBL_startLoading(void)
{
if (dcBL_step==0 || dcBL_step>17)
{
//dcBL_iniChain();
dcBL_step=1;
//epi_clrRawReceivedString();
qDebug()<<"DCBL start sending hexfile...";
dcBL_writeText("DCBL start sending hexfile...");
dcBL_BlkCtr=0;
dcBL_cyclCtr=0;
}
}
uint8_t dcBL_sendHexfile(void)
{
QString tmpStr="";
uint8_t buf[70], sendBuf[160], len, sendLen, gotResp; //, recLen; recBuff[160], ii,
QString stemp=" ";
uint32_t ultmp;
uint8_t uit8tmp, ii;
gotResp=dcBL_ChkResponse();
switch (dcBL_step)
{
case 1: // send start address
if (dcBL_BlkCtr==0 || dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096)
{
ultmp=uint32_t(dcBL_BlkCtr);
ultmp*=64;
len=dcBL_sendFlashStartAddr2BL(ultmp, buf);
sendWRcmd_setSendBlock160(len, buf);
qDebug()<<" DCBL_CYCL_sending HexFile address ";
dcBL_writeText("sending addr");
dcBL_step++;
return 0;
} else
dcBL_step=12;
break;
case 2: // wait for answer 2 161 68 59 3
if (gotResp==ISOK)
{
dcBL_step=12; // Header nicht senden, unnötig
dcBL_BlkCtr=0; // 0
repeatCtr=0;
return 0;
} else
if (gotResp==ISWRONG)
{
if (++repeatCtr<3)
{
dcBL_step--;
} else
{
dcBL_step=0; // stop chain
qDebug()<<" DCBL_CYCL_got wrong resp to addr";
dcBL_writeText("wrong resp");
}
}
if (++dcBL_cyclCtr>100)
{
dcBL_writeText("cancel");
qDebug()<<" DCBL_CYCL_step 2 got NO resp to addr";
dcBL_step=0; // stop chain
}
break;
case 12: // send binary 64 byte wise
len=dcBL_getFileBlock(dcBL_BlkCtr, buf); // read from file, len = 0...64
//lastBlkLength=len; // recognize last block or end
sendLen=dcBL_prepareDC_BLcmd(0x22, len, buf, sendBuf); // pack into protocol frame
// Kontrolle:
qDebug()<<"dcBL sending: ";
ii=0;
do
{
uit8tmp=(uint8_t)sendBuf[ii++];
//qDebug() << uit8tmp << " "; // Anzeige in dez
stemp.setNum(uit8tmp,16);
qDebug() << stemp << " "; // Anzeige in hex
} while (ii<100);
sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes
delay(100);
dcBL_writeText("blk nr: ");
tmpStr.setNum(dcBL_BlkCtr);
dcBL_writeText(tmpStr);
delay(100);
qDebug()<<"DCBL sending blk nr: " << dcBL_BlkCtr;
dcBL_cyclCtr=0;
dcBL_BlkCtr++;
dcBL_step++;
break;
case 13: // wait for answer 2 162 116 88 3
if (gotResp==ISOK)
{
// check if next address is needed (every 1024Blocks = 65536bytes)
if (dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096)
{
dcBL_step=8;
return 0;
}
// check for EOF:
if (dcBL_BlkCtr >= dcBL_nrOfBlocks)
{
dcBL_writeText("last block successful sent...");
dcBL_step++; // stop chain
dcBL_state=3; // transmission SUCCESSFUL
return 0;
}
dcBL_state=2; // transmission started
dcBL_step--; // send next data block
repeatCtr=0;
return 0;
}
if (gotResp==ISWRONG)
{
if (++repeatCtr<3)
{
dcBL_writeText("error");
dcBL_BlkCtr--;
dcBL_step--; // send same block again
} else
{
dcBL_step=0; // stop chain
}
}
if (++dcBL_cyclCtr>30) // longer TO due to flashing
{
dcBL_writeText("cancel");
dcBL_step=0; // stop chain
}
break;
case 14: //
dcBL_writeText("finish writing flash");
len=dcBL_writeLastPage(buf); // nur zur Sicherheit
sendWRcmd_setSendBlock160(len, buf);
dcBL_step++;
break;
case 15: // wait for answer
if (gotResp==ISOK)
{
dcBL_step++;
repeatCtr=0;
return 0;
} else
if (gotResp==ISWRONG)
{
if (++repeatCtr>3)
{
dcBL_step--;
}
}
if (++dcBL_cyclCtr>10)
{
dcBL_writeText("cancel");
dcBL_step=0; // stop chain
}
break;
}
return 0;
}
uint8_t dcBL_getResult(void)
{
// call after every step to what's going on....
@@ -1190,6 +1375,9 @@ uint8_t dcBL_getResult(void)
return dcBL_state;
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
static uint8_t Sdata_rawData[RAW_BL_DATALEN];
@@ -1204,6 +1392,8 @@ void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData)
Sdata_LengthRawData=RAW_BL_DATALEN;
for (nn=0; nn<Sdata_LengthRawData; nn++)
Sdata_rawData[nn]=receivedData[nn];
qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)";
}
uint8_t epi_getRawReceivedData(uint8_t *receivedData)
@@ -1230,8 +1420,8 @@ QString epi_getRawReceivedString()
QString myString=nullptr, tmpStr=nullptr;
myString.clear();
//if (Sdata_LengthRawData==0)
// return myString;
if (Sdata_LengthRawData==0)
return myString;
for (nn=0; nn<Sdata_LengthRawData; nn++)
{