Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added default values for FT58 and FT45 #780

Merged
merged 4 commits into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 74 additions & 17 deletions src/tools/FirmwareUpdater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <qdebug.h>
#include <QDir>


#include "firmwareupdatercore.h"

#undef UPDATER_RELEASE
Expand Down Expand Up @@ -39,9 +38,16 @@ enum action_t
action_getcanboardversion = 10,
action_savedatfile = 11,
action_changeCanId = 12,
action_changeBoardIp = 13

action_changeBoardIp = 13,
action_setstrainft45gainsoffsets = 14,
action_setstrainft58gainsoffsets = 15,
action_setstraingainsspecificoffsets = 16
};

enum class SensorModel
{
ft45,
ft58
};


Expand Down Expand Up @@ -70,7 +76,7 @@ int queryOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QSt
int loadDatFileStrain2(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,QString file,bool eraseEEprom);
int saveDatFileStrain2(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,bool eraseEEprom);
int setStrainSn(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId, QString serialNumber);
int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId);
int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,SensorModel model);
int getCanBoardVersion(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,bool save);
int changeCanId(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId, QString canIdNew);
int changeBoardIp(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString newipaddr);
Expand Down Expand Up @@ -122,6 +128,7 @@ int main(int argc, char *argv[])
QCommandLineOption loadDatFileOption(QStringList() << "z" << "load-dat-file", "Loads the calibration .dat file into STRAIN2 eeprom (pass the file.dat with -l or --file option)","","");
QCommandLineOption setStrainSnOption(QStringList() << "w" << "set-strain-sn", "Sets the passed serialNumber (i.e. SN001) on STRAIN2","sn","");
QCommandLineOption setStrainGainsOffsetOption(QStringList() << "j" << "set-strain-gains", "Sets on STRAIN2 default gains to (8,24,24,10,10,24) , adjust the offset and check if some channel saturates","","");
QCommandLineOption setStrainGainsSpecificOffsetOption(QStringList() << "3" << "set-strain-gains-specific", "Sets on STRAIN2 default gains to (8,24,24,10,10,24) or to (8,10,10,10,10,10) depending on the sensor type, adjust the offset and check if some channel saturates","xx","");
QCommandLineOption getCanBoardVersionOption(QStringList() << "b" << "get-canboard-version", "Gets Bootloader or Application version (<saveFile> must be y or n to save or not a file containing fw info)","saveFile","");
QCommandLineOption saveDatFileOption(QStringList() << "u" << "save-dat-file", "Saves the calibration .dat file from STRAIN2 eeprom","","");
QCommandLineOption changeCanIdOption(QStringList() << "k" << "change-can-id", "changes CAN ID","id-new","");
Expand Down Expand Up @@ -151,12 +158,12 @@ int main(int argc, char *argv[])
parser.addOption(loadDatFileOption);
parser.addOption(setStrainSnOption);
parser.addOption(setStrainGainsOffsetOption);
parser.addOption(setStrainGainsSpecificOffsetOption);
parser.addOption(getCanBoardVersionOption);
parser.addOption(saveDatFileOption);
parser.addOption(changeCanIdOption);
parser.addOption(changeBoardIpOption);


parser.process(a);

bool noGui = parser.isSet(noGuiOption);
Expand Down Expand Up @@ -194,10 +201,6 @@ int main(int argc, char *argv[])
//qDebug() << "Usage: " << argv[0] << " --port n --address xxx.xxx.xxx.xxx\n";
}





ResourceFinder rf;
rf.setDefaultContext("firmwareUpdater");
rf.setDefaultConfigFile(iniFile.toLatin1().data());
Expand Down Expand Up @@ -225,6 +228,11 @@ int main(int argc, char *argv[])
QString file = parser.value(fileOption);
QString canLine = parser.value(ethCanLineOption);
QString canId = parser.value(ethCanIdOption);
QString sensorModel = parser.value(setStrainGainsSpecificOffsetOption);

if(parser.isSet(setStrainGainsSpecificOffsetOption)){
if(verbosity >= 1) qDebug() << "Sensor model:" << sensorModel;
}

QString targetFW = parser.value(verifyOption);

Expand All @@ -236,6 +244,7 @@ int main(int argc, char *argv[])
bool setSn = parser.isSet(setStrainSnOption);
QString serialNumber = parser.value(setStrainSnOption);
bool setGains = parser.isSet(setStrainGainsOffsetOption);
bool setGainsSpecific = parser.isSet(setStrainGainsSpecificOffsetOption);
QString saveVersion = parser.value(getCanBoardVersionOption);
bool getVersion = parser.isSet(getCanBoardVersionOption);
bool changeCanID = parser.isSet(changeCanIdOption);
Expand Down Expand Up @@ -362,6 +371,18 @@ int main(int argc, char *argv[])
}
}

if((setGainsSpecific) && (action_impossible != action))
{
if(action == action_none)
{
action = action_setstraingainsspecificoffsets;
}
else
{
action = action_impossible;
}
}

if((getVersion) && (action_impossible != action))
{
if(action == action_none)
Expand Down Expand Up @@ -683,7 +704,35 @@ int main(int argc, char *argv[])
} else if(!device.contains("ETH") && canId.isEmpty()){
if(verbosity >= 1) qDebug() << "Need a can id to be set";
}else{
ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId);
ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId,SensorModel::ft45);
}
}

} break;

case action_setstraingainsspecificoffsets:
{
ret = 1;

if(device.isEmpty()){
if(verbosity >= 1) qDebug() << "Need a device to be set";
}else if(id.isEmpty()){
if(verbosity >= 1) qDebug() << "Need an id to be set";
}else{
if(!device.contains("ETH") && canLine.isEmpty()){
if(verbosity >= 1) qDebug() << "Need a can line to be set";
} else if(!device.contains("ETH") && canId.isEmpty()){
if(verbosity >= 1) qDebug() << "Need a can id to be set";
}else{

if(sensorModel=="FT58")
{
ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId,SensorModel::ft58);
}
else
{
ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId,SensorModel::ft45);
}
}
}

Expand Down Expand Up @@ -1029,7 +1078,9 @@ int getCanBoardVersion(FirmwareUpdaterCore *core,QString device,QString id,QStri
return -1;
}

int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId)


int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,SensorModel model)
{
//10-2020 - davide.tome@iit.it
//This method is used to set the PGA gains to
Expand All @@ -1041,12 +1092,18 @@ int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QS
string msg;
std::vector<strain2_ampl_discretegain_t> gains(0);
std::vector<int16_t> targets(0);
const strain2_ampl_discretegain_t ampsets[6] =
{
ampl_gain08, ampl_gain24, ampl_gain24,
ampl_gain10, ampl_gain10, ampl_gain24
};


std::vector<strain2_ampl_discretegain_t> ampsets = {
ampl_gain08, ampl_gain24, ampl_gain24,
ampl_gain10, ampl_gain10, ampl_gain24};

if (model == SensorModel::ft45) {
ampsets = {ampl_gain08, ampl_gain24, ampl_gain24,
ampl_gain10, ampl_gain10, ampl_gain24};
} else {
ampsets = {ampl_gain08, ampl_gain10, ampl_gain10,
ampl_gain10, ampl_gain10, ampl_gain10};
}

for(int i = 0; i < 6; i++){ targets.push_back(0); gains.push_back(ampsets[i]);}

Expand Down