ok
Actually in my GUI I have two button connect and disconnect on connect it will start writing to file and on disconnect it will stop.
I have the Structure also
Below is the code for Write File
void ui_logging::log_report()
{
int index = 0;
stream << "ECU->USS\n";
stream <<"Sensor"<<" "<<"Time"<<" "<<"Data"<<endl;
for(int i = 0;i<12;i++)
{
stream << "USS"<<i+1<<" ";
stream<<time_log_ecu2uss[i];
if(i<9)
{
stream<<" ";
}
else
{
stream<<" ";
}
for(int j = 0;j<4;j++)
{
stream<<
("0x"+QString::number(Data_ecu2uss
[index
],
16));
if(j<3)
{
stream<<" ";
}
index++;
}
stream<<endl;
}
index = 0 ;
stream << "USS->ECU\n";
stream <<"Sensor"<<" "<<"Time"<<" "<<"Data"<<endl;
for(int i = 0;i<12;i++)
{
stream << "USS"<<i+1<<" ";
stream<<time_log_uss2ecu[i];
if(i<9)
{
stream<<" ";
}
else
{
stream<<" ";
}
for(int j = 0;j<4;j++)
{
stream<<
("0x"+QString::number(Data_uss2ecu
[index
],
16));
if(j<3)
{
stream<<" ";
}
index++;
}
stream<<endl;
}
stream<<"******************************************************************"<<endl;
}
void ui_logging::log_report()
{
QTextStream stream(file);
int index = 0;
stream << "ECU->USS\n";
stream <<"Sensor"<<" "<<"Time"<<" "<<"Data"<<endl;
for(int i = 0;i<12;i++)
{
stream << "USS"<<i+1<<" ";
stream<<time_log_ecu2uss[i];
if(i<9)
{
stream<<" ";
}
else
{
stream<<" ";
}
for(int j = 0;j<4;j++)
{
stream<<("0x"+QString::number(Data_ecu2uss[index],16));
if(j<3)
{
stream<<" ";
}
index++;
}
stream<<endl;
}
index = 0 ;
stream << "USS->ECU\n";
stream <<"Sensor"<<" "<<"Time"<<" "<<"Data"<<endl;
for(int i = 0;i<12;i++)
{
stream << "USS"<<i+1<<" ";
stream<<time_log_uss2ecu[i];
if(i<9)
{
stream<<" ";
}
else
{
stream<<" ";
}
for(int j = 0;j<4;j++)
{
stream<<("0x"+QString::number(Data_uss2ecu[index],16));
if(j<3)
{
stream<<" ";
}
index++;
}
stream<<endl;
}
stream<<"******************************************************************"<<endl;
}
To copy to clipboard, switch view to plain text mode
Where my file Look like below
ECU->USS
Sensor Time Data
USS1 12:25:15 0x0 0x0 0x0 0x0
USS2 12:25:15 0x0 0x0 0x0 0x0
USS3 12:25:15 0x0 0x0 0x0 0x0
USS4 12:25:15 0x0 0x0 0x0 0x0
USS5 12:25:15 0x0 0x0 0x0 0x0
USS6 12:25:15 0x0 0x0 0x0 0x0
USS7 12:25:15 0x0 0x0 0x0 0x0
USS8 12:25:15 0x0 0x0 0x0 0x0
USS9 12:25:15 0x0 0x0 0x0 0x0
USS10 12:25:15 0x0 0x0 0x0 0x0
USS11 12:25:15 0x0 0x0 0x0 0x0
USS12 12:25:15 0x0 0x0 0x0 0x0
USS->ECU
Sensor Time Data
USS1 12:25:15 0x0 0x0 0x0 0x0
USS2 12:25:15 0x0 0x0 0x0 0x0
USS3 12:25:15 0x0 0x0 0x0 0x0
USS4 12:25:15 0x0 0x0 0x0 0x0
USS5 12:25:15 0x0 0x0 0x0 0x0
USS6 12:25:15 0x0 0x0 0x0 0x0
USS7 12:25:15 0x0 0x0 0x0 0x0
USS8 12:25:15 0x0 0x0 0x0 0x0
USS9 12:25:15 0x0 0x0 0x0 0x0
USS10 12:25:15 0x0 0x0 0x0 0x0
USS11 12:25:15 0x0 0x0 0x0 0x0
USS12 12:25:15 0x0 0x0 0x0 0x0
************************************************** ****************
ECU->USS
Sensor Time Data
USS1 12:25:16 0x0 0x0 0x0 0x0
USS2 12:25:16 0x0 0x0 0x0 0x0
USS3 12:25:16 0x0 0x0 0x0 0x0
USS4 12:25:16 0x0 0x0 0x0 0x0
USS5 12:25:16 0x0 0x0 0x0 0x0
USS6 12:25:16 0x0 0x0 0x0 0x0
USS7 12:25:16 0x0 0x0 0x0 0x0
USS8 12:25:16 0x0 0x0 0x0 0x0
USS9 12:25:16 0x0 0x0 0x0 0x0
USS10 12:25:16 0x0 0x0 0x0 0x0
USS11 12:25:16 0x0 0x0 0x0 0x0
USS12 12:25:16 0x0 0x0 0x0 0x0
USS->ECU
Sensor Time Data
USS1 12:25:16 0x0 0x0 0x0 0x0
USS2 12:25:16 0x0 0x0 0x0 0x0
USS3 12:25:16 0x0 0x0 0x0 0x0
USS4 12:25:16 0x0 0x0 0x0 0x0
USS5 12:25:16 0x0 0x0 0x0 0x0
USS6 12:25:16 0x0 0x0 0x0 0x0
USS7 12:25:16 0x0 0x0 0x0 0x0
USS8 12:25:16 0x0 0x0 0x0 0x0
USS9 12:25:16 0x0 0x0 0x0 0x0
USS10 12:25:16 0x0 0x0 0x0 0x0
USS11 12:25:16 0x0 0x0 0x0 0x0
USS12 12:25:16 0x0 0x0 0x0 0x0
************************************************** ****************
It will write until and unless I stop the button
Now I have two button called Read_up2down which will read the data from USS1 to USS12 on every click and Read_down2up which will read the data from USS12 to USS1 and rest element has to be ignored.
I am able to read data from USS1 to USS12 but not from USS12 to USS1
Below is the code for Read_up2down
void ui_logging::Read_up2down()
{
count++;
//get position of file
if(!flag_Position)
{
in.seek(n);
}
for( i = 0;i<4;i++)//Ignore the unused data
{
in>>str1;
qDebug()<<str1;
}
for(int i = 0;i<72;i++)//Get the used data first time
{
in>>str[i];
qDebug()<<str[i];
}
if(count == 2)//ignore the *** every time
{
in>>str1;
qDebug()<<str1;
count = 0;
}
n = in.pos();
in.skipWhiteSpace();
flag_Position = false;
}
void ui_logging::Read_up2down()
{
count++;
QTextStream in(file);
//get position of file
if(!flag_Position)
{
in.seek(n);
}
for( i = 0;i<4;i++)//Ignore the unused data
{
in>>str1;
qDebug()<<str1;
}
for(int i = 0;i<72;i++)//Get the used data first time
{
in>>str[i];
qDebug()<<str[i];
}
if(count == 2)//ignore the *** every time
{
in>>str1;
qDebug()<<str1;
count = 0;
}
n = in.pos();
in.skipWhiteSpace();
flag_Position = false;
}
To copy to clipboard, switch view to plain text mode
O/p:
1st Click
"ECU->USS"
"Sensor"
"Time"
"Data"
"USS1"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS2"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS3"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS4"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS5"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS6"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS7"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS8"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS9"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS10"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS11"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS12"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
2nd Click
"USS->ECU"
"Sensor"
"Time"
"Data"
"USS1"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS2"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS3"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS4"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS5"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS6"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS7"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS8"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS9"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS10"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS11"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"USS12"
"12:25:15"
"0x0"
"0x0"
"0x0"
"0x0"
"************************************************* *****************"
and so on...
Bookmarks