Projectkk2glider/companion archive support (#4017)
* Files moved to thirdparty directory * Miniz library added * Unused simulators removed: er9x, th9x, ersky9x * Example of opening archive file .eepe2 (File->Open) * File reorganization, bunch of files moved to storage directory * Added StorageSdcard class to handle storage for radios that use SD card to store radio settings and models
This commit is contained in:
committed by
Bertrand Songis
parent
fb27acf286
commit
60524f77f0
@@ -0,0 +1,26 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(storage_NAMES
|
||||
storage_eeprom
|
||||
storage_sdcard
|
||||
hexinterface
|
||||
# xmlinterface
|
||||
mountlist
|
||||
rlefile
|
||||
appdata
|
||||
firmwareinterface
|
||||
)
|
||||
|
||||
set(storage_SRCS
|
||||
)
|
||||
|
||||
set(storage_HDRS
|
||||
)
|
||||
|
||||
foreach(name ${storage_NAMES})
|
||||
set(storage_SRCS ${storage_SRCS} ${name}.cpp)
|
||||
set(storage_HDRS ${storage_HDRS} ${name}.h)
|
||||
endforeach()
|
||||
|
||||
add_library(storage ${storage_SRCS})
|
||||
target_link_libraries(storage Qt5::Core Qt5::Gui Qt5::Xml Qt5::Widgets)
|
||||
@@ -0,0 +1,800 @@
|
||||
/*
|
||||
* Author - Kjell Kernen
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "appdata.h"
|
||||
|
||||
// Global data and storage object
|
||||
AppData g;
|
||||
|
||||
// ** CompStoreObj class********************
|
||||
void CompStoreObj::clear (const QString tag1, const QString tag2, const QString tag3)
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (tag2.isEmpty())
|
||||
{
|
||||
settings.remove(tag1);
|
||||
}
|
||||
else if (tag3.isEmpty())
|
||||
{
|
||||
settings.beginGroup(tag1);
|
||||
settings.remove(tag2);
|
||||
settings.endGroup();
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.beginGroup(tag1);
|
||||
settings.beginGroup(tag2);
|
||||
settings.remove(tag3);
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void CompStoreObj::store(const QByteArray newArray, QByteArray &array, const QString tag, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
settings.setValue(tag, newArray);
|
||||
array = newArray;
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::store(const QStringList newSList, QStringList &stringList, const QString tag, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
settings.setValue(tag, newSList);
|
||||
stringList = newSList;
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::store(const QString newString, QString &string, const QString tag, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
settings.setValue(tag, newString);
|
||||
string = newString;
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::store(const bool newTruth, bool &truth, const QString tag, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
settings.setValue(tag, newTruth);
|
||||
truth = newTruth;
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::store(const int newNumber, int &number, const QString tag, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
settings.setValue(tag, newNumber);
|
||||
number = newNumber;
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
// Retrieval functions
|
||||
void CompStoreObj::retrieve( QByteArray &array, const QString tag, const QString def, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
array = settings.value(tag, def).toByteArray();
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::retrieve( QStringList &stringList, const QString tag, const QString def, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
stringList = settings.value(tag, def).toStringList();
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::retrieve( QString &string, const QString tag, const QString def, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
string = settings.value(tag, def).toString();
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::retrieve( bool &truth, const QString tag, const bool def, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
truth = settings.value(tag, def).toBool();
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
void CompStoreObj::retrieve( int &number, const QString tag, const int def, const QString group1, const QString group2 )
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!group1.isEmpty()) settings.beginGroup(group1);
|
||||
if (!group2.isEmpty()) settings.beginGroup(group2);
|
||||
|
||||
number = settings.value(tag, def).toInt();
|
||||
|
||||
if (!group1.isEmpty()) settings.endGroup();
|
||||
if (!group2.isEmpty()) settings.endGroup();
|
||||
}
|
||||
|
||||
// Retrieve and Store functions
|
||||
void CompStoreObj::getset( QByteArray &array, const QString tag, const QString def, const QString group1, const QString group2 )
|
||||
{
|
||||
retrieve( array, tag, def, group1, group2);
|
||||
store(array, array, tag, group1, group2);
|
||||
}
|
||||
|
||||
void CompStoreObj::getset( QStringList &stringList, const QString tag, const QString def, const QString group1, const QString group2 )
|
||||
{
|
||||
retrieve( stringList, tag, def, group1, group2);
|
||||
store(stringList, stringList, tag, group1, group2);
|
||||
}
|
||||
|
||||
void CompStoreObj::getset( QString &string, const QString tag, const QString def, const QString group1, const QString group2 )
|
||||
{
|
||||
retrieve( string, tag, def, group1, group2);
|
||||
store(string, string, tag, group1, group2);
|
||||
}
|
||||
|
||||
void CompStoreObj::getset( bool &truth, const QString tag, const bool def, const QString group1, const QString group2 )
|
||||
{
|
||||
retrieve( truth, tag, def, group1, group2);
|
||||
store(truth, truth, tag, group1, group2);
|
||||
}
|
||||
|
||||
void CompStoreObj::getset( int &number, const QString tag, const int def, const QString group1, const QString group2 )
|
||||
{
|
||||
retrieve( number, tag, def, group1, group2);
|
||||
store(number, number, tag, group1, group2);
|
||||
}
|
||||
|
||||
// ** FwRevision class********************
|
||||
int FwRevision::get( const QString fwType )
|
||||
{
|
||||
QString result;
|
||||
retrieve( result, fwType, "", "FwRevisions" );
|
||||
return result.toInt();
|
||||
}
|
||||
|
||||
void FwRevision::set( const QString fwType, const int fwRevision )
|
||||
{
|
||||
QString tempString = QString("%1").arg(fwRevision);
|
||||
store( tempString, tempString, fwType, "FwRevisions" );
|
||||
}
|
||||
|
||||
void FwRevision::remove( const QString tag )
|
||||
{
|
||||
clear( "FwRevisions", tag );
|
||||
}
|
||||
|
||||
// ** JStickData class********************
|
||||
// Get declarations
|
||||
int JStickData::stick_axe() { return _stickAxe; }
|
||||
int JStickData::stick_min() { return _stickMin; }
|
||||
int JStickData::stick_med() { return _stickMed; }
|
||||
int JStickData::stick_max() { return _stickMax; }
|
||||
int JStickData::stick_inv() { return _stickInv; }
|
||||
|
||||
// Set declarations
|
||||
void JStickData::stick_axe(const int it) { store( it, _stickAxe, QString("stick%1_axe").arg(index), "JsCalibration" );}
|
||||
void JStickData::stick_min(const int it) { store( it, _stickMin, QString("stick%1_min").arg(index), "JsCalibration" );}
|
||||
void JStickData::stick_med(const int it) { store( it, _stickMed, QString("stick%1_med").arg(index), "JsCalibration" );}
|
||||
void JStickData::stick_max(const int it) { store( it, _stickMax, QString("stick%1_max").arg(index), "JsCalibration" );}
|
||||
void JStickData::stick_inv(const int it) { store( it, _stickInv, QString("stick%1_inv").arg(index), "JsCalibration" );}
|
||||
|
||||
// Constructor
|
||||
JStickData::JStickData()
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
|
||||
void JStickData::remove()
|
||||
{
|
||||
// Remove all JStickData values from settings file
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
settings.beginGroup( "JsCalibration" );
|
||||
settings.remove( QString( "stick%1_axe").arg(index) );
|
||||
settings.remove( QString( "stick%1_min").arg(index) );
|
||||
settings.remove( QString( "stick%1_med").arg(index) );
|
||||
settings.remove( QString( "stick%1_max").arg(index) );
|
||||
settings.remove( QString( "stick%1_inv").arg(index) );
|
||||
settings.endGroup();
|
||||
|
||||
// Reset all JStickData variables to initial values
|
||||
init(index);
|
||||
}
|
||||
|
||||
bool JStickData::existsOnDisk()
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
settings.beginGroup("JsCalibration");
|
||||
int axe = settings.value( QString("stick%1_axe").arg(index), -1 ).toInt();
|
||||
settings.endGroup();
|
||||
|
||||
return (axe > -1);
|
||||
}
|
||||
|
||||
void JStickData::init(int newIndex)
|
||||
{
|
||||
index = newIndex;
|
||||
_stickAxe = -1;
|
||||
_stickMin = -32767;
|
||||
_stickMed = 0;
|
||||
_stickMax = 0;
|
||||
_stickInv = 0;
|
||||
|
||||
// Do not write empty joystick calibrations to disk.
|
||||
if ( !existsOnDisk() )
|
||||
return;
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
void JStickData::flush()
|
||||
{
|
||||
getset( _stickAxe, QString("stick%1_axe").arg(index), -1, "JsCalibration" );
|
||||
getset( _stickMin, QString("stick%1_min").arg(index), -32767, "JsCalibration" );
|
||||
getset( _stickMed, QString("stick%1_med").arg(index), 0, "JsCalibration" );
|
||||
getset( _stickMax, QString("stick%1_max").arg(index), 0, "JsCalibration" );
|
||||
getset( _stickInv, QString("stick%1_inv").arg(index), 0, "JsCalibration" );
|
||||
}
|
||||
|
||||
// ** Profile class********************
|
||||
// Get declarations
|
||||
QString Profile::fwName() const { return _fwName; }
|
||||
QString Profile::fwType() const { return _fwType; }
|
||||
QString Profile::name() const { return _name; }
|
||||
QString Profile::sdPath() const { return _sdPath; }
|
||||
int Profile::volumeGain() const { return _volumeGain; }
|
||||
QString Profile::pBackupDir() const { return _pBackupDir; }
|
||||
QString Profile::splashFile() const { return _splashFile; }
|
||||
bool Profile::burnFirmware() const { return _burnFirmware; }
|
||||
bool Profile::penableBackup() const { return _penableBackup; }
|
||||
bool Profile::renameFwFiles() const { return _renameFwFiles; }
|
||||
int Profile::channelOrder() const { return _channelOrder; }
|
||||
int Profile::defaultMode() const { return _defaultMode; }
|
||||
|
||||
QString Profile::beeper() const { return _beeper; }
|
||||
QString Profile::countryCode() const { return _countryCode; }
|
||||
QString Profile::display() const { return _display; }
|
||||
QString Profile::haptic() const { return _haptic; }
|
||||
QString Profile::speaker() const { return _speaker; }
|
||||
QString Profile::stickPotCalib() const { return _stickPotCalib; }
|
||||
QString Profile::timeStamp() const { return _timeStamp; }
|
||||
QString Profile::trainerCalib() const { return _trainerCalib; }
|
||||
QString Profile::controlTypes() const { return _controlTypes; }
|
||||
QString Profile::controlNames() const { return _controlNames; }
|
||||
int Profile::txCurrentCalibration() const { return _txCurrentCalibration; }
|
||||
int Profile::gsStickMode() const { return _gsStickMode; }
|
||||
int Profile::ppmMultiplier() const { return _ppmMultiplier; }
|
||||
int Profile::txVoltageCalibration() const { return _txVoltageCalibration; }
|
||||
int Profile::vBatWarn() const { return _vBatWarn; }
|
||||
int Profile::vBatMin() const { return _vBatMin; }
|
||||
int Profile::vBatMax() const { return _vBatMax; }
|
||||
|
||||
// Set declarations
|
||||
void Profile::name (const QString x) { store(x, _name, "Name" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::fwName (const QString x) { store(x, _fwName, "fwName" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::fwType (const QString x) { store(x, _fwType, "fwType" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::sdPath (const QString x) { store(x, _sdPath, "sdPath" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::volumeGain (const int x) { store(x, _volumeGain, "volumeGain" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::pBackupDir (const QString x) { store(x, _pBackupDir, "pBackupDir" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::splashFile (const QString x) { store(x, _splashFile, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::burnFirmware (const bool x) { store(x, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::renameFwFiles (const bool x) { store(x, _renameFwFiles, "rename_firmware_files" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::penableBackup (const bool x) { store(x, _penableBackup, "penableBackup" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::channelOrder (const int x) { store(x, _channelOrder, "default_channel_order" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::defaultMode (const int x) { store(x, _defaultMode, "default_mode" ,"Profiles", QString("profile%1").arg(index));}
|
||||
|
||||
void Profile::beeper (const QString x) { store(x, _beeper, "Beeper" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::countryCode (const QString x) { store(x, _countryCode, "countryCode" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::display (const QString x) { store(x, _display, "Display" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::haptic (const QString x) { store(x, _haptic, "Haptic" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::speaker (const QString x) { store(x, _speaker, "Speaker" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::stickPotCalib (const QString x) { store(x, _stickPotCalib, "StickPotCalib" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::timeStamp (const QString x) { store(x, _timeStamp, "TimeStamp" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::trainerCalib (const QString x) { store(x, _trainerCalib, "TrainerCalib" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::controlTypes (const QString x) { store(x, _controlTypes, "ControlTypes" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::controlNames (const QString x) { store(x, _controlNames, "ControlNames" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::txCurrentCalibration (const int x) { store(x, _txCurrentCalibration, "currentCalib","Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::gsStickMode (const int x) { store(x, _gsStickMode, "GSStickMode" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::ppmMultiplier (const int x) { store(x, _ppmMultiplier, "PPM_Multiplier" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::txVoltageCalibration (const int x) { store(x, _txVoltageCalibration, "VbatCalib","Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::vBatWarn (const int x) { store(x, _vBatWarn, "vBatWarn" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::vBatMin (const int x) { store(x, _vBatMin, "VbatMin" ,"Profiles", QString("profile%1").arg(index));}
|
||||
void Profile::vBatMax (const int x) { store(x, _vBatMax, "VbatMax" ,"Profiles", QString("profile%1").arg(index));}
|
||||
|
||||
// Constructor
|
||||
Profile::Profile()
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
|
||||
// The default copy operator can not be used since the index variable would be destroyed
|
||||
Profile& Profile::operator=(const Profile& rhs)
|
||||
{
|
||||
name ( rhs.name() );
|
||||
fwName ( rhs.fwName() );
|
||||
fwType ( rhs.fwType() );
|
||||
sdPath ( rhs.sdPath() );
|
||||
volumeGain ( rhs.volumeGain() );
|
||||
pBackupDir ( rhs.pBackupDir() );
|
||||
splashFile ( rhs.splashFile() );
|
||||
burnFirmware ( rhs.burnFirmware() );
|
||||
renameFwFiles( rhs.renameFwFiles() );
|
||||
penableBackup( rhs.penableBackup() );
|
||||
channelOrder ( rhs.channelOrder() );
|
||||
defaultMode ( rhs.defaultMode() );
|
||||
beeper ( rhs.beeper() );
|
||||
countryCode ( rhs.countryCode() );
|
||||
display ( rhs.display() );
|
||||
haptic ( rhs.haptic() );
|
||||
speaker ( rhs.speaker() );
|
||||
stickPotCalib( rhs.stickPotCalib() );
|
||||
trainerCalib ( rhs.trainerCalib() );
|
||||
controlTypes ( rhs.controlTypes() );
|
||||
controlNames ( rhs.controlNames() );
|
||||
txCurrentCalibration ( rhs.txCurrentCalibration() );
|
||||
gsStickMode ( rhs.gsStickMode() );
|
||||
ppmMultiplier( rhs.ppmMultiplier() );
|
||||
txVoltageCalibration ( rhs.txVoltageCalibration() );
|
||||
vBatWarn ( rhs.vBatWarn() );
|
||||
vBatMin ( rhs.vBatMin() );
|
||||
vBatMax ( rhs.vBatMax() );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Profile::remove()
|
||||
{
|
||||
// Remove all profile values from settings file
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
settings.beginGroup("Profiles");
|
||||
settings.remove(QString("profile%1").arg(index));
|
||||
settings.endGroup();
|
||||
|
||||
// Reset all profile variables to initial values
|
||||
init(index);
|
||||
}
|
||||
|
||||
bool Profile::existsOnDisk()
|
||||
{
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
settings.beginGroup("Profiles");
|
||||
settings.beginGroup(QString("profile%1").arg(index));
|
||||
QStringList keyList = settings.allKeys();
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
|
||||
return (keyList.length() > 0);
|
||||
}
|
||||
|
||||
void Profile::initFwVariables()
|
||||
{
|
||||
_beeper = "";
|
||||
_countryCode = "";
|
||||
_display = "";
|
||||
_haptic = "";
|
||||
_speaker = "";
|
||||
_stickPotCalib = "";
|
||||
_timeStamp = "";
|
||||
_trainerCalib = "";
|
||||
_controlTypes = "";
|
||||
_controlNames = "";
|
||||
|
||||
_txCurrentCalibration = 0;
|
||||
_gsStickMode = 0;
|
||||
_ppmMultiplier = 0;
|
||||
_txVoltageCalibration = 0;
|
||||
_vBatWarn = 0;
|
||||
_vBatMin = 0;
|
||||
_vBatMax = 0;
|
||||
}
|
||||
|
||||
void Profile::init(int newIndex)
|
||||
{
|
||||
index = newIndex;
|
||||
|
||||
_fwName = "";
|
||||
_fwType = "";
|
||||
_name = "";
|
||||
_sdPath = "";
|
||||
_volumeGain = 10;
|
||||
_pBackupDir = "";
|
||||
_splashFile = "";
|
||||
_burnFirmware = false;
|
||||
_renameFwFiles = false;
|
||||
_penableBackup = false;
|
||||
_channelOrder = 0;
|
||||
_defaultMode = 1;
|
||||
|
||||
initFwVariables();
|
||||
|
||||
// Do not write empty profiles to disk except the default (0) profile.
|
||||
if ( index > 0 && !existsOnDisk())
|
||||
return;
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
void Profile::flush()
|
||||
{
|
||||
// Load and store all variables. Use default values if setting values are missing
|
||||
getset( _fwName, "fwName" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _fwType, "fwType" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _name, "Name" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _sdPath, "sdPath" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _volumeGain, "volumeGain" ,10 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _pBackupDir, "pBackupDir" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _splashFile, "SplashFileName" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _burnFirmware, "burnFirmware" ,false ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _penableBackup, "penableBackup" ,false ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _renameFwFiles, "rename_firmware_files" ,false ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _channelOrder, "default_channel_order" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _defaultMode, "default_mode" ,1 ,"Profiles", QString("profile%1").arg(index));
|
||||
|
||||
getset( _beeper, "Beeper" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _countryCode, "countryCode" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _display, "Display" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _haptic, "Haptic" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _speaker, "Speaker" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _stickPotCalib, "StickPotCalib" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _timeStamp, "TimeStamp" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _trainerCalib, "TrainerCalib" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _controlTypes, "ControlTypes" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _controlNames, "ControlNames" ,"" ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _txCurrentCalibration, "currentCalib" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _gsStickMode, "GSStickMode" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _ppmMultiplier, "PPM_Multiplier" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _txVoltageCalibration, "VbatCalib" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _vBatWarn, "vBatWarn" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _vBatMin, "VbatMin" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
getset( _vBatMax, "VbatMax" ,0 ,"Profiles", QString("profile%1").arg(index));
|
||||
}
|
||||
|
||||
|
||||
// ** AppData class********************
|
||||
|
||||
// Get declarations
|
||||
QStringList AppData::recentFiles() { return _recentFiles; }
|
||||
QByteArray AppData::mainWinGeo() { return _mainWinGeo; }
|
||||
QByteArray AppData::mainWinState() { return _mainWinState; }
|
||||
QByteArray AppData::modelEditGeo() { return _modelEditGeo; }
|
||||
|
||||
QString AppData::armMcu() { return _armMcu; }
|
||||
QString AppData::avrArguments() { return _avrArguments; }
|
||||
QString AppData::avrPort() { return _avrPort; }
|
||||
QString AppData::avrdudeLocation() { return _avrdudeLocation; }
|
||||
QString AppData::dfuArguments() { return _dfuArguments; }
|
||||
QString AppData::dfuLocation() { return _dfuLocation; }
|
||||
QString AppData::locale() { return _locale; }
|
||||
QString AppData::mcu() { return _mcu; }
|
||||
QString AppData::programmer() { return _programmer; }
|
||||
QString AppData::sambaLocation() { return _sambaLocation; }
|
||||
QString AppData::sambaPort() { return _sambaPort; }
|
||||
QString AppData::lastSimulator() { return _lastSimulator; }
|
||||
|
||||
QString AppData::backupDir() { return _backupDir; }
|
||||
QString AppData::gePath() { return _gePath; }
|
||||
QString AppData::eepromDir() { return _eepromDir; }
|
||||
QString AppData::flashDir() { return _flashDir; }
|
||||
QString AppData::imagesDir() { return _imagesDir; }
|
||||
QString AppData::logDir() { return _logDir; }
|
||||
QString AppData::libDir() { return _libDir; }
|
||||
QString AppData::snapshotDir() { return _snapshotDir; }
|
||||
QString AppData::updatesDir() { return _updatesDir; }
|
||||
|
||||
bool AppData::jsSupport() { return _jsSupport; }
|
||||
bool AppData::maximized() { return _maximized; }
|
||||
bool AppData::showSplash() { return _showSplash; }
|
||||
bool AppData::snapToClpbrd() { return _snapToClpbrd; }
|
||||
bool AppData::autoCheckApp() { return _autoCheckApp; }
|
||||
bool AppData::autoCheckFw() { return _autoCheckFw; }
|
||||
bool AppData::simuSW() { return _simuSW; }
|
||||
bool AppData::useWizard() { return _useWizard; }
|
||||
|
||||
int AppData::backLight() { return _backLight; }
|
||||
int AppData::embedSplashes() { return _embedSplashes; }
|
||||
int AppData::fwServerFails() { return _fwServerFails; }
|
||||
int AppData::generalEditTab() { return _generalEditTab; }
|
||||
int AppData::iconSize() { return _iconSize; }
|
||||
int AppData::historySize() { return _historySize; }
|
||||
int AppData::jsCtrl() { return _jsCtrl; }
|
||||
int AppData::id() { return _id; }
|
||||
int AppData::theme() { return _theme; }
|
||||
int AppData::warningId() { return _warningId; }
|
||||
|
||||
// Set declarations
|
||||
void AppData::recentFiles (const QStringList x) { store(x, _recentFiles, "recentFileList" );}
|
||||
void AppData::mainWinGeo (const QByteArray x) { store(x, _mainWinGeo, "mainWindowGeometry" );}
|
||||
void AppData::mainWinState (const QByteArray x) { store(x, _mainWinState, "mainWindowState" );}
|
||||
void AppData::modelEditGeo (const QByteArray x) { store(x, _modelEditGeo, "modelEditGeometry" );}
|
||||
|
||||
void AppData::armMcu (const QString x) { store(x, _armMcu, "arm_mcu" );}
|
||||
void AppData::avrArguments (const QString x) { store(x, _avrArguments, "avr_arguments" );}
|
||||
void AppData::avrPort (const QString x) { store(x, _avrPort, "avr_port" );}
|
||||
void AppData::avrdudeLocation (const QString x) { store(x, _avrdudeLocation, "avrdudeLocation" );}
|
||||
void AppData::dfuArguments (const QString x) { store(x, _dfuArguments, "dfu_arguments" );}
|
||||
void AppData::dfuLocation (const QString x) { store(x, _dfuLocation, "dfu_location" );}
|
||||
void AppData::locale (const QString x) { store(x, _locale, "locale" );}
|
||||
void AppData::mcu (const QString x) { store(x, _mcu, "mcu" );}
|
||||
void AppData::programmer (const QString x) { store(x, _programmer, "programmer" );}
|
||||
void AppData::sambaLocation (const QString x) { store(x, _sambaLocation, "samba_location" );}
|
||||
void AppData::sambaPort (const QString x) { store(x, _sambaPort, "samba_port" );}
|
||||
void AppData::lastSimulator (const QString x) { store(x, _lastSimulator, "last_simulator" );}
|
||||
|
||||
void AppData::backupDir (const QString x) { store(x, _backupDir, "backupPath" );}
|
||||
void AppData::gePath (const QString x) { store(x, _gePath, "gePath" );}
|
||||
void AppData::eepromDir (const QString x) { store(x, _eepromDir, "lastDir" );}
|
||||
void AppData::flashDir (const QString x) { store(x, _flashDir, "lastFlashDir" );}
|
||||
void AppData::imagesDir (const QString x) { store(x, _imagesDir, "lastImagesDir" );}
|
||||
void AppData::logDir (const QString x) { store(x, _logDir, "lastLogDir" );}
|
||||
void AppData::libDir (const QString x) { store(x, _libDir, "libraryPath" );}
|
||||
void AppData::snapshotDir (const QString x) { store(x, _snapshotDir, "snapshotpath" );}
|
||||
void AppData::updatesDir (const QString x) { store(x, _updatesDir, "lastUpdatesDir" );}
|
||||
|
||||
void AppData::maximized (const bool x) { store(x, _maximized, "maximized" );}
|
||||
void AppData::jsSupport (const bool x) { store(x, _jsSupport, "js_support" );}
|
||||
void AppData::showSplash (const bool x) { store(x, _showSplash, "show_splash" );}
|
||||
void AppData::snapToClpbrd (const bool x) { store(x, _snapToClpbrd, "snapshot_to_clipboard" );}
|
||||
void AppData::autoCheckApp (const bool x) { store(x, _autoCheckApp, "startup_check_companion" );}
|
||||
void AppData::autoCheckFw (const bool x) { store(x, _autoCheckFw, "startup_check_fw" );}
|
||||
void AppData::simuSW (const bool x) { store(x, _simuSW, "simuSW" );}
|
||||
void AppData::useWizard (const bool x) { store(x, _useWizard, "useWizard" );}
|
||||
|
||||
void AppData::backLight (const int x) { store(x, _backLight, "backLight" );}
|
||||
void AppData::embedSplashes (const int x) { store(x, _embedSplashes, "embedded_splashes" );}
|
||||
void AppData::fwServerFails (const int x) { store(x, _fwServerFails, "fwserver" );}
|
||||
void AppData::generalEditTab (const int x) { store(x, _generalEditTab, "generalEditTab" );}
|
||||
void AppData::iconSize (const int x) { store(x, _iconSize, "icon_size" );}
|
||||
void AppData::historySize (const int x) { store(x, _historySize, "history_size" );}
|
||||
void AppData::jsCtrl (const int x) { store(x, _jsCtrl, "js_ctrl" );}
|
||||
void AppData::id (const int x) { store(x, _id, "profileId" );}
|
||||
void AppData::theme (const int x) { store(x, _theme, "theme" );}
|
||||
void AppData::warningId (const int x) { store(x, _warningId, "warningId" );}
|
||||
|
||||
// Constructor
|
||||
AppData::AppData()
|
||||
{
|
||||
}
|
||||
|
||||
void AppData::init()
|
||||
{
|
||||
//Initialize the profiles
|
||||
for (int i=0; i<MAX_PROFILES; i++)
|
||||
profile[i].init( i );
|
||||
|
||||
//Initialize the joysticks
|
||||
for (int i=0; i<MAX_JOYSTICKS; i++)
|
||||
joystick[i].init( i );
|
||||
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
|
||||
// Copy existing 2.1 settings if present
|
||||
if (profile[0].name().isEmpty())
|
||||
{
|
||||
QSettings settings21("OpenTX", "Companion 2.1");
|
||||
|
||||
QStringList keys = settings21.allKeys();
|
||||
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++)
|
||||
{
|
||||
if (settings21.value(*i) != QString("") && settings21.value(*i) != QString("Start Menu Folder"))
|
||||
{
|
||||
settings.setValue(*i, settings21.value(*i));
|
||||
}
|
||||
}
|
||||
|
||||
//Reload profiles
|
||||
for (int i=0; i<MAX_PROFILES; i++)
|
||||
profile[i].init( i );
|
||||
}
|
||||
|
||||
// Copy existing 2.0 settings if present
|
||||
if (profile[0].name().isEmpty())
|
||||
{
|
||||
QSettings settings20("OpenTX", "Companion 2.0");
|
||||
|
||||
QStringList keys = settings20.allKeys();
|
||||
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++)
|
||||
{
|
||||
if (settings20.value(*i) != QString("") && settings20.value(*i) != QString("Start Menu Folder"))
|
||||
{
|
||||
settings.setValue(*i, settings20.value(*i));
|
||||
}
|
||||
}
|
||||
|
||||
//Reload profiles
|
||||
for (int i=0; i<MAX_PROFILES; i++)
|
||||
profile[i].init( i );
|
||||
}
|
||||
|
||||
// Else copy existing <2.0.16 settings if present
|
||||
if (profile[0].name().isEmpty())
|
||||
{
|
||||
QSettings pre2016settings("OpenTX", "OpenTX Companion");
|
||||
|
||||
QStringList keys = pre2016settings.allKeys();
|
||||
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++)
|
||||
{
|
||||
if (pre2016settings.value(*i) != QString("") && pre2016settings.value(*i) != QString("Start Menu Folder"))
|
||||
{
|
||||
settings.setValue(*i, pre2016settings.value(*i));
|
||||
}
|
||||
}
|
||||
|
||||
//Reload profiles
|
||||
for (int i=0; i<MAX_PROFILES; i++)
|
||||
profile[i].init( i );
|
||||
}
|
||||
|
||||
// Else import settings from companion9x if present
|
||||
if (profile[0].name().isEmpty())
|
||||
{
|
||||
QSettings c9x_settings("companion9x", "companion9x");
|
||||
// Copy all settings from companion9x to companion
|
||||
QStringList keys = c9x_settings.allKeys();
|
||||
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++)
|
||||
{
|
||||
settings.setValue(*i, c9x_settings.value(*i));
|
||||
}
|
||||
|
||||
// Store old values in new locations
|
||||
autoCheckApp(settings.value("startup_check_companion9x", true).toBool());
|
||||
useWizard(settings.value("wizardEnable", true).toBool());
|
||||
|
||||
// Convert and store the firmware type
|
||||
QString fwType = settings.value("firmware", "").toString();
|
||||
fwType.replace("open9x","opentx");
|
||||
fwType.replace("x9da","taranis");
|
||||
profile[0].fwType( fwType );
|
||||
|
||||
// Move the Companion9x profile settings to profile0, the new default profile
|
||||
profile[0].name( settings.value( "Name", "" ).toString());
|
||||
profile[0].sdPath( settings.value( "sdPath", "" ).toString());
|
||||
profile[0].splashFile( settings.value( "SplashFileName", "" ).toString());
|
||||
profile[0].burnFirmware( settings.value( "burnFirmware", false ).toBool());
|
||||
profile[0].renameFwFiles( settings.value( "rename_firmware_files", false ).toBool());
|
||||
profile[0].channelOrder( settings.value( "default_channel_order", "0" ).toInt());
|
||||
profile[0].defaultMode( settings.value( "default_mode", "1" ).toInt());
|
||||
|
||||
// Ensure that the default profile has a name
|
||||
if ( profile[0].name().isEmpty() )
|
||||
profile[0].name("My Radio");
|
||||
|
||||
// Delete obsolete settings fields from companion9x
|
||||
settings.remove("ActiveProfile");
|
||||
settings.remove("burnFirmware");
|
||||
settings.remove("custom_id");
|
||||
settings.remove("default_channel_order");
|
||||
settings.remove("default_mode");
|
||||
settings.remove("firmware");
|
||||
settings.remove("lastFw");
|
||||
settings.remove("modelEditTab");
|
||||
settings.remove("Name");
|
||||
settings.remove("patchImage");
|
||||
settings.remove("rename_firmware_files");
|
||||
settings.remove("sdPath");
|
||||
settings.remove("SplashFileName");
|
||||
settings.remove("startup_check_companion9x");
|
||||
settings.remove("wizardEnable");
|
||||
|
||||
// Delete settings that we do not want to carry over from 1.52
|
||||
settings.remove("dfu_location");
|
||||
|
||||
// Select the new default profile as current profile
|
||||
id( 0 );
|
||||
}
|
||||
|
||||
// Remove settings that have been made obsolete during companion2.0 development
|
||||
settings.remove("compilation-server");
|
||||
|
||||
// Load and store all variables. Use default values if setting values are missing
|
||||
QString _tempString; // Do not touch. Do not change the settings version before a new verson update!
|
||||
getset( _tempString, "settings_version" ,"220" ); // This is a version marker. Will be used to upgrade the settings later on.
|
||||
|
||||
getset( _recentFiles, "recentFileList" ,"" );
|
||||
getset( _mainWinGeo, "mainWindowGeometry" ,"" );
|
||||
getset( _mainWinState, "mainWindowState" ,"" );
|
||||
getset( _modelEditGeo, "modelEditGeometry" ,"" );
|
||||
|
||||
getset( _armMcu, "arm_mcu" ,"at91sam3s4-9x" );
|
||||
getset( _avrArguments, "avr_arguments" ,"" );
|
||||
getset( _avrPort, "avr_port" ,"" );
|
||||
getset( _avrdudeLocation, "avrdudeLocation" ,"" );
|
||||
getset( _dfuArguments, "dfu_arguments" ,"-a 0" );
|
||||
getset( _dfuLocation, "dfu_location" ,"" );
|
||||
getset( _locale, "locale" ,"" );
|
||||
getset( _mcu, "mcu" ,"m64" );
|
||||
getset( _programmer, "programmer" ,"usbasp" );
|
||||
getset( _sambaLocation, "samba_location" ,"" );
|
||||
getset( _sambaPort, "samba_port" ,"\\USBserial\\COM23" );
|
||||
getset( _lastSimulator, "last_simulator" ,"" );
|
||||
|
||||
getset( _backupDir, "backupPath" ,"" );
|
||||
getset( _gePath, "gePath" ,"" );
|
||||
getset( _eepromDir, "lastDir" ,"" );
|
||||
getset( _flashDir, "lastFlashDir" ,"" );
|
||||
getset( _imagesDir, "lastImagesDir" ,"" );
|
||||
getset( _logDir, "lastLogDir" ,"" );
|
||||
getset( _libDir, "libraryPath" ,"" );
|
||||
getset( _snapshotDir, "snapshotpath" ,"" );
|
||||
getset( _updatesDir, "lastUpdatesDir" ,"" );
|
||||
|
||||
getset( _outputDisplayDetails, "outputDisplayDetails" ,false );
|
||||
getset( _enableBackup, "enableBackup" ,false );
|
||||
getset( _backupOnFlash, "backupOnFlash" ,true );
|
||||
getset( _checkHardwareCompatibility, "checkHardwareCompatibility" ,true );
|
||||
|
||||
getset( _useCompanionNightlyBuilds, "useCompanionNightlyBuilds" ,false );
|
||||
getset( _useFirmwareNightlyBuilds, "useFirmwareNightlyBuilds" ,false );
|
||||
|
||||
getset( _jsSupport, "js_support" ,false );
|
||||
getset( _maximized, "maximized" ,false );
|
||||
getset( _showSplash, "show_splash" ,true );
|
||||
getset( _snapToClpbrd, "snapshot_to_clipboard" ,false );
|
||||
getset( _autoCheckApp, "startup_check_companion" ,true );
|
||||
getset( _autoCheckFw, "startup_check_fw" ,true );
|
||||
getset( _simuSW, "simuSW" ,false );
|
||||
getset( _useWizard, "useWizard" ,true );
|
||||
|
||||
getset( _backLight, "backLight" ,0 );
|
||||
getset( _embedSplashes, "embedded_splashes" ,0 );
|
||||
getset( _fwServerFails, "fwserver" ,0 );
|
||||
getset( _generalEditTab, "generalEditTab" ,0 );
|
||||
getset( _iconSize, "icon_size" ,2 );
|
||||
getset( _jsCtrl, "js_ctrl" ,0 );
|
||||
getset( _historySize, "history_size" ,10 );
|
||||
getset( _id, "profileId" ,0 );
|
||||
getset( _theme, "theme" ,1 );
|
||||
getset( _warningId, "warningId" ,0 );
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
/*
|
||||
* Author - Kjell Kernen
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
// All temporary and permanent global variables are defined here to make
|
||||
// initialization and storage safe and visible.
|
||||
// Do not access variables in QSettings directly, it is not type safe!
|
||||
|
||||
|
||||
#ifndef COMPANION_APPDATA_H
|
||||
#define COMPANION_APPDATA_H
|
||||
#include <QByteArray>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
|
||||
#define COMPANY "OpenTX"
|
||||
#define PRODUCT "Companion 2.2"
|
||||
|
||||
#define MAX_PROFILES 15
|
||||
#define MAX_JOYSTICKS 8
|
||||
|
||||
class CompStoreObj
|
||||
{
|
||||
public:
|
||||
void clear (const QString tag1="", const QString tag2="", const QString tag3="");
|
||||
void store(const QByteArray newArray, QByteArray &array, const QString tag, const QString group1="", const QString group2="" );
|
||||
void store(const QStringList newSList, QStringList &stringList, const QString tag, const QString group1="", const QString group2="" );
|
||||
void store(const QString newString, QString &string, const QString tag, const QString group1="", const QString group2="" );
|
||||
void store(const bool newTruth, bool &truth, const QString tag, const QString group1="", const QString group2="" );
|
||||
void store(const int newNumber, int &number, const QString tag, const QString group1="", const QString group2="" );
|
||||
|
||||
// Retrieval functions
|
||||
void retrieve( QByteArray &array, const QString tag, const QString def, const QString group1="", const QString group2="" );
|
||||
void retrieve( QStringList &stringList, const QString tag, const QString def, const QString group1="", const QString group2="" );
|
||||
void retrieve( QString &string, const QString tag, const QString def, const QString group1="", const QString group2="" );
|
||||
void retrieve( bool &truth, const QString tag, const bool def, const QString group1="", const QString group2="" );
|
||||
void retrieve( int &number, const QString tag, const int def, const QString group1="", const QString group2="" );
|
||||
|
||||
// Retrieve and Store functions
|
||||
void getset( QByteArray &array, const QString tag, const QString def, const QString group1="", const QString group2="" );
|
||||
void getset( QStringList &stringList, const QString tag, const QString def, const QString group1="", const QString group2="" );
|
||||
void getset( QString &string, const QString tag, const QString def, const QString group1="", const QString group2="" );
|
||||
void getset( bool &truth, const QString tag, const bool def, const QString group1="", const QString group2="" );
|
||||
void getset( int &number, const QString tag, const int def, const QString group1="", const QString group2="" );
|
||||
};
|
||||
|
||||
class FwRevision: protected CompStoreObj
|
||||
{
|
||||
public:
|
||||
int get( const QString);
|
||||
void set( const QString, const int );
|
||||
void remove( const QString );
|
||||
};
|
||||
|
||||
class JStickData: protected CompStoreObj
|
||||
{
|
||||
private:
|
||||
int index;
|
||||
|
||||
int _stickAxe;
|
||||
int _stickMin;
|
||||
int _stickMed;
|
||||
int _stickMax;
|
||||
int _stickInv;
|
||||
|
||||
public:
|
||||
// All the get definitions
|
||||
int stick_axe();
|
||||
int stick_min();
|
||||
int stick_med();
|
||||
int stick_max();
|
||||
int stick_inv();
|
||||
|
||||
// All the set definitions
|
||||
void stick_axe(const int);
|
||||
void stick_min(const int);
|
||||
void stick_med(const int);
|
||||
void stick_max(const int);
|
||||
void stick_inv(const int);
|
||||
|
||||
JStickData();
|
||||
void remove();
|
||||
bool existsOnDisk();
|
||||
void init(int index);
|
||||
void flush();
|
||||
};
|
||||
|
||||
class Profile: protected CompStoreObj
|
||||
{
|
||||
private:
|
||||
// Class Internal Variable
|
||||
int index;
|
||||
|
||||
// Application Variables
|
||||
QString _fwName;
|
||||
QString _fwType;
|
||||
QString _name;
|
||||
QString _sdPath;
|
||||
int _volumeGain;
|
||||
QString _pBackupDir;
|
||||
QString _splashFile;
|
||||
bool _burnFirmware;
|
||||
bool _penableBackup;
|
||||
bool _renameFwFiles;
|
||||
int _channelOrder;
|
||||
int _defaultMode;
|
||||
|
||||
// Firmware Variables
|
||||
QString _beeper;
|
||||
QString _countryCode;
|
||||
QString _display;
|
||||
QString _haptic;
|
||||
QString _speaker;
|
||||
QString _stickPotCalib;
|
||||
QString _timeStamp;
|
||||
QString _trainerCalib;
|
||||
QString _controlTypes;
|
||||
QString _controlNames;
|
||||
int _txCurrentCalibration;
|
||||
int _gsStickMode;
|
||||
int _ppmMultiplier;
|
||||
int _txVoltageCalibration;
|
||||
int _vBatWarn;
|
||||
int _vBatMin;
|
||||
int _vBatMax;
|
||||
|
||||
public:
|
||||
// All the get definitions
|
||||
QString fwName() const;
|
||||
QString fwType() const;
|
||||
QString name() const;
|
||||
QString sdPath() const;
|
||||
int volumeGain() const;
|
||||
QString pBackupDir() const;
|
||||
QString splashFile() const;
|
||||
bool burnFirmware() const;
|
||||
bool renameFwFiles() const;
|
||||
bool penableBackup() const;
|
||||
int channelOrder() const;
|
||||
int defaultMode() const;
|
||||
|
||||
QString beeper() const;
|
||||
QString countryCode() const;
|
||||
QString display() const;
|
||||
QString haptic() const;
|
||||
QString speaker() const;
|
||||
QString stickPotCalib() const;
|
||||
QString timeStamp() const;
|
||||
QString trainerCalib() const;
|
||||
QString controlTypes() const;
|
||||
QString controlNames() const;
|
||||
int txCurrentCalibration() const;
|
||||
int gsStickMode() const;
|
||||
int ppmMultiplier() const;
|
||||
int txVoltageCalibration() const;
|
||||
int vBatWarn() const;
|
||||
int vBatMin() const;
|
||||
int vBatMax() const;
|
||||
|
||||
// All the set definitions
|
||||
void name (const QString);
|
||||
void fwName (const QString);
|
||||
void fwType (const QString);
|
||||
void volumeGain (const int);
|
||||
void sdPath (const QString);
|
||||
void pBackupDir (const QString);
|
||||
void splashFile (const QString);
|
||||
void burnFirmware (const bool);
|
||||
void renameFwFiles (const bool);
|
||||
void penableBackup (const bool);
|
||||
void channelOrder (const int);
|
||||
void defaultMode (const int);
|
||||
|
||||
void beeper (const QString);
|
||||
void countryCode (const QString);
|
||||
void display (const QString);
|
||||
void haptic (const QString);
|
||||
void speaker (const QString);
|
||||
void stickPotCalib (const QString);
|
||||
void timeStamp (const QString);
|
||||
void trainerCalib (const QString);
|
||||
void controlTypes (const QString);
|
||||
void controlNames (const QString);
|
||||
void txCurrentCalibration (const int);
|
||||
void gsStickMode (const int);
|
||||
void ppmMultiplier (const int);
|
||||
void txVoltageCalibration (const int);
|
||||
void vBatWarn (const int);
|
||||
void vBatMin (const int);
|
||||
void vBatMax (const int);
|
||||
|
||||
Profile();
|
||||
Profile& operator=(const Profile&);
|
||||
void remove();
|
||||
bool existsOnDisk();
|
||||
void init(int newIndex);
|
||||
void initFwVariables();
|
||||
void flush();
|
||||
};
|
||||
|
||||
#define BOOL_PROPERTY(name, dflt) \
|
||||
public: \
|
||||
inline bool name() { return _ ## name; } \
|
||||
void name(const bool val) { store(val, _ ## name, # name); } \
|
||||
private: \
|
||||
bool _ ## name;
|
||||
|
||||
class AppData: protected CompStoreObj
|
||||
{
|
||||
BOOL_PROPERTY(enableBackup, false)
|
||||
BOOL_PROPERTY(outputDisplayDetails, false)
|
||||
BOOL_PROPERTY(backupOnFlash, true)
|
||||
BOOL_PROPERTY(checkHardwareCompatibility, true)
|
||||
BOOL_PROPERTY(useCompanionNightlyBuilds, false)
|
||||
BOOL_PROPERTY(useFirmwareNightlyBuilds, false)
|
||||
|
||||
// All the global variables
|
||||
public:
|
||||
Profile profile[MAX_PROFILES];
|
||||
JStickData joystick[MAX_JOYSTICKS];
|
||||
FwRevision fwRev;
|
||||
|
||||
private:
|
||||
QStringList _recentFiles;
|
||||
QByteArray _mainWinGeo;
|
||||
QByteArray _mainWinState;
|
||||
QByteArray _modelEditGeo;
|
||||
|
||||
QString _armMcu;
|
||||
QString _avrArguments;
|
||||
QString _avrPort;
|
||||
QString _avrdudeLocation;
|
||||
QString _dfuArguments;
|
||||
QString _dfuLocation;
|
||||
QString _locale;
|
||||
QString _mcu;
|
||||
QString _programmer;
|
||||
QString _sambaLocation;
|
||||
QString _sambaPort;
|
||||
QString _lastSimulator;
|
||||
|
||||
QString _backupDir;
|
||||
QString _gePath;
|
||||
QString _eepromDir;
|
||||
QString _flashDir;
|
||||
QString _imagesDir;
|
||||
QString _logDir;
|
||||
QString _libDir;
|
||||
QString _snapshotDir;
|
||||
QString _updatesDir;
|
||||
|
||||
bool _maximized;
|
||||
bool _jsSupport;
|
||||
bool _showSplash;
|
||||
bool _snapToClpbrd;
|
||||
bool _autoCheckApp;
|
||||
bool _autoCheckFw;
|
||||
bool _simuSW;
|
||||
bool _useWizard;
|
||||
|
||||
int _backLight;
|
||||
int _embedSplashes;
|
||||
int _fwServerFails;
|
||||
int _generalEditTab;
|
||||
int _iconSize;
|
||||
int _jsCtrl;
|
||||
int _historySize;
|
||||
int _id;
|
||||
int _theme;
|
||||
int _warningId;
|
||||
|
||||
public:
|
||||
// All the get definitions
|
||||
QStringList recentFiles();
|
||||
QByteArray mainWinGeo();
|
||||
QByteArray mainWinState();
|
||||
QByteArray modelEditGeo();
|
||||
|
||||
QString armMcu();
|
||||
QString avrArguments();
|
||||
QString avrPort();
|
||||
QString avrdudeLocation();
|
||||
QString dfuArguments();
|
||||
QString dfuLocation();
|
||||
QString lastFw();
|
||||
QString locale();
|
||||
QString mcu();
|
||||
QString programmer();
|
||||
QString sambaLocation();
|
||||
QString sambaPort();
|
||||
QString lastSimulator();
|
||||
|
||||
QString backupDir();
|
||||
QString gePath();
|
||||
QString eepromDir();
|
||||
QString flashDir();
|
||||
QString imagesDir();
|
||||
QString logDir();
|
||||
QString libDir();
|
||||
QString snapshotDir();
|
||||
QString updatesDir();
|
||||
|
||||
bool jsSupport();
|
||||
bool maximized();
|
||||
bool showSplash();
|
||||
bool snapToClpbrd();
|
||||
bool autoCheckApp();
|
||||
bool autoCheckFw();
|
||||
bool simuSW();
|
||||
bool useWizard();
|
||||
|
||||
int backLight();
|
||||
int embedSplashes();
|
||||
int fwServerFails();
|
||||
int generalEditTab();
|
||||
int iconSize();
|
||||
int historySize();
|
||||
int jsCtrl();
|
||||
int id();
|
||||
int theme();
|
||||
int warningId();
|
||||
|
||||
// All the set definitions
|
||||
void recentFiles (const QStringList x);
|
||||
void mainWinGeo (const QByteArray);
|
||||
void mainWinState (const QByteArray);
|
||||
void modelEditGeo (const QByteArray);
|
||||
|
||||
void armMcu (const QString);
|
||||
void avrArguments (const QString);
|
||||
void avrPort (const QString);
|
||||
void avrdudeLocation (const QString);
|
||||
void dfuArguments (const QString);
|
||||
void dfuLocation (const QString);
|
||||
void lastFw (const QString);
|
||||
void locale (const QString);
|
||||
void mcu (const QString);
|
||||
void programmer (const QString);
|
||||
void sambaLocation (const QString);
|
||||
void sambaPort (const QString);
|
||||
void lastSimulator (const QString);
|
||||
|
||||
void backupDir (const QString);
|
||||
void gePath (const QString);
|
||||
void eepromDir (const QString);
|
||||
void flashDir (const QString);
|
||||
void imagesDir (const QString);
|
||||
void logDir (const QString);
|
||||
void libDir (const QString);
|
||||
void snapshotDir (const QString);
|
||||
void updatesDir (const QString);
|
||||
|
||||
void maximized (const bool);
|
||||
void jsSupport (const bool);
|
||||
void showSplash (const bool);
|
||||
void snapToClpbrd (const bool);
|
||||
void autoCheckApp (const bool);
|
||||
void autoCheckFw (const bool);
|
||||
void simuSW (const bool);
|
||||
void useWizard (const bool);
|
||||
|
||||
void backLight (const int);
|
||||
void embedSplashes (const int);
|
||||
void fwServerFails (const int);
|
||||
void generalEditTab (const int);
|
||||
void iconSize (const int);
|
||||
void historySize (const int);
|
||||
void jsCtrl (const int);
|
||||
void modelEditTab (const int);
|
||||
void id (const int);
|
||||
void theme (const int);
|
||||
void warningId (const int);
|
||||
|
||||
// Constructor
|
||||
AppData();
|
||||
void init();
|
||||
};
|
||||
|
||||
extern AppData g;
|
||||
|
||||
#endif // COMPANION_APPDATA_H
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtGui>
|
||||
#include "hexinterface.h"
|
||||
#include "splash.h"
|
||||
#include "firmwareinterface.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#define FW_MARK "FW"
|
||||
#define VERS_MARK "VERS"
|
||||
#define DATE_MARK "DATE"
|
||||
#define TIME_MARK "TIME"
|
||||
#define EEPR_MARK "EEPR"
|
||||
|
||||
int getFileType(const QString &fullFileName)
|
||||
{
|
||||
QString suffix = QFileInfo(fullFileName).suffix().toUpper();
|
||||
if (suffix == "HEX")
|
||||
return FILE_TYPE_HEX;
|
||||
else if (suffix == "BIN")
|
||||
return FILE_TYPE_BIN;
|
||||
else if (suffix == "EEPM")
|
||||
return FILE_TYPE_EEPM;
|
||||
else if (suffix == "EEPE")
|
||||
return FILE_TYPE_EEPE;
|
||||
else if (suffix == "XML")
|
||||
return FILE_TYPE_XML;
|
||||
else if (suffix == "OTX")
|
||||
return FILE_TYPE_OTX;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
FirmwareInterface::FirmwareInterface(const QString &filename):
|
||||
flash(FSIZE_MAX, 0),
|
||||
flashSize(0),
|
||||
versionId(0),
|
||||
eepromVersion(0),
|
||||
eepromVariant(0),
|
||||
splashOffset(0),
|
||||
splashSize(0),
|
||||
splashWidth(0),
|
||||
splashHeight(0),
|
||||
isValidFlag(false)
|
||||
{
|
||||
if (!filename.isEmpty()) {
|
||||
QFile file(filename);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { // reading HEX TEXT file
|
||||
QTextStream inputStream(&file);
|
||||
flashSize = HexInterface(inputStream).load((uint8_t *)flash.data(), FSIZE_MAX);
|
||||
file.close();
|
||||
if (flashSize == 0) {
|
||||
file.open(QIODevice::ReadOnly);
|
||||
flashSize = file.read((char *)flash.data(), FSIZE_MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flashSize > 0) {
|
||||
flavour = seekLabel(FW_MARK);
|
||||
version = seekLabel(VERS_MARK);
|
||||
if (version.startsWith("opentx-")) {
|
||||
// old version format
|
||||
int index = version.lastIndexOf('-');
|
||||
flavour = version.mid(0, index);
|
||||
version = version.mid(index+1);
|
||||
}
|
||||
date = seekLabel(DATE_MARK);
|
||||
time = seekLabel(TIME_MARK);
|
||||
eepromId = seekLabel(EEPR_MARK);
|
||||
|
||||
if (eepromId.contains('-')) {
|
||||
QStringList list = eepromId.split('-');
|
||||
eepromVersion = list[0].toInt();
|
||||
eepromVariant = list[1].toInt();
|
||||
}
|
||||
else {
|
||||
eepromVersion = eepromId.toInt();
|
||||
}
|
||||
|
||||
versionId = version2index(version);
|
||||
SeekSplash();
|
||||
isValidFlag = !version.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
QString FirmwareInterface::seekString(const QString & string)
|
||||
{
|
||||
QString result = "";
|
||||
|
||||
int start = flash.indexOf(string);
|
||||
if (start > 0) {
|
||||
start += string.length();
|
||||
int end = -1;
|
||||
for (int i=start; i<start+50; i++) {
|
||||
char c = flash.at(i);
|
||||
if (c == '\0' || c == '\036') {
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end > 0) {
|
||||
result = flash.mid(start, (end - start)).trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString FirmwareInterface::seekLabel(const QString & label)
|
||||
{
|
||||
QString result = seekString(label + "\037\033:");
|
||||
if (!result.isEmpty())
|
||||
return result;
|
||||
|
||||
return seekString(label + ":");
|
||||
}
|
||||
|
||||
QString FirmwareInterface::getFlavour() const
|
||||
{
|
||||
if (flavour == "opentx-taranis-x9e")
|
||||
return "opentx-x9e";
|
||||
else if (flavour == "opentx-x9dp" || flavour == "opentx-taranis-plus")
|
||||
return "opentx-x9d+";
|
||||
else if (flavour == "opentx-taranis")
|
||||
return "opentx-x9d";
|
||||
else
|
||||
return flavour;
|
||||
}
|
||||
|
||||
bool FirmwareInterface::isHardwareCompatible(const FirmwareInterface &previousFirmware) const
|
||||
{
|
||||
QString newFlavour = getFlavour();
|
||||
if (newFlavour.isEmpty())
|
||||
return true;
|
||||
|
||||
QString previousFlavour = previousFirmware.getFlavour();
|
||||
if (previousFlavour.isEmpty())
|
||||
return true;
|
||||
|
||||
return (newFlavour == previousFlavour);
|
||||
}
|
||||
|
||||
bool FirmwareInterface::SeekSplash(QByteArray splash)
|
||||
{
|
||||
int start = flash.indexOf(splash);
|
||||
if (start>0) {
|
||||
splashOffset = start;
|
||||
splashSize = splash.size();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool FirmwareInterface::SeekSplash(QByteArray sps, QByteArray spe, int size)
|
||||
{
|
||||
int start = 0;
|
||||
while (start>=0) {
|
||||
start = flash.indexOf(sps, start+1);
|
||||
if (start>0) {
|
||||
int end = start + sps.size() + size;
|
||||
if (end == flash.indexOf(spe, end)) {
|
||||
splashOffset = start + sps.size();
|
||||
splashSize = end - start - sps.size();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
qDebug() << flash.indexOf(spe, start) << end << sps.size() << spe;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#define OTX_SPS_9X "SPS\0\200\100"
|
||||
#define OTX_SPS_TARANIS "SPS\0\324\100"
|
||||
#define OTX_SPS_SIZE 6
|
||||
#define OTX_SPE "SPE"
|
||||
#define OTX_SPE_SIZE 4
|
||||
|
||||
void FirmwareInterface::SeekSplash(void)
|
||||
{
|
||||
splashSize = 0;
|
||||
splashOffset = 0;
|
||||
splashWidth = SPLASH_WIDTH;
|
||||
splashHeight = SPLASH_HEIGHT;
|
||||
splash_format = QImage::Format_Mono;
|
||||
|
||||
if (SeekSplash(QByteArray((const char *)gr9x_splash, sizeof(gr9x_splash))) || SeekSplash(QByteArray((const char *)gr9xv4_splash, sizeof(gr9xv4_splash)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray((const char *)er9x_splash, sizeof(er9x_splash)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray((const char *)opentx_splash, sizeof(opentx_splash)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray((const char *)opentxtaranis_splash, sizeof(opentxtaranis_splash)))) {
|
||||
splashWidth = SPLASHX9D_WIDTH;
|
||||
splashHeight = SPLASHX9D_HEIGHT;
|
||||
splash_format = QImage::Format_Indexed8;
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray((const char *)ersky9x_splash, sizeof(ersky9x_splash)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray(OTX_SPS_9X, OTX_SPS_SIZE), QByteArray(OTX_SPE, OTX_SPE_SIZE), 1024)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray(OTX_SPS_TARANIS, OTX_SPS_SIZE), QByteArray(OTX_SPE, OTX_SPE_SIZE), 6784)) {
|
||||
splashWidth = SPLASHX9D_WIDTH;
|
||||
splashHeight = SPLASHX9D_HEIGHT;
|
||||
splash_format = QImage::Format_Indexed8;
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray(ERSKY9X_SPS, sizeof(ERSKY9X_SPS)), QByteArray(ERSKY9X_SPE, sizeof(ERSKY9X_SPE)), 1030)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SeekSplash(QByteArray(ERSPLASH_MARKER, sizeof(ERSPLASH_MARKER)))) {
|
||||
splashOffset += sizeof(ERSPLASH_MARKER);
|
||||
splashSize = sizeof(er9x_splash);
|
||||
}
|
||||
}
|
||||
|
||||
bool FirmwareInterface::setSplash(const QImage & newsplash)
|
||||
{
|
||||
if (splashOffset == 0 || splashSize == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char b[SPLASH_SIZE_MAX] = {0};
|
||||
QColor color;
|
||||
QByteArray splash;
|
||||
if (splash_format == QImage::Format_Indexed8) {
|
||||
for (unsigned int y=0; y<splashHeight; y++) {
|
||||
unsigned int idx = (y/2)*splashWidth;
|
||||
for (unsigned int x=0; x<splashWidth; x++, idx++) {
|
||||
QRgb gray = qGray(newsplash.pixel(x, y));
|
||||
uint8_t z = ((255-gray)*15)/255;
|
||||
if (y & 1) z <<= 4;
|
||||
b[idx] |= z;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
QColor black = QColor(0,0,0);
|
||||
QImage blackNwhite = newsplash.convertToFormat(QImage::Format_MonoLSB);
|
||||
for (uint y=0; y<splashHeight; y++) {
|
||||
for (uint x=0; x<splashWidth; x++) {
|
||||
color = QColor(blackNwhite.pixel(x,y));
|
||||
b[splashWidth*(y/8) + x] |= ((color==black ? 1: 0)<<(y % 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
splash.clear();
|
||||
splash.append(b, splashSize);
|
||||
flash.replace(splashOffset, splashSize, splash);
|
||||
return true;
|
||||
}
|
||||
|
||||
int FirmwareInterface::getSplashWidth()
|
||||
{
|
||||
return splashWidth;
|
||||
}
|
||||
|
||||
uint FirmwareInterface::getSplashHeight()
|
||||
{
|
||||
return splashHeight;
|
||||
}
|
||||
|
||||
QImage::Format FirmwareInterface::getSplashFormat()
|
||||
{
|
||||
return splash_format;
|
||||
}
|
||||
|
||||
QImage FirmwareInterface::getSplash()
|
||||
{
|
||||
if (splashOffset == 0 || splashSize == 0) {
|
||||
return QImage(); // empty image
|
||||
}
|
||||
|
||||
if (splash_format == QImage::Format_Indexed8) {
|
||||
QImage image(splashWidth, splashHeight, QImage::Format_RGB888);
|
||||
if (splashOffset > 0) {
|
||||
for (unsigned int y=0; y<splashHeight; y++) {
|
||||
unsigned int idx = (y/2)*splashWidth;
|
||||
for (unsigned int x=0; x<splashWidth; x++, idx++) {
|
||||
uint8_t byte = flash.at(splashOffset+idx);
|
||||
unsigned int z = (y & 1) ? (byte >> 4) : (byte & 0x0F);
|
||||
z = 255-(z*255)/15;
|
||||
QRgb rgb = qRgb(z, z, z);
|
||||
image.setPixel(x, y, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
else {
|
||||
QImage image(splashWidth, splashHeight, QImage::Format_Mono);
|
||||
if (splashOffset > 0) {
|
||||
for (unsigned int y=0; y<splashHeight; y++) {
|
||||
for(unsigned int x=0; x<splashWidth; x++) {
|
||||
image.setPixel(x, y, (flash.at(splashOffset+(splashWidth*(y/8)+x)) & (1<<(y % 8))) ? 0 : 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
bool FirmwareInterface::hasSplash()
|
||||
{
|
||||
return (splashOffset > 0 ? true : false);
|
||||
}
|
||||
|
||||
bool FirmwareInterface::isValid()
|
||||
{
|
||||
return isValidFlag;
|
||||
}
|
||||
|
||||
unsigned int FirmwareInterface::save(QString fileName)
|
||||
{
|
||||
uint8_t *binflash = (uint8_t*)malloc(FSIZE_MAX);
|
||||
if (binflash == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(binflash, flash.constData(), flashSize);
|
||||
QFile file(fileName);
|
||||
|
||||
int fileType = getFileType(fileName);
|
||||
|
||||
if (fileType == FILE_TYPE_HEX) {
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { //reading HEX TEXT file
|
||||
free(binflash);
|
||||
return -1;
|
||||
}
|
||||
QTextStream outputStream(&file);
|
||||
HexInterface hex=HexInterface(outputStream);
|
||||
hex.save(binflash, flashSize);
|
||||
}
|
||||
else {
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { //reading HEX TEXT file
|
||||
free(binflash);
|
||||
return -1;
|
||||
}
|
||||
file.write((char*)binflash, flashSize);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
free(binflash);
|
||||
return flashSize;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Author - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FIRMWAREINTERFACE_H_
|
||||
#define FIRMWAREINTERFACE_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
#include <QByteArray>
|
||||
|
||||
#define SPLASH_WIDTH (128)
|
||||
#define SPLASH_HEIGHT (64)
|
||||
#define SPLASHX9D_WIDTH (212)
|
||||
#define SPLASHX9D_HEIGHT (64)
|
||||
#define SPLASH_SIZE_MAX (SPLASHX9D_WIDTH*SPLASHX9D_HEIGHT/2)
|
||||
#define ERSPLASH_MARKER "Splash"
|
||||
#define ERSPLASH_OFFSET (10)
|
||||
#define ERSKY9X_SPS "SPS"
|
||||
#define ERSKY9X_SPE "SPE"
|
||||
#define ERSKY9X_OFFSET (7)
|
||||
|
||||
#define FILE_TYPE_BIN 1
|
||||
#define FILE_TYPE_HEX 2
|
||||
#define FILE_TYPE_EEPE 3
|
||||
#define FILE_TYPE_EEPM 4
|
||||
#define FILE_TYPE_XML 5
|
||||
#define FILE_TYPE_OTX 6
|
||||
|
||||
int getFileType(const QString &fullFileName);
|
||||
|
||||
class FirmwareInterface
|
||||
{
|
||||
public:
|
||||
FirmwareInterface(const QString &filename);
|
||||
inline QString getDate() { return date; }
|
||||
inline QString getTime() { return time; }
|
||||
int getSize() { return flashSize; }
|
||||
QString getFlavour() const;
|
||||
bool isHardwareCompatible(const FirmwareInterface &previousFirmware) const;
|
||||
inline QString getVersion() { return version; }
|
||||
unsigned int getVersionId() { return versionId; }
|
||||
inline int getEEpromVersion() { return eepromVersion; }
|
||||
inline int getEEpromVariant() { return eepromVariant; }
|
||||
inline QString getEEpromId() { return eepromId; }
|
||||
QImage getSplash();
|
||||
bool setSplash(const QImage & newsplash);
|
||||
bool hasSplash();
|
||||
int getSplashWidth();
|
||||
uint getSplashHeight();
|
||||
QImage::Format getSplashFormat();
|
||||
unsigned int save(QString fileName);
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
QByteArray flash;
|
||||
uint flashSize;
|
||||
QString seekString(const QString & string);
|
||||
QString seekLabel(const QString & label);
|
||||
void SeekSplash();
|
||||
bool SeekSplash(QByteArray sps, QByteArray spe, int size);
|
||||
bool SeekSplash(QByteArray splash);
|
||||
QString filename;
|
||||
QString date;
|
||||
QString time;
|
||||
QString flavour;
|
||||
QString version;
|
||||
int versionId;
|
||||
QString eepromId;
|
||||
int eepromVersion;
|
||||
int eepromVariant;
|
||||
QByteArray splash;
|
||||
uint splashOffset;
|
||||
uint splashSize;
|
||||
uint splashWidth;
|
||||
uint splashHeight;
|
||||
QImage::Format splash_format;
|
||||
bool isValidFlag;
|
||||
};
|
||||
|
||||
#endif /* FIRMWAREINTERFACE_H_ */
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hexinterface.h"
|
||||
|
||||
HexInterface::HexInterface(QTextStream &stream):
|
||||
stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
int HexInterface::getValueFromLine(const QString &line, int pos, int len)
|
||||
{
|
||||
bool ok;
|
||||
int hex = line.mid(pos,len).toInt(&ok, 16);
|
||||
return ok ? hex : -1;
|
||||
}
|
||||
|
||||
int HexInterface::load(uint8_t *data, int maxsize)
|
||||
{
|
||||
int result = 0;
|
||||
int offset = 0;
|
||||
while (!stream.atEnd()) {
|
||||
QString line = stream.readLine();
|
||||
|
||||
if(line.left(1)!=":") continue;
|
||||
|
||||
int byteCount = getValueFromLine(line,1);
|
||||
int address = getValueFromLine(line,3,4);
|
||||
int recType = getValueFromLine(line,7);
|
||||
if (recType==0x02) {
|
||||
offset+=0x010000;
|
||||
}
|
||||
if(byteCount<0 || address<0 || recType<0)
|
||||
return 0;
|
||||
|
||||
QByteArray ba;
|
||||
ba.clear();
|
||||
|
||||
quint8 chkSum = 0;
|
||||
chkSum -= byteCount;
|
||||
chkSum -= recType;
|
||||
chkSum -= address & 0xFF;
|
||||
chkSum -= address >> 8;
|
||||
for(int i=0; i<byteCount; i++)
|
||||
{
|
||||
quint8 v = getValueFromLine(line,(i*2)+9) & 0xFF;
|
||||
chkSum -= v;
|
||||
ba.append(v);
|
||||
}
|
||||
|
||||
quint8 retV = getValueFromLine(line,(byteCount*2)+9) & 0xFF;
|
||||
if(chkSum!=retV)
|
||||
return 0;
|
||||
|
||||
if (address+offset + byteCount <= maxsize) {
|
||||
if (recType == 0x00) { //data record - ba holds record
|
||||
memcpy(&data[address+offset],ba.data(),byteCount);
|
||||
result = std::max(result, address+offset+byteCount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool HexInterface::save(uint8_t *data, const int size)
|
||||
{
|
||||
int addr = 0;
|
||||
int nextbank = 1;
|
||||
while (addr < size) {
|
||||
if (addr>(nextbank*0x010000)-1) {
|
||||
stream << iHEXExtRec(nextbank) << "\n";
|
||||
nextbank++;
|
||||
}
|
||||
int llen = 32;
|
||||
if ((size - addr) < llen)
|
||||
llen = size - addr;
|
||||
stream << iHEXLine(data, addr, llen) << "\n";
|
||||
addr += llen;
|
||||
}
|
||||
stream << ":00000001FF\n"; // write EOF
|
||||
return true;
|
||||
}
|
||||
|
||||
QString HexInterface::iHEXLine(quint8 * data, quint32 addr, quint8 len)
|
||||
{
|
||||
unsigned int bankaddr;
|
||||
bankaddr=addr&0xffff;
|
||||
QString str = QString(":%1%2000").arg(len, 2, 16, QChar('0')).arg(bankaddr, 4, 16, QChar('0')); //write start, bytecount (32), address and record type
|
||||
quint8 chkSum = 0;
|
||||
chkSum = -len; //-bytecount; recordtype is zero
|
||||
chkSum -= bankaddr & 0xFF;
|
||||
chkSum -= bankaddr >> 8;
|
||||
for (int j = 0; j < len; j++) {
|
||||
str += QString("%1").arg(data[addr + j], 2, 16, QChar('0'));
|
||||
chkSum -= data[addr + j];
|
||||
}
|
||||
|
||||
str += QString("%1").arg(chkSum, 2, 16, QChar('0'));
|
||||
return str.toUpper(); // output to file and lf;
|
||||
}
|
||||
|
||||
QString HexInterface::iHEXExtRec(quint8 bank)
|
||||
{
|
||||
QString str = QString(":02000002"); //write record type 2 record
|
||||
quint8 chkSum = 0;
|
||||
chkSum = -2; //-bytecount; recordtype is zero
|
||||
chkSum -= 2; // type 2 record type
|
||||
str += QString("%1000").arg((bank&0x0f)<<4,1,16,QChar('0'));
|
||||
chkSum -= ((bank&0x0f)<<4); // type 2 record type
|
||||
str += QString("%1").arg(chkSum, 2, 16, QChar('0'));
|
||||
return str.toUpper(); // output to file and lf;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef hex_stream_h
|
||||
#define hex_stream_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <QTextStream>
|
||||
|
||||
class HexInterface {
|
||||
public:
|
||||
HexInterface(QTextStream &stream);
|
||||
|
||||
int load(uint8_t *output, int maxsize);
|
||||
bool save(uint8_t *data, const int size);
|
||||
|
||||
protected:
|
||||
|
||||
int getValueFromLine(const QString &line, int pos, int len=2);
|
||||
QString iHEXLine(quint8 * data, quint32 addr, quint8 len);
|
||||
QString iHEXExtRec(quint8 bank);
|
||||
|
||||
QTextStream & stream;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,940 @@
|
||||
/* vim:expandtab:ts=2 sw=2:
|
||||
*/
|
||||
/* mountlist.c -- return a list of mounted file systems
|
||||
|
||||
Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||
2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
||||
|
||||
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 2, 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/>.
|
||||
*/
|
||||
|
||||
// This file is not used on some platforms, so don't do anything for them
|
||||
#if(!(defined(WIN32) || !defined __GNUC__)&&(!defined(__amigaos4__))&&(!defined(__AROS__))&&(!defined(__MORPHOS__))&&(!defined(__amigaos__)))
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) // MacOS X is POSIX compliant
|
||||
#define MOUNTED_GETMNTINFO
|
||||
#if defined(__APPLE__)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#if defined(__OpenBSD__)
|
||||
#define HAVE_STRUCT_STATFS_F_FSTYPENAME 1
|
||||
#include <sys/param.h> /* types.h needs this */
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#elif defined(__NetBSD__)
|
||||
#define MOUNTED_GETMNTINFO2
|
||||
#elif defined(__BEOS__) || defined(__HAIKU__)
|
||||
#define MOUNTED_FS_STAT_DEV
|
||||
#elif defined(__TRU64__)
|
||||
#define MOUNTED_GETFSSTAT 1
|
||||
#define HAVE_SYS_MOUNT_H 1
|
||||
#include <sys/types.h>
|
||||
#else
|
||||
#define MOUNTED_GETMNTENT1
|
||||
#endif
|
||||
|
||||
#include "mountlist.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */
|
||||
# if HAVE_SYS_UCRED_H
|
||||
# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS,
|
||||
NGROUPS is used as an array dimension in ucred.h */
|
||||
# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
|
||||
# endif
|
||||
# if HAVE_SYS_MOUNT_H
|
||||
# include <sys/mount.h>
|
||||
# endif
|
||||
# if HAVE_SYS_FS_TYPES_H
|
||||
# include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
|
||||
# endif
|
||||
# if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
|
||||
# define FS_TYPE(Ent) ((Ent).f_fstypename)
|
||||
# else
|
||||
# define FS_TYPE(Ent) mnt_names[(Ent).f_type]
|
||||
# endif
|
||||
#endif /* MOUNTED_GETFSSTAT */
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
# include <mntent.h>
|
||||
# if !defined MOUNTED
|
||||
# if defined _PATH_MOUNTED /* GNU libc */
|
||||
# define MOUNTED _PATH_MOUNTED
|
||||
# endif
|
||||
# if defined MNT_MNTTAB /* HP-UX. */
|
||||
# define MOUNTED MNT_MNTTAB
|
||||
# endif
|
||||
# if defined MNTTABNAME /* Dynix. */
|
||||
# define MOUNTED MNTTABNAME
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */
|
||||
# include <sys/statvfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||
# include <sys/mount.h>
|
||||
# include <sys/fs_types.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */
|
||||
# include <fs_info.h>
|
||||
# include <dirent.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FREAD /* SVR2. */
|
||||
# include <mnttab.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
|
||||
# include <mnttab.h>
|
||||
# include <sys/fstyp.h>
|
||||
# include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_LISTMNTENT
|
||||
# include <mntent.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||
# include <sys/mnttab.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
# include <fshelp.h>
|
||||
# include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef DOLPHIN
|
||||
/* So special that it's not worth putting this in autoconf. */
|
||||
# undef MOUNTED_FREAD_FSTYP
|
||||
# define MOUNTED_GETMNTTBL
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_MNTENT_H
|
||||
/* This is to get MNTOPT_IGNORE on e.g. SVR4. */
|
||||
# include <sys/mntent.h>
|
||||
#endif
|
||||
|
||||
#undef MNT_IGNORE
|
||||
#if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT
|
||||
# define MNT_IGNORE(M) hasmntopt ((M), MNTOPT_IGNORE)
|
||||
#else
|
||||
# define MNT_IGNORE(M) 0
|
||||
#endif
|
||||
|
||||
#if USE_UNLOCKED_IO
|
||||
# include "unlocked-io.h"
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
/* The results of open() in this file are not used with fchdir,
|
||||
therefore save some unnecessary work in fchdir.c. */
|
||||
#undef open
|
||||
#undef close
|
||||
|
||||
/* The results of opendir() in this file are not used with dirfd and fchdir,
|
||||
therefore save some unnecessary work in fchdir.c. */
|
||||
#undef opendir
|
||||
#undef closedir
|
||||
|
||||
// gcc2 under haiku and beos don't like these macros for some reason.
|
||||
// As they are not used there anyways, we remove them and everyone is happy.
|
||||
#if !defined(__HAIKU__) && !defined(__BEOS__)
|
||||
#ifndef ME_DUMMY
|
||||
# define ME_DUMMY(Fs_name, Fs_type) \
|
||||
(strcmp (Fs_type, "autofs") == 0 \
|
||||
|| strcmp (Fs_type, "none") == 0 \
|
||||
|| strcmp (Fs_type, "proc") == 0 \
|
||||
|| strcmp (Fs_type, "subfs") == 0 \
|
||||
|| strcmp (Fs_type, "sysfs") == 0 \
|
||||
|| strcmp (Fs_type, "usbfs") == 0 \
|
||||
|| strcmp (Fs_type, "devpts") == 0 \
|
||||
|| strcmp (Fs_type, "tmpfs") == 0 \
|
||||
/* for NetBSD 3.0 */ \
|
||||
|| strcmp (Fs_type, "kernfs") == 0 \
|
||||
/* for Irix 6.5 */ \
|
||||
|| strcmp (Fs_type, "ignore") == 0 \
|
||||
/* for MacOSX */ \
|
||||
|| strcmp (Fs_type, "devfs") == 0 \
|
||||
|| strcmp (Fs_type, "fdesc") == 0 \
|
||||
|| strcmp (Fs_type, "nfs") == 0 \
|
||||
|| strcmp (Fs_type, "volfs") == 0)
|
||||
#endif
|
||||
|
||||
#ifndef ME_REMOTE
|
||||
/* A file system is `remote' if its Fs_name contains a `:'
|
||||
or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */
|
||||
# define ME_REMOTE(Fs_name, Fs_type) \
|
||||
(strchr (Fs_name, ':') != NULL \
|
||||
|| ((Fs_name)[0] == '/' \
|
||||
&& (Fs_name)[1] == '/' \
|
||||
&& (strcmp (Fs_type, "smbfs") == 0 \
|
||||
|| strcmp (Fs_type, "cifs") == 0)))
|
||||
#endif
|
||||
#endif // HAIKU / BEOS
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO
|
||||
|
||||
# if ! HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
static const char *
|
||||
fstype_to_string (short int t)
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
# ifdef MOUNT_PC
|
||||
case MOUNT_PC:
|
||||
return "pc";
|
||||
# endif
|
||||
# ifdef MOUNT_MFS
|
||||
case MOUNT_MFS:
|
||||
return "mfs";
|
||||
# endif
|
||||
# ifdef MOUNT_LO
|
||||
case MOUNT_LO:
|
||||
return "lo";
|
||||
# endif
|
||||
# ifdef MOUNT_TFS
|
||||
case MOUNT_TFS:
|
||||
return "tfs";
|
||||
# endif
|
||||
# ifdef MOUNT_TMP
|
||||
case MOUNT_TMP:
|
||||
return "tmp";
|
||||
# endif
|
||||
# ifdef MOUNT_UFS
|
||||
case MOUNT_UFS:
|
||||
return "ufs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_NFS
|
||||
case MOUNT_NFS:
|
||||
return "nfs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_MSDOS
|
||||
case MOUNT_MSDOS:
|
||||
return "msdos" ;
|
||||
# endif
|
||||
# ifdef MOUNT_LFS
|
||||
case MOUNT_LFS:
|
||||
return "lfs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_LOFS
|
||||
case MOUNT_LOFS:
|
||||
return "lofs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_FDESC
|
||||
case MOUNT_FDESC:
|
||||
return "fdesc" ;
|
||||
# endif
|
||||
# ifdef MOUNT_PORTAL
|
||||
case MOUNT_PORTAL:
|
||||
return "portal" ;
|
||||
# endif
|
||||
# ifdef MOUNT_NULL
|
||||
case MOUNT_NULL:
|
||||
return "null" ;
|
||||
# endif
|
||||
# ifdef MOUNT_UMAP
|
||||
case MOUNT_UMAP:
|
||||
return "umap" ;
|
||||
# endif
|
||||
# ifdef MOUNT_KERNFS
|
||||
case MOUNT_KERNFS:
|
||||
return "kernfs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_PROCFS
|
||||
case MOUNT_PROCFS:
|
||||
return "procfs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_AFS
|
||||
case MOUNT_AFS:
|
||||
return "afs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_CD9660
|
||||
case MOUNT_CD9660:
|
||||
return "cd9660" ;
|
||||
# endif
|
||||
# ifdef MOUNT_UNION
|
||||
case MOUNT_UNION:
|
||||
return "union" ;
|
||||
# endif
|
||||
# ifdef MOUNT_DEVFS
|
||||
case MOUNT_DEVFS:
|
||||
return "devfs" ;
|
||||
# endif
|
||||
# ifdef MOUNT_EXT2FS
|
||||
case MOUNT_EXT2FS:
|
||||
return "ext2fs" ;
|
||||
# endif
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
static const char *
|
||||
fsp_to_string (const struct statfs *fsp)
|
||||
{
|
||||
# if HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
return (char *) (fsp->f_fstypename);
|
||||
# else
|
||||
return fstype_to_string (fsp->f_type);
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
static char *
|
||||
fstype_to_string (int t)
|
||||
{
|
||||
struct vfs_ent *e;
|
||||
|
||||
e = getvfsbytype (t);
|
||||
if (!e || !e->vfsent_name)
|
||||
return "none";
|
||||
else
|
||||
return e->vfsent_name;
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT */
|
||||
|
||||
#if defined MOUNTED_GETMNTENT1 || defined MOUNTED_GETMNTENT2
|
||||
|
||||
/* Return the device number from MOUNT_OPTIONS, if possible.
|
||||
Otherwise return (dev_t) -1. */
|
||||
|
||||
static dev_t
|
||||
dev_from_mount_options (char const *mount_options)
|
||||
{
|
||||
/* GNU/Linux allows file system implementations to define their own
|
||||
meaning for "dev=" mount options, so don't trust the meaning
|
||||
here. */
|
||||
# ifndef __linux__
|
||||
static char const dev_pattern[] = ",dev=";
|
||||
char const *devopt = strstr (mount_options, dev_pattern);
|
||||
|
||||
if (devopt)
|
||||
{
|
||||
char const *optval = devopt + sizeof dev_pattern - 1;
|
||||
char *optvalend;
|
||||
unsigned long int dev;
|
||||
errno = 0;
|
||||
dev = strtoul (optval, &optvalend, 16);
|
||||
if (optval != optvalend
|
||||
&& (*optvalend == '\0' || *optvalend == ',')
|
||||
&& ! (dev == ULONG_MAX && errno == ERANGE)
|
||||
&& dev == (dev_t) dev)
|
||||
return dev;
|
||||
}
|
||||
#else
|
||||
(void)mount_options; // unused
|
||||
# endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Return a list of the currently mounted file systems, or NULL on error.
|
||||
Add each entry to the tail of the list so that they stay in order.
|
||||
If NEED_FS_TYPE is true, ensure that the file system type fields in
|
||||
the returned list are valid. Otherwise, they might not be. */
|
||||
|
||||
struct mount_entry *
|
||||
read_file_system_list (bool need_fs_type)
|
||||
{
|
||||
struct mount_entry *mount_list;
|
||||
struct mount_entry *me;
|
||||
struct mount_entry **mtail = &mount_list;
|
||||
(void)need_fs_type; // may be unused
|
||||
|
||||
#ifdef MOUNTED_LISTMNTENT
|
||||
{
|
||||
struct tabmntent *mntlist, *p;
|
||||
struct mntent *mnt;
|
||||
struct mount_entry *me;
|
||||
|
||||
/* the third and fourth arguments could be used to filter mounts,
|
||||
but Crays doesn't seem to have any mounts that we want to
|
||||
remove. Specifically, automount create normal NFS mounts.
|
||||
*/
|
||||
|
||||
if (listmntent (&mntlist, KMTAB, NULL, NULL) < 0)
|
||||
return NULL;
|
||||
for (p = mntlist; p; p = p->next) {
|
||||
mnt = p->ment;
|
||||
me = xmalloc (sizeof *me);
|
||||
me->me_devname = xstrdup (mnt->mnt_fsname);
|
||||
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
||||
me->me_type = xstrdup (mnt->mnt_type);
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = -1;
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
freemntlist (mntlist);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
{
|
||||
struct mntent *mnt;
|
||||
const char *table = MOUNTED;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((mnt = getmntent (fp)))
|
||||
{
|
||||
me = (mount_entry *) malloc (sizeof *me);
|
||||
me->me_devname = strdup (mnt->mnt_fsname);
|
||||
me->me_mountdir = strdup (mnt->mnt_dir);
|
||||
me->me_type = strdup (mnt->mnt_type);
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = dev_from_mount_options (mnt->mnt_opts);
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
|
||||
if (endmntent (fp) == 0)
|
||||
goto free_then_fail;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT1. */
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||
{
|
||||
struct statfs *fsp;
|
||||
int entries;
|
||||
|
||||
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
||||
if (entries < 0)
|
||||
return NULL;
|
||||
for (; entries-- > 0; fsp++)
|
||||
{
|
||||
me = (mount_entry *) malloc (sizeof *me);
|
||||
me->me_devname = strdup (fsp->f_mntfromname);
|
||||
me->me_mountdir = strdup (fsp->f_mntonname);
|
||||
#if defined(__APPLE__) || defined(__OpenBSD__)
|
||||
me->me_type = fsp->f_fstypename;
|
||||
#else
|
||||
me->me_type = fsp->fs_typename;
|
||||
#endif
|
||||
me->me_type_malloced = 0;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */
|
||||
{
|
||||
struct statvfs *fsp;
|
||||
int entries;
|
||||
|
||||
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
||||
if (entries < 0)
|
||||
return NULL;
|
||||
for (; entries-- > 0; fsp++)
|
||||
{
|
||||
me = malloc (sizeof *me);
|
||||
me->me_devname = strdup (fsp->f_mntfromname);
|
||||
me->me_mountdir = strdup (fsp->f_mntonname);
|
||||
me->me_type = strdup (fsp->f_fstypename);
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTINFO2 */
|
||||
|
||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||
{
|
||||
int offset = 0;
|
||||
int val;
|
||||
struct fs_data fsd;
|
||||
|
||||
while (errno = 0,
|
||||
0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
|
||||
(char *) 0)))
|
||||
{
|
||||
me = xmalloc (sizeof *me);
|
||||
me->me_devname = xstrdup (fsd.fd_req.devname);
|
||||
me->me_mountdir = xstrdup (fsd.fd_req.path);
|
||||
me->me_type = gt_names[fsd.fd_req.fstype];
|
||||
me->me_type_malloced = 0;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = fsd.fd_req.dev;
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
if (val < 0)
|
||||
goto free_then_fail;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNT. */
|
||||
|
||||
#if defined MOUNTED_FS_STAT_DEV /* BeOS */
|
||||
{
|
||||
/* The next_dev() and fs_stat_dev() system calls give the list of
|
||||
all file systems, including the information returned by statvfs()
|
||||
(fs type, total blocks, free blocks etc.), but without the mount
|
||||
point. But on BeOS all file systems except / are mounted in the
|
||||
rootfs, directly under /.
|
||||
The directory name of the mount point is often, but not always,
|
||||
identical to the volume name of the device.
|
||||
We therefore get the list of subdirectories of /, and the list
|
||||
of all file systems, and match the two lists. */
|
||||
|
||||
DIR *dirp;
|
||||
struct rootdir_entry
|
||||
{
|
||||
char *name;
|
||||
dev_t dev;
|
||||
ino_t ino;
|
||||
struct rootdir_entry *next;
|
||||
};
|
||||
struct rootdir_entry *rootdir_list;
|
||||
struct rootdir_entry **rootdir_tail;
|
||||
int32 pos;
|
||||
dev_t dev;
|
||||
fs_info fi;
|
||||
|
||||
/* All volumes are mounted in the rootfs, directly under /. */
|
||||
rootdir_list = NULL;
|
||||
rootdir_tail = &rootdir_list;
|
||||
dirp = opendir ("/");
|
||||
if (dirp)
|
||||
{
|
||||
struct dirent *d;
|
||||
|
||||
while ((d = readdir (dirp)) != NULL)
|
||||
{
|
||||
char *name;
|
||||
struct stat statbuf;
|
||||
|
||||
if (strcmp (d->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
if (strcmp (d->d_name, ".") == 0)
|
||||
name = strdup ("/");
|
||||
else
|
||||
{
|
||||
name = malloc (1 + strlen (d->d_name) + 1);
|
||||
name[0] = '/';
|
||||
strcpy (name + 1, d->d_name);
|
||||
}
|
||||
|
||||
if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode))
|
||||
{
|
||||
struct rootdir_entry *re = malloc (sizeof *re);
|
||||
re->name = name;
|
||||
re->dev = statbuf.st_dev;
|
||||
re->ino = statbuf.st_ino;
|
||||
|
||||
/* Add to the linked list. */
|
||||
*rootdir_tail = re;
|
||||
rootdir_tail = &re->next;
|
||||
}
|
||||
else
|
||||
free (name);
|
||||
}
|
||||
closedir (dirp);
|
||||
}
|
||||
*rootdir_tail = NULL;
|
||||
|
||||
for (pos = 0; (dev = next_dev (&pos)) >= 0; )
|
||||
if (fs_stat_dev (dev, &fi) >= 0)
|
||||
{
|
||||
/* Note: fi.dev == dev. */
|
||||
struct rootdir_entry *re;
|
||||
|
||||
for (re = rootdir_list; re; re = re->next)
|
||||
if (re->dev == fi.dev && re->ino == fi.root)
|
||||
break;
|
||||
|
||||
me = malloc (sizeof *me);
|
||||
me->me_devname = strdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name);
|
||||
me->me_mountdir = strdup (re != NULL ? re->name : fi.fsh_name);
|
||||
me->me_type = strdup (fi.fsh_name);
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dev = fi.dev;
|
||||
me->me_dummy = 0;
|
||||
me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0;
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
*mtail = NULL;
|
||||
|
||||
while (rootdir_list != NULL)
|
||||
{
|
||||
struct rootdir_entry *re = rootdir_list;
|
||||
rootdir_list = re->next;
|
||||
free (re->name);
|
||||
free (re);
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_FS_STAT_DEV */
|
||||
|
||||
#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */
|
||||
{
|
||||
int numsys, counter;
|
||||
size_t bufsize;
|
||||
struct statfs *stats;
|
||||
|
||||
numsys = getfsstat ((struct statfs *)0, 0L, MNT_NOWAIT);
|
||||
if (numsys < 0)
|
||||
return (NULL);
|
||||
/*
|
||||
if (SIZE_MAX / sizeof *stats <= numsys)
|
||||
xalloc_die ();*/
|
||||
|
||||
bufsize = (1 + numsys) * sizeof *stats;
|
||||
stats = malloc (bufsize);
|
||||
numsys = getfsstat (stats, bufsize, MNT_NOWAIT);
|
||||
|
||||
if (numsys < 0)
|
||||
{
|
||||
free (stats);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (counter = 0; counter < numsys; counter++)
|
||||
{
|
||||
me = malloc (sizeof *me);
|
||||
me->me_devname = strdup (stats[counter].f_mntfromname);
|
||||
me->me_mountdir = strdup (stats[counter].f_mntonname);
|
||||
//me->me_type = strdup (FS_TYPE (stats[counter]));
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
|
||||
free (stats);
|
||||
}
|
||||
#endif /* MOUNTED_GETFSSTAT */
|
||||
|
||||
#if defined MOUNTED_FREAD || defined MOUNTED_FREAD_FSTYP /* SVR[23]. */
|
||||
{
|
||||
struct mnttab mnt;
|
||||
char *table = "/etc/mnttab";
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while (fread (&mnt, sizeof mnt, 1, fp) > 0)
|
||||
{
|
||||
me = xmalloc (sizeof *me);
|
||||
# ifdef GETFSTYP /* SVR3. */
|
||||
me->me_devname = xstrdup (mnt.mt_dev);
|
||||
# else
|
||||
me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
|
||||
strcpy (me->me_devname, "/dev/");
|
||||
strcpy (me->me_devname + 5, mnt.mt_dev);
|
||||
# endif
|
||||
me->me_mountdir = xstrdup (mnt.mt_filsys);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_type = "";
|
||||
me->me_type_malloced = 0;
|
||||
# ifdef GETFSTYP /* SVR3. */
|
||||
if (need_fs_type)
|
||||
{
|
||||
struct statfs fsd;
|
||||
char typebuf[FSTYPSZ];
|
||||
|
||||
if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
|
||||
&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
|
||||
{
|
||||
me->me_type = xstrdup (typebuf);
|
||||
me->me_type_malloced = 1;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
{
|
||||
/* The last fread() call must have failed. */
|
||||
int saved_errno = errno;
|
||||
fclose (fp);
|
||||
errno = saved_errno;
|
||||
goto free_then_fail;
|
||||
}
|
||||
|
||||
if (fclose (fp) == EOF)
|
||||
goto free_then_fail;
|
||||
}
|
||||
#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
|
||||
|
||||
#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */
|
||||
{
|
||||
struct mntent **mnttbl = getmnttbl (), **ent;
|
||||
for (ent=mnttbl;*ent;ent++)
|
||||
{
|
||||
me = xmalloc (sizeof *me);
|
||||
me->me_devname = xstrdup ( (*ent)->mt_resource);
|
||||
me->me_mountdir = xstrdup ( (*ent)->mt_directory);
|
||||
me->me_type = xstrdup ((*ent)->mt_fstype);
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
endmnttbl ();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||
{
|
||||
struct mnttab mnt;
|
||||
char *table = MNTTAB;
|
||||
FILE *fp;
|
||||
int ret;
|
||||
int lockfd = -1;
|
||||
|
||||
# if defined F_RDLCK && defined F_SETLKW
|
||||
/* MNTTAB_LOCK is a macro name of our own invention; it's not present in
|
||||
e.g. Solaris 2.6. If the SVR4 folks ever define a macro
|
||||
for this file name, we should use their macro name instead.
|
||||
(Why not just lock MNTTAB directly? We don't know.) */
|
||||
# ifndef MNTTAB_LOCK
|
||||
# define MNTTAB_LOCK "/etc/.mnttab.lock"
|
||||
# endif
|
||||
lockfd = open (MNTTAB_LOCK, O_RDONLY);
|
||||
if (0 <= lockfd)
|
||||
{
|
||||
struct flock flock;
|
||||
flock.l_type = F_RDLCK;
|
||||
flock.l_whence = SEEK_SET;
|
||||
flock.l_start = 0;
|
||||
flock.l_len = 0;
|
||||
while (fcntl (lockfd, F_SETLKW, &flock) == -1)
|
||||
if (errno != EINTR)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
close (lockfd);
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (errno != ENOENT)
|
||||
return NULL;
|
||||
# endif
|
||||
|
||||
errno = 0;
|
||||
fp = fopen (table, "r");
|
||||
if (fp == NULL)
|
||||
ret = errno;
|
||||
else
|
||||
{
|
||||
while ((ret = getmntent (fp, &mnt)) == 0)
|
||||
{
|
||||
me = xmalloc (sizeof *me);
|
||||
me->me_devname = xstrdup (mnt.mnt_special);
|
||||
me->me_mountdir = xstrdup (mnt.mnt_mountp);
|
||||
me->me_type = xstrdup (mnt.mnt_fstype);
|
||||
me->me_type_malloced = 1;
|
||||
me->me_dummy = MNT_IGNORE (&mnt) != 0;
|
||||
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
||||
me->me_dev = dev_from_mount_options (mnt.mnt_mntopts);
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
|
||||
ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
|
||||
}
|
||||
|
||||
if (0 <= lockfd && close (lockfd) != 0)
|
||||
ret = errno;
|
||||
|
||||
if (0 <= ret)
|
||||
{
|
||||
errno = ret;
|
||||
goto free_then_fail;
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT2. */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
{
|
||||
int bufsize;
|
||||
char *entries, *thisent;
|
||||
struct vmount *vmp;
|
||||
int n_entries;
|
||||
int i;
|
||||
|
||||
/* Ask how many bytes to allocate for the mounted file system info. */
|
||||
if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0)
|
||||
return NULL;
|
||||
entries = xmalloc (bufsize);
|
||||
|
||||
/* Get the list of mounted file systems. */
|
||||
n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
|
||||
if (n_entries < 0)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (entries);
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0, thisent = entries;
|
||||
i < n_entries;
|
||||
i++, thisent += vmp->vmt_length)
|
||||
{
|
||||
char *options, *ignore;
|
||||
|
||||
vmp = (struct vmount *) thisent;
|
||||
me = xmalloc (sizeof *me);
|
||||
if (vmp->vmt_flags & MNT_REMOTE)
|
||||
{
|
||||
char *host, *dir;
|
||||
|
||||
me->me_remote = 1;
|
||||
/* Prepend the remote dirname. */
|
||||
host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
|
||||
dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
|
||||
me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2);
|
||||
strcpy (me->me_devname, host);
|
||||
strcat (me->me_devname, ":");
|
||||
strcat (me->me_devname, dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->me_remote = 0;
|
||||
me->me_devname = xstrdup (thisent +
|
||||
vmp->vmt_data[VMT_OBJECT].vmt_off);
|
||||
}
|
||||
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
|
||||
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
|
||||
me->me_type_malloced = 1;
|
||||
options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
|
||||
ignore = strstr (options, "ignore");
|
||||
me->me_dummy = (ignore
|
||||
&& (ignore == options || ignore[-1] == ',')
|
||||
&& (ignore[sizeof "ignore" - 1] == ','
|
||||
|| ignore[sizeof "ignore" - 1] == '\0'));
|
||||
me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
|
||||
|
||||
/* Add to the linked list. */
|
||||
*mtail = me;
|
||||
mtail = &me->me_next;
|
||||
}
|
||||
free (entries);
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT. */
|
||||
|
||||
*mtail = NULL;
|
||||
return mount_list;
|
||||
|
||||
|
||||
free_then_fail:
|
||||
{
|
||||
int saved_errno = errno;
|
||||
*mtail = NULL;
|
||||
|
||||
while (mount_list)
|
||||
{
|
||||
me = mount_list->me_next;
|
||||
free (mount_list->me_devname);
|
||||
free (mount_list->me_mountdir);
|
||||
if (mount_list->me_type_malloced)
|
||||
free (mount_list->me_type);
|
||||
free (mount_list);
|
||||
mount_list = me;
|
||||
}
|
||||
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void free_file_system_list(struct mount_entry * mount_list)
|
||||
{
|
||||
struct mount_entry * me;
|
||||
while (mount_list)
|
||||
{
|
||||
me = mount_list->me_next;
|
||||
free (mount_list->me_devname);
|
||||
free (mount_list->me_mountdir);
|
||||
if (mount_list->me_type_malloced)
|
||||
free (mount_list->me_type);
|
||||
free (mount_list);
|
||||
mount_list = me;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
/* vim:expandtab:ts=2 sw=2:
|
||||
*/
|
||||
/* mountlist.h -- declarations for list of mounted file systems
|
||||
|
||||
Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003, 2004, 2005
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
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 2, 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/>.
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
///@file mountlist.h
|
||||
/// A function to enumerate the mounting points in the filesystem.
|
||||
/// Used to display them in fileselectors.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MOUNTLIST_H_
|
||||
# define MOUNTLIST_H_
|
||||
|
||||
#if defined __GNUC__
|
||||
# include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* A mount table entry. */
|
||||
struct mount_entry
|
||||
{
|
||||
char *me_devname; /* Device node name, including "/dev/". */
|
||||
char *me_mountdir; /* Mount point directory name. */
|
||||
char *me_type; /* "nfs", "4.2", etc. */
|
||||
dev_t me_dev; /* Device number of me_mountdir. */
|
||||
unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */
|
||||
unsigned int me_remote : 1; /* Nonzero for remote fileystems. */
|
||||
unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */
|
||||
struct mount_entry *me_next;
|
||||
};
|
||||
|
||||
struct mount_entry *read_file_system_list (bool need_fs_type);
|
||||
|
||||
void free_file_system_list(struct mount_entry * mount_list);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,761 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include "eeprominterface.h"
|
||||
#include "rlefile.h"
|
||||
|
||||
RleFile::RleFile():
|
||||
eeprom(NULL),
|
||||
eeprom_size(0),
|
||||
eeFs(NULL),
|
||||
eeFsArm(NULL),
|
||||
eepromFatHeader(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
#define EEPROM_SIZE (4*1024*1024/8)
|
||||
#define EEPROM_BLOCK_SIZE (4*1024)
|
||||
#define EEPROM_MARK 0x84697771 /* thanks ;) */
|
||||
#define EEPROM_ZONE_SIZE (8*1024)
|
||||
#define EEPROM_FAT_SIZE 128
|
||||
#define EEPROM_MAX_ZONES (EEPROM_SIZE / EEPROM_ZONE_SIZE)
|
||||
#define EEPROM_MAX_FILES (EEPROM_MAX_ZONES - 1)
|
||||
#define FIRST_FILE_AVAILABLE (1+MAX_MODELS)
|
||||
|
||||
void RleFile::EeFsCreate(uint8_t *eeprom, int size, BoardEnum board, unsigned int version)
|
||||
{
|
||||
this->eeprom = eeprom;
|
||||
this->eeprom_size = size;
|
||||
this->board = board;
|
||||
this->version = version;
|
||||
|
||||
if (IS_SKY9X(board)) {
|
||||
memset(eeprom, 0xFF, size);
|
||||
if (version >= 217) {
|
||||
memset(eeprom, 0, EEPROM_FAT_SIZE);
|
||||
eepromFatHeader = (EepromHeader *)(eeprom + EEPROM_FAT_SIZE);
|
||||
eepromFatHeader->mark = EEPROM_MARK;
|
||||
eepromFatHeader->index = 1;
|
||||
for (int i=0; i<EEPROM_MAX_FILES; i++) {
|
||||
eepromFatHeader->files[i].exists = 0;
|
||||
eepromFatHeader->files[i].zoneIndex = i+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IS_TARANIS(board)) {
|
||||
eeFsArm = (EeFsArm *)eeprom;
|
||||
eeFsVersion = 5;
|
||||
eeFsSize = 8+4*62;
|
||||
eeFsBlockSize = 64;
|
||||
eeFsFirstBlock = 1;
|
||||
eeFsBlocksOffset = eeFsSize - eeFsBlockSize;
|
||||
eeFsBlocksMax = 1 + (EESIZE_TARANIS-eeFsSize)/eeFsBlockSize;
|
||||
eeFsLinkSize = sizeof(int16_t);
|
||||
memset(eeprom, 0, size);
|
||||
eeFsArm->version = eeFsVersion;
|
||||
eeFsArm->mySize = eeFsSize;
|
||||
eeFsArm->freeList = 0;
|
||||
eeFsArm->bs = 64;
|
||||
for (unsigned int i=eeFsFirstBlock; i<eeFsBlocksMax-1; i++)
|
||||
EeFsSetLink(i, i+1);
|
||||
EeFsSetLink(eeFsBlocksMax-1, 0);
|
||||
eeFsArm->freeList = eeFsFirstBlock;
|
||||
// EeFsFlush();
|
||||
}
|
||||
else {
|
||||
eeFs = (EeFs *)eeprom;
|
||||
eeFsVersion = (IS_2560(board) || board==BOARD_M128) ? 5 : 4;
|
||||
eeFsBlockSize = 16;
|
||||
eeFsLinkSize = 1;
|
||||
|
||||
if (eeFsVersion == 5) {
|
||||
eeFsSize = 4+3*36;
|
||||
eeFsFirstBlock = 1;
|
||||
eeFsBlocksOffset = 112 - 16;
|
||||
eeFsBlocksMax = 1 + (4096-112)/16;
|
||||
}
|
||||
else {
|
||||
eeFsSize = 4+3*20;
|
||||
eeFsFirstBlock = 4;
|
||||
eeFsBlocksOffset = 0;
|
||||
eeFsBlocksMax = 2048/16;
|
||||
}
|
||||
|
||||
memset(eeprom, 0, size);
|
||||
eeFs->version = eeFsVersion;
|
||||
eeFs->mySize = eeFsSize;
|
||||
eeFs->freeList = 0;
|
||||
eeFs->bs = eeFsBlockSize;
|
||||
for (unsigned int i=eeFsFirstBlock; i<eeFsBlocksMax-1; i++)
|
||||
EeFsSetLink(i, i+1);
|
||||
EeFsSetLink(eeFsBlocksMax-1, 0);
|
||||
eeFs->freeList = eeFsFirstBlock;
|
||||
// EeFsFlush();
|
||||
}
|
||||
}
|
||||
|
||||
PACK(struct EepromFileHeader
|
||||
{
|
||||
uint16_t fileIndex;
|
||||
uint16_t size;
|
||||
});
|
||||
|
||||
bool RleFile::searchFat()
|
||||
{
|
||||
eepromFatHeader = NULL;
|
||||
uint32_t bestFatIndex = 0;
|
||||
for (int i=0; i<EEPROM_ZONE_SIZE/EEPROM_FAT_SIZE; i++) {
|
||||
EepromHeader * header = (EepromHeader *)(eeprom+i*EEPROM_FAT_SIZE);
|
||||
if (header->mark == EEPROM_MARK && header->index >= bestFatIndex) {
|
||||
eepromFatHeader = header;
|
||||
bestFatIndex = header->index;
|
||||
}
|
||||
}
|
||||
return (eepromFatHeader != NULL);
|
||||
}
|
||||
|
||||
bool RleFile::EeFsOpen(uint8_t *eeprom, int size, BoardEnum board)
|
||||
{
|
||||
this->eeprom = eeprom;
|
||||
this->eeprom_size = size;
|
||||
this->board = board;
|
||||
|
||||
if (IS_SKY9X(board)) {
|
||||
searchFat();
|
||||
return 1;
|
||||
}
|
||||
else if (IS_TARANIS(board)) {
|
||||
eeFsArm = (EeFsArm *)eeprom;
|
||||
eeFsVersion = eeFsArm->version;
|
||||
eeFsSize = 8+4*62;
|
||||
eeFsBlockSize = 64;
|
||||
eeFsLinkSize = sizeof(int16_t);
|
||||
eeFsFirstBlock = 1;
|
||||
eeFsBlocksOffset = eeFsSize - eeFsBlockSize;
|
||||
eeFsBlocksMax = 1 + (EESIZE_TARANIS-eeFsSize)/eeFsBlockSize;
|
||||
return eeFsArm->mySize == eeFsSize;
|
||||
}
|
||||
else {
|
||||
eeFs = (EeFs *)eeprom;
|
||||
eeFsVersion = eeFs->version;
|
||||
eeFsBlockSize = 16;
|
||||
eeFsLinkSize = 1;
|
||||
if (eeFsVersion == 5) {
|
||||
eeFsSize = 4+3*36;
|
||||
eeFsFirstBlock = 1;
|
||||
eeFsBlocksOffset = 112 - 16;
|
||||
eeFsBlocksMax = 1 + (4096-112)/16;
|
||||
}
|
||||
else if (eeFsVersion == 4) {
|
||||
eeFsSize = 4+3*20;
|
||||
eeFsFirstBlock = 4;
|
||||
eeFsBlocksOffset = 0;
|
||||
eeFsBlocksMax = 2048/16;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return eeFs->mySize == eeFsSize;
|
||||
}
|
||||
}
|
||||
|
||||
void RleFile::eeprom_read_block (void *pointer_ram, unsigned int pointer_eeprom, size_t size)
|
||||
{
|
||||
memcpy(pointer_ram, &eeprom[pointer_eeprom], size);
|
||||
}
|
||||
|
||||
void RleFile::eeprom_write_block(const void *pointer_ram, unsigned int pointer_eeprom, size_t size)
|
||||
{
|
||||
memcpy(&eeprom[pointer_eeprom], pointer_ram, size);
|
||||
}
|
||||
|
||||
uint8_t RleFile::EeFsRead(unsigned int blk, unsigned int ofs)
|
||||
{
|
||||
uint8_t ret;
|
||||
eeprom_read_block(&ret, blk*eeFsBlockSize+ofs+eeFsBlocksOffset, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void RleFile::EeFsWrite(unsigned int blk, unsigned int ofs, uint8_t val)
|
||||
{
|
||||
eeprom_write_block(&val, blk*eeFsBlockSize+ofs+eeFsBlocksOffset, 1);
|
||||
}
|
||||
|
||||
unsigned int RleFile::EeFsGetLink(unsigned int blk)
|
||||
{
|
||||
if (IS_ARM(board)) {
|
||||
int16_t ret;
|
||||
eeprom_read_block((uint8_t *)&ret, blk*eeFsBlockSize+eeFsBlocksOffset, eeFsLinkSize);
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return EeFsRead(blk, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void RleFile::EeFsSetLink(unsigned int blk, unsigned int val)
|
||||
{
|
||||
if (IS_ARM(board)) {
|
||||
int16_t s_link = val;
|
||||
eeprom_write_block((uint8_t *)&s_link, (blk*eeFsBlockSize)+eeFsBlocksOffset, eeFsLinkSize);
|
||||
}
|
||||
else {
|
||||
EeFsWrite(blk, 0, val);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t RleFile::EeFsGetDat(unsigned int blk, unsigned int ofs)
|
||||
{
|
||||
return EeFsRead(blk, ofs+eeFsLinkSize);
|
||||
}
|
||||
|
||||
void RleFile::EeFsSetDat(unsigned int blk, unsigned int ofs, const uint8_t *buf, unsigned int len)
|
||||
{
|
||||
eeprom_write_block(buf, blk*eeFsBlockSize+ofs+eeFsLinkSize+eeFsBlocksOffset, len);
|
||||
}
|
||||
|
||||
unsigned int RleFile::EeFsGetFree()
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
|
||||
unsigned int ret = 0;
|
||||
unsigned int i;
|
||||
if (IS_ARM(board))
|
||||
i = eeFsArm->freeList;
|
||||
else
|
||||
i = eeFs->freeList;
|
||||
|
||||
while (i) {
|
||||
ret += eeFsBlockSize-eeFsLinkSize;
|
||||
i = EeFsGetLink(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* free one or more blocks
|
||||
*/
|
||||
void RleFile::EeFsFree(unsigned int blk)
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return;
|
||||
|
||||
unsigned int i = blk;
|
||||
while (EeFsGetLink(i)) i = EeFsGetLink(i);
|
||||
if (IS_ARM(board)) {
|
||||
EeFsSetLink(i, eeFsArm->freeList);
|
||||
eeFsArm->freeList = blk; //chain in front
|
||||
}
|
||||
else {
|
||||
EeFsSetLink(i, eeFs->freeList);
|
||||
eeFs->freeList = blk; //chain in front
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* alloc one block from freelist
|
||||
*/
|
||||
unsigned int RleFile::EeFsAlloc()
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
unsigned int ret = (IS_ARM(board) ? eeFsArm->freeList : eeFs->freeList);
|
||||
if (ret) {
|
||||
if (IS_ARM(board))
|
||||
eeFsArm->freeList = EeFsGetLink(ret);
|
||||
else
|
||||
eeFs->freeList = EeFsGetLink(ret);
|
||||
EeFsSetLink(ret, 0);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int RleFile::size(unsigned int id)
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
else
|
||||
return IS_ARM(board) ? eeFsArm->files[id].size : eeFs->files[id].size;
|
||||
}
|
||||
|
||||
unsigned int RleFile::openRd(unsigned int i_fileId)
|
||||
{
|
||||
if (IS_HORUS(board)) {
|
||||
return 1;
|
||||
}
|
||||
else if (IS_SKY9X(board)) {
|
||||
if (eepromFatHeader) {
|
||||
m_fileId = eepromFatHeader->files[i_fileId].zoneIndex;
|
||||
if (eepromFatHeader->files[i_fileId].exists) {
|
||||
eeprom_read_block(&m_size, m_fileId*(1<<13)+sizeof(uint16_t), sizeof(uint16_t));
|
||||
}
|
||||
else {
|
||||
m_size = 0;
|
||||
}
|
||||
m_pos = sizeof(EepromFileHeader);
|
||||
}
|
||||
else {
|
||||
m_fileId = get_current_block_number(i_fileId * 2, &m_size);
|
||||
m_pos = sizeof(t_eeprom_header);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
m_fileId = i_fileId;
|
||||
m_pos = 0;
|
||||
m_currBlk = (IS_ARM(board) ? eeFsArm->files[m_fileId].startBlk : eeFs->files[m_fileId].startBlk);
|
||||
m_ofs = 0;
|
||||
m_zeroes = 0;
|
||||
m_bRlc = 0;
|
||||
m_err = ERR_NONE; //error reasons
|
||||
if (IS_ARM(board))
|
||||
return eeFsArm->files[m_fileId].typ;
|
||||
else
|
||||
return eeFs->files[m_fileId].typ;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int RleFile::read(uint8_t *buf, unsigned int i_len)
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
|
||||
unsigned int len = IS_ARM(board) ? eeFsArm->files[m_fileId].size : eeFs->files[m_fileId].size;
|
||||
len -= m_pos;
|
||||
if (i_len > len) i_len = len;
|
||||
len = i_len;
|
||||
while(len) {
|
||||
if (!m_currBlk) break;
|
||||
*buf++ = EeFsGetDat(m_currBlk, m_ofs++);
|
||||
if (m_ofs >= (eeFsBlockSize-(IS_ARM(board)? 2 : 1))) {
|
||||
m_ofs = 0;
|
||||
m_currBlk = EeFsGetLink(m_currBlk);
|
||||
}
|
||||
len--;
|
||||
}
|
||||
m_pos += i_len - len;
|
||||
return i_len - len;
|
||||
}
|
||||
|
||||
// G: Read runlength (RLE) compressed bytes into buf.
|
||||
unsigned int RleFile::readRlc12(uint8_t *buf, unsigned int i_len, bool rlc2)
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
|
||||
memset(buf, 0, i_len);
|
||||
|
||||
if (IS_SKY9X(board)) {
|
||||
int len;
|
||||
if (eepromFatHeader) {
|
||||
len = std::min((int)i_len, (int)m_size + (int)sizeof(EepromFileHeader) - (int)m_pos);
|
||||
eeprom_read_block(buf, (m_fileId << 13) + m_pos, len);
|
||||
m_pos += len;
|
||||
}
|
||||
else {
|
||||
len = std::min((int)i_len, (int)m_size + (int)sizeof(t_eeprom_header) - (int)m_pos);
|
||||
if (len > 0) {
|
||||
eeprom_read_block(buf, (m_fileId << 12) + m_pos, len);
|
||||
m_pos += len;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
else {
|
||||
unsigned int i=0;
|
||||
for( ; 1; ) {
|
||||
uint8_t ln = std::min<uint16_t>(m_zeroes, i_len-i);
|
||||
memset(&buf[i], 0, ln);
|
||||
i += ln;
|
||||
m_zeroes -= ln;
|
||||
if(m_zeroes) break;
|
||||
|
||||
ln = std::min<uint16_t>(m_bRlc, i_len-i);
|
||||
uint8_t lr = read(&buf[i], ln);
|
||||
i += lr ;
|
||||
m_bRlc -= lr;
|
||||
if(m_bRlc) break;
|
||||
|
||||
if (read(&m_bRlc, 1) !=1) break; //read how many bytes to read
|
||||
|
||||
if (!(m_bRlc & 0x7f)) {
|
||||
qDebug() << "RLC decoding error!";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rlc2) {
|
||||
if(m_bRlc&0x80){ // if contains high byte
|
||||
m_zeroes =(m_bRlc>>4) & 0x7;
|
||||
m_bRlc = m_bRlc & 0x0f;
|
||||
}
|
||||
else if(m_bRlc&0x40){
|
||||
m_zeroes = m_bRlc & 0x3f;
|
||||
m_bRlc = 0;
|
||||
}
|
||||
//else m_bRlc
|
||||
}
|
||||
else {
|
||||
if(m_bRlc&0x80){ // if contains high byte
|
||||
m_zeroes = m_bRlc & 0x7f;
|
||||
m_bRlc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int importRlc(QByteArray & dst, QByteArray & src, unsigned int rlcVersion)
|
||||
{
|
||||
uint8_t *buf = (uint8_t *)src.data();
|
||||
unsigned int len = src.size();
|
||||
uint8_t zeroes = 0;
|
||||
uint8_t bRlc = 0;
|
||||
|
||||
dst.resize(0);
|
||||
|
||||
for( ; 1; ) {
|
||||
if (zeroes > 0) {
|
||||
for (int i = 0; i < zeroes; i++)
|
||||
dst.append((char) 0);
|
||||
zeroes = 0;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
return dst.size();
|
||||
|
||||
for (int i=0; i<bRlc; i++) {
|
||||
dst.append(*buf++);
|
||||
if (--len == 0)
|
||||
return dst.size();
|
||||
}
|
||||
|
||||
bRlc = *buf++;
|
||||
--len;
|
||||
|
||||
if (!(bRlc & 0x7f)) {
|
||||
qDebug() << "RLC decoding error!";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rlcVersion == 2) {
|
||||
if (bRlc&0x80){ // if contains high byte
|
||||
zeroes = (bRlc>>4) & 0x07;
|
||||
bRlc = bRlc & 0x0f;
|
||||
}
|
||||
else if (bRlc&0x40){
|
||||
zeroes = bRlc & 0x3f;
|
||||
bRlc = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (bRlc&0x80){ // if contains high byte
|
||||
zeroes = bRlc & 0x7f;
|
||||
bRlc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst.size();
|
||||
}
|
||||
|
||||
unsigned int RleFile::write1(uint8_t b)
|
||||
{
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
unsigned int RleFile::write(const uint8_t *buf, unsigned int i_len)
|
||||
{
|
||||
unsigned int len = i_len;
|
||||
if (!m_currBlk && m_pos==0)
|
||||
{
|
||||
if (IS_ARM(board))
|
||||
eeFsArm->files[m_fileId].startBlk = m_currBlk = EeFsAlloc();
|
||||
else
|
||||
eeFs->files[m_fileId].startBlk = m_currBlk = EeFsAlloc();
|
||||
}
|
||||
while (len)
|
||||
{
|
||||
if (!m_currBlk) {
|
||||
m_err = ERR_FULL;
|
||||
return 0;
|
||||
}
|
||||
if (m_ofs >= eeFsBlockSize-eeFsLinkSize) {
|
||||
m_ofs = 0;
|
||||
if (!EeFsGetLink(m_currBlk) ){
|
||||
EeFsSetLink(m_currBlk, EeFsAlloc());
|
||||
}
|
||||
m_currBlk = EeFsGetLink(m_currBlk);
|
||||
}
|
||||
if (!m_currBlk) {
|
||||
m_err = ERR_FULL;
|
||||
return 0;
|
||||
}
|
||||
uint8_t l = eeFsBlockSize-eeFsLinkSize-m_ofs; if(l>len) l=len;
|
||||
EeFsSetDat(m_currBlk, m_ofs, buf, l);
|
||||
buf +=l;
|
||||
m_ofs +=l;
|
||||
len -=l;
|
||||
}
|
||||
m_pos += i_len - len;
|
||||
return i_len - len;
|
||||
}
|
||||
|
||||
void RleFile::create(unsigned int i_fileId, unsigned int typ)
|
||||
{
|
||||
openRd(i_fileId); //internal use
|
||||
if (IS_ARM(board)) {
|
||||
eeFsArm->files[i_fileId].typ = typ;
|
||||
eeFsArm->files[i_fileId].size = 0;
|
||||
}
|
||||
else {
|
||||
eeFs->files[i_fileId].typ = typ;
|
||||
eeFs->files[i_fileId].size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RleFile::closeTrunc()
|
||||
{
|
||||
unsigned int fri=0;
|
||||
if (IS_ARM(board))
|
||||
eeFsArm->files[m_fileId].size = m_pos;
|
||||
else
|
||||
eeFs->files[m_fileId].size = m_pos;
|
||||
if (m_currBlk && ( fri = EeFsGetLink(m_currBlk))) EeFsSetLink(m_currBlk, 0);
|
||||
if(fri) EeFsFree( fri ); //chain in
|
||||
}
|
||||
|
||||
unsigned int RleFile::writeRlc1(unsigned int i_fileId, unsigned int typ, const uint8_t *buf, unsigned int i_len)
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
|
||||
create(i_fileId, typ);
|
||||
bool state0 = true;
|
||||
uint8_t cnt = 0;
|
||||
uint16_t i;
|
||||
|
||||
//RLE compression:
|
||||
//rb = read byte
|
||||
//if (rb | 0x80) write rb & 0x7F zeros
|
||||
//else write rb bytes
|
||||
for (i=0; i<=i_len; i++)
|
||||
{
|
||||
bool nst0 = (buf[i] == 0);
|
||||
if (nst0 && !state0 && buf[i+1]!=0) nst0 = false ;
|
||||
if (nst0 != state0 || cnt>=0x7f || i==i_len) {
|
||||
if (state0) {
|
||||
if(cnt>0) {
|
||||
cnt |= 0x80;
|
||||
if (write(&cnt,1)!=1) goto error;
|
||||
cnt=0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cnt>0) {
|
||||
if (write(&cnt,1) !=1) goto error;
|
||||
uint8_t ret=write(&buf[i-cnt],cnt);
|
||||
if (ret!=cnt) { cnt-=ret; goto error;}
|
||||
cnt=0;
|
||||
}
|
||||
}
|
||||
state0 = nst0;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
if(0){
|
||||
error:
|
||||
i_len = i - (cnt & 0x7f);
|
||||
}
|
||||
closeTrunc();
|
||||
return i_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write runlength (RLE) compressed bytes
|
||||
*/
|
||||
unsigned int RleFile::writeRlc2(unsigned int i_fileId, unsigned int typ, const uint8_t *buf, unsigned int i_len)
|
||||
{
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
|
||||
if (IS_SKY9X(board)) {
|
||||
openRd(i_fileId);
|
||||
if (eepromFatHeader) {
|
||||
eepromFatHeader->files[i_fileId].exists = 1;
|
||||
eeprom_write_block(buf, (m_fileId << 13) + m_pos, i_len);
|
||||
{
|
||||
EepromFileHeader header;
|
||||
header.fileIndex = i_fileId;
|
||||
header.size = i_len;
|
||||
eeprom_write_block(&header, (m_fileId << 13), sizeof(header));
|
||||
}
|
||||
}
|
||||
else {
|
||||
eeprom_write_block(buf, (m_fileId << 12) + m_pos, i_len);
|
||||
t_eeprom_header header;
|
||||
header.sequence_no = 1;
|
||||
header.data_size = i_len;
|
||||
header.flags = 0;
|
||||
header.hcsum = byte_checksum((uint8_t *) &header, 7);
|
||||
eeprom_write_block(&header, (m_fileId << 12), sizeof(header));
|
||||
}
|
||||
return i_len;
|
||||
}
|
||||
else {
|
||||
create(i_fileId, typ);
|
||||
bool run0 = buf[0] == 0;
|
||||
uint8_t cnt = 1;
|
||||
uint8_t cnt0 = 0;
|
||||
uint16_t i = 0;
|
||||
if (i_len==0) goto close;
|
||||
|
||||
//RLE compression:
|
||||
//rb = read byte
|
||||
//if (rb | 0x80) write rb & 0x7F zeros
|
||||
//else write rb bytes
|
||||
for (i=1; 1; i++) { // !! laeuft ein byte zu weit !!
|
||||
bool cur0 = buf[i] == 0;
|
||||
if (i==i_len || cur0 != run0 || cnt==0x3f || (cnt0 && cnt==0xf)) {
|
||||
if (run0){
|
||||
assert(cnt0==0);
|
||||
if (cnt<8 && i!=i_len)
|
||||
cnt0 = cnt; //aufbew fuer spaeter
|
||||
else {
|
||||
if (write1(cnt|0x40)!=1) goto error;//-cnt&0x3f
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cnt0) {
|
||||
if (write1(0x80 | (cnt0<<4) | cnt)!=1) goto error;//-cnt0xx-cnt
|
||||
cnt0 = 0;
|
||||
}
|
||||
else {
|
||||
if (write1(cnt)!=1) goto error;//-cnt
|
||||
}
|
||||
uint8_t ret = write(&buf[i-cnt], cnt);
|
||||
if (ret != cnt) { cnt-=ret; goto error;}//-cnt
|
||||
}
|
||||
cnt=0;
|
||||
if (i==i_len) break;
|
||||
run0 = cur0;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
if (0) {
|
||||
error:
|
||||
i-=cnt+cnt0;
|
||||
}
|
||||
|
||||
close:
|
||||
closeTrunc();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t RleFile::byte_checksum( uint8_t *p, unsigned int size )
|
||||
{
|
||||
uint32_t csum ;
|
||||
|
||||
csum = 0 ;
|
||||
while( size )
|
||||
{
|
||||
csum += *p++ ;
|
||||
size -= 1 ;
|
||||
}
|
||||
return csum ;
|
||||
}
|
||||
|
||||
uint32_t RleFile::ee32_check_header( struct t_eeprom_header *hptr )
|
||||
{
|
||||
uint8_t csum ;
|
||||
|
||||
csum = byte_checksum( ( uint8_t *) hptr, 7 ) ;
|
||||
if ( csum == hptr->hcsum )
|
||||
{
|
||||
return 1 ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
// Pass in an even block number, this and the next block will be checked
|
||||
// to see which is the most recent, the block_no of the most recent
|
||||
// is returned, with the corresponding data size if required
|
||||
// and the sequence number if required
|
||||
uint32_t RleFile::get_current_block_number( uint32_t block_no, uint16_t *p_size)
|
||||
{
|
||||
struct t_eeprom_header b0 ;
|
||||
struct t_eeprom_header b1 ;
|
||||
// uint32_t sequence_no ;
|
||||
uint16_t size ;
|
||||
|
||||
eeprom_read_block( ( uint8_t *)&b0, block_no << 12, sizeof(b0) ) ; // Sequence # 0
|
||||
eeprom_read_block( ( uint8_t *)&b1, (block_no+1) << 12, sizeof(b1) ) ; // Sequence # 1
|
||||
|
||||
if ( ee32_check_header( &b0 ) == 0 )
|
||||
{
|
||||
b0.sequence_no = 0 ;
|
||||
b0.data_size = 0 ;
|
||||
b0.flags = 0 ;
|
||||
}
|
||||
|
||||
size = b0.data_size ;
|
||||
// sequence_no = b0.sequence_no ;
|
||||
if ( ee32_check_header( &b0 ) == 0 )
|
||||
{
|
||||
if ( ee32_check_header( &b1 ) != 0 )
|
||||
{
|
||||
size = b1.data_size ;
|
||||
// sequence_no = b1.sequence_no ;
|
||||
block_no += 1 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = 0 ;
|
||||
// sequence_no = 1 ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ee32_check_header( &b1 ) != 0 )
|
||||
{
|
||||
if ( b1.sequence_no > b0.sequence_no )
|
||||
{
|
||||
size = b1.data_size ;
|
||||
// sequence_no = b1.sequence_no ;
|
||||
block_no += 1 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( size == 0xFFFF )
|
||||
{
|
||||
size = 0 ;
|
||||
}
|
||||
if ( p_size )
|
||||
{
|
||||
*p_size = size ;
|
||||
}
|
||||
|
||||
return block_no ;
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
// TODO should be rle
|
||||
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef rlefile_h
|
||||
#define rlefile_h
|
||||
|
||||
#include "eeprominterface.h"
|
||||
|
||||
#define ERR_NONE 0
|
||||
#define ERR_FULL 1
|
||||
#define ERR_TMO 2
|
||||
|
||||
PACK(struct DirEnt {
|
||||
uint8_t startBlk;
|
||||
uint16_t size:12;
|
||||
uint16_t typ:4;
|
||||
});
|
||||
|
||||
PACK(struct DirEntArm {
|
||||
uint16_t startBlk;
|
||||
uint16_t size:12;
|
||||
uint16_t typ:4;
|
||||
});
|
||||
|
||||
PACK(struct EeFs{
|
||||
uint8_t version;
|
||||
uint8_t mySize;
|
||||
uint8_t freeList;
|
||||
uint8_t bs;
|
||||
DirEnt files[36];
|
||||
});
|
||||
|
||||
PACK(struct EeFsArm {
|
||||
uint8_t version;
|
||||
uint16_t mySize;
|
||||
uint16_t freeList;
|
||||
uint8_t bs;
|
||||
uint8_t spare[2];
|
||||
DirEntArm files[62];
|
||||
});
|
||||
|
||||
struct t_eeprom_header
|
||||
{
|
||||
uint32_t sequence_no ; // sequence # to decide which block is most recent
|
||||
uint16_t data_size ; // # bytes in data area
|
||||
uint8_t flags ;
|
||||
uint8_t hcsum ;
|
||||
};
|
||||
|
||||
PACK(struct EepromHeaderFile
|
||||
{
|
||||
uint8_t zoneIndex:7;
|
||||
uint8_t exists:1;
|
||||
});
|
||||
|
||||
PACK(struct EepromHeader
|
||||
{
|
||||
uint32_t mark;
|
||||
uint32_t index;
|
||||
EepromHeaderFile files[63];
|
||||
});
|
||||
|
||||
class RleFile
|
||||
{
|
||||
uint8_t m_fileId; //index of file in directory = filename
|
||||
unsigned int m_pos; //over all filepos
|
||||
unsigned int m_currBlk; //current block.id
|
||||
unsigned int m_ofs; //offset inside of the current block
|
||||
uint8_t m_zeroes; //control byte for run length decoder
|
||||
uint8_t m_bRlc; //control byte for run length decoder
|
||||
unsigned int m_err; //error reasons
|
||||
uint16_t m_size;
|
||||
|
||||
BoardEnum board;
|
||||
unsigned int version;
|
||||
uint8_t *eeprom;
|
||||
unsigned int eeprom_size;
|
||||
EeFs *eeFs;
|
||||
EeFsArm *eeFsArm;
|
||||
unsigned int eeFsVersion;
|
||||
unsigned int eeFsBlockSize;
|
||||
unsigned int eeFsSize;
|
||||
unsigned int eeFsFirstBlock;
|
||||
unsigned int eeFsBlocksOffset;
|
||||
unsigned int eeFsBlocksMax;
|
||||
unsigned int eeFsLinkSize;
|
||||
|
||||
EepromHeader * eepromFatHeader;
|
||||
|
||||
void eeprom_read_block (void *pointer_ram, unsigned int pointer_eeprom, size_t size);
|
||||
void eeprom_write_block(const void *pointer_ram, unsigned int pointer_eeprom, size_t size);
|
||||
|
||||
uint8_t EeFsRead(unsigned int blk, unsigned int ofs);
|
||||
void EeFsWrite(unsigned int blk, unsigned int ofs, uint8_t val);
|
||||
|
||||
unsigned int EeFsGetLink(unsigned int blk);
|
||||
void EeFsSetLink(unsigned int blk, unsigned int val);
|
||||
uint8_t EeFsGetDat(unsigned int blk, unsigned int ofs);
|
||||
void EeFsSetDat(unsigned int blk, unsigned int ofs, const uint8_t *buf, unsigned int len);
|
||||
unsigned int EeFsGetFree();
|
||||
void EeFsFree(unsigned int blk); // free one or more blocks
|
||||
unsigned int EeFsAlloc(); // alloc one block from freelist
|
||||
bool searchFat();
|
||||
|
||||
public:
|
||||
|
||||
RleFile();
|
||||
|
||||
void EeFsCreate(uint8_t *eeprom, int size, BoardEnum board, unsigned int version);
|
||||
|
||||
bool EeFsOpen(uint8_t *eeprom, int size, BoardEnum board);
|
||||
|
||||
///open file for reading, no close necessary
|
||||
///for writing use writeRlc() or create()
|
||||
unsigned int openRd(unsigned int i_fileId);
|
||||
/// create a new file with given fileId,
|
||||
/// !!! if this file already exists, then all blocks are reused
|
||||
/// and all contents will be overwritten.
|
||||
/// after writing closeTrunc has to be called
|
||||
void create(unsigned int i_fileId, unsigned int typ);
|
||||
/// close file and truncate the blockchain if to long.
|
||||
void closeTrunc();
|
||||
|
||||
///open file, write to file and close it.
|
||||
///If file existed before, then contents is overwritten.
|
||||
///If file was larger before, then unused blocks are freed
|
||||
unsigned int writeRlc1(unsigned int i_fileId, unsigned int typ, const uint8_t *buf, unsigned int i_len);
|
||||
unsigned int writeRlc2(unsigned int i_fileId, unsigned int typ, const uint8_t *buf, unsigned int i_len);
|
||||
|
||||
unsigned int read(uint8_t *buf, unsigned int i_len);
|
||||
unsigned int write1(uint8_t b);
|
||||
unsigned int write(const uint8_t *buf, unsigned int i_len);
|
||||
|
||||
///return size of compressed file without block overhead
|
||||
unsigned int size(unsigned int id);
|
||||
///read from opened file and decode rlc-coded data
|
||||
unsigned int readRlc12(uint8_t *buf, unsigned int i_len, bool rlc2);
|
||||
inline unsigned int readRlc1(uint8_t *buf, unsigned int i_len)
|
||||
{
|
||||
return readRlc12(buf, i_len, false);
|
||||
}
|
||||
inline unsigned int readRlc2(uint8_t *buf, unsigned int i_len)
|
||||
{
|
||||
return readRlc12(buf, i_len, true);
|
||||
}
|
||||
|
||||
uint8_t byte_checksum(uint8_t *p, unsigned int size);
|
||||
unsigned int ee32_check_header(struct t_eeprom_header *hptr);
|
||||
unsigned int get_current_block_number(unsigned int block_no, uint16_t *p_size);
|
||||
};
|
||||
|
||||
unsigned int importRlc(QByteArray & dst, QByteArray & src, unsigned int rlcVersion=2);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,106 @@
|
||||
#include <QFile>
|
||||
#include "firmwareinterface.h"
|
||||
#include "storage_eeprom.h"
|
||||
|
||||
|
||||
unsigned long LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size)
|
||||
{
|
||||
std::bitset<NUM_ERRORS> errors;
|
||||
|
||||
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
||||
std::bitset<NUM_ERRORS> result((unsigned long long)eepromInterface->load(radioData, eeprom, size));
|
||||
if (result.test(ALL_OK)) {
|
||||
return result.to_ulong();
|
||||
}
|
||||
else {
|
||||
errors |= result;
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.none()) {
|
||||
errors.set(UNKNOWN_ERROR);
|
||||
}
|
||||
return errors.to_ulong();
|
||||
}
|
||||
|
||||
unsigned long LoadBackup(RadioData & radioData, uint8_t * eeprom, int size, int index)
|
||||
{
|
||||
std::bitset<NUM_ERRORS> errors;
|
||||
|
||||
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
||||
std::bitset<NUM_ERRORS> result((unsigned long long)eepromInterface->loadBackup(radioData, eeprom, size, index));
|
||||
if (result.test(ALL_OK)) {
|
||||
return result.to_ulong();
|
||||
}
|
||||
else {
|
||||
errors |= result;
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.none()) {
|
||||
errors.set(UNKNOWN_ERROR);
|
||||
}
|
||||
return errors.to_ulong();
|
||||
}
|
||||
|
||||
|
||||
unsigned long LoadEepromXml(RadioData & radioData, QDomDocument & doc)
|
||||
{
|
||||
std::bitset<NUM_ERRORS> errors;
|
||||
|
||||
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
||||
std::bitset<NUM_ERRORS> result((unsigned long long)eepromInterface->loadxml(radioData, doc));
|
||||
if (result.test(ALL_OK)) {
|
||||
return result.to_ulong();
|
||||
}
|
||||
else {
|
||||
errors |= result;
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.none()) {
|
||||
errors.set(UNKNOWN_ERROR);
|
||||
}
|
||||
return errors.to_ulong();
|
||||
}
|
||||
|
||||
bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom, const QString &firmwareFilename)
|
||||
{
|
||||
Firmware *currentFirmware = GetCurrentFirmware();
|
||||
FirmwareInterface firmware(firmwareFilename);
|
||||
if (!firmware.isValid())
|
||||
return false;
|
||||
|
||||
unsigned int version = firmware.getEEpromVersion();
|
||||
unsigned int variant = firmware.getEEpromVariant();
|
||||
|
||||
QFile sourceFile(sourceEEprom);
|
||||
int eeprom_size = sourceFile.size();
|
||||
if (!eeprom_size)
|
||||
return false;
|
||||
|
||||
if (!sourceFile.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
|
||||
QByteArray eeprom(eeprom_size, 0);
|
||||
long result = sourceFile.read(eeprom.data(), eeprom_size);
|
||||
sourceFile.close();
|
||||
|
||||
QSharedPointer<RadioData> radioData = QSharedPointer<RadioData>(new RadioData());
|
||||
std::bitset<NUM_ERRORS> errors((unsigned long long)LoadEeprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size));
|
||||
if (!errors.test(ALL_OK)
|
||||
|| !currentFirmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile destinationFile(destinationEEprom);
|
||||
if (!destinationFile.open(QIODevice::WriteOnly))
|
||||
return false;
|
||||
|
||||
result = destinationFile.write(eeprom.constData(), eeprom_size);
|
||||
destinationFile.close();
|
||||
if (result != eeprom_size)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef storage_eeprom_h
|
||||
#define storage_eeprom_h
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QString>
|
||||
#include "eeprominterface.h"
|
||||
|
||||
unsigned long LoadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index);
|
||||
unsigned long LoadEeprom(RadioData &radioData, const uint8_t *eeprom, int size);
|
||||
unsigned long LoadEepromXml(RadioData &radioData, QDomDocument &doc);
|
||||
bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom, const QString &firmware);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,280 @@
|
||||
#include <QFileInfo>
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
#include "storage_sdcard.h"
|
||||
|
||||
// defines for miniz
|
||||
#include "miniz.c"
|
||||
|
||||
int readFromArchive(QByteArray & data, mz_zip_archive * zip_archive, unsigned int index)
|
||||
{
|
||||
size_t uncompSize;
|
||||
void * uncompData = mz_zip_reader_extract_to_heap(zip_archive, index, &uncompSize, 0);
|
||||
if (!uncompData) {
|
||||
return -1;
|
||||
}
|
||||
qDebug() << "Extracted file with index" << index << ",size" << uncompSize;
|
||||
data.append((const char *)uncompData, uncompSize);
|
||||
mz_free(uncompData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int StorageSdcard::read(const QString & path)
|
||||
{
|
||||
return QFileInfo(path).isDir() ? readSdcard(path) : readOtx(path);
|
||||
}
|
||||
|
||||
int StorageSdcard::write(const QString & path)
|
||||
{
|
||||
return QFileInfo(path).isDir() ? writeSdcard(path) : writeOtx(path);
|
||||
}
|
||||
|
||||
int StorageSdcard::readOtx(const QString & path)
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
lastErrorMessage = QObject::tr("Error opening file %1:\n%2.").arg(path).arg(file.errorString());
|
||||
return -1;
|
||||
}
|
||||
QByteArray archiveContents = file.readAll();
|
||||
file.close();
|
||||
qDebug() << "File" << path << "read, size:" << archiveContents.size();
|
||||
|
||||
// open zip file
|
||||
mz_zip_archive zip_archive;
|
||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||
if (!mz_zip_reader_init_mem(&zip_archive, archiveContents.data(), archiveContents.size(), 0)) {
|
||||
lastErrorMessage = QObject::tr("Error opening OTX archive %1.").arg(path);
|
||||
qDebug() << lastErrorMessage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// go trough all files in an archive
|
||||
QRegularExpression regexModel("MODELS/\\w+.bin", QRegularExpression::CaseInsensitiveOption);
|
||||
for (unsigned int i = 0; i < mz_zip_reader_get_num_files(&zip_archive); i++)
|
||||
{
|
||||
mz_zip_archive_file_stat file_stat;
|
||||
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) {
|
||||
lastErrorMessage = QObject::tr("mz_zip_reader_file_stat() failed!");
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
// printf("Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u, Is Dir: %u\n", file_stat.m_filename, file_stat.m_comment, (uint)file_stat.m_uncomp_size, (uint)file_stat.m_comp_size, mz_zip_reader_is_file_a_directory(&zip_archive, i));
|
||||
|
||||
if (mz_zip_reader_is_file_a_directory(&zip_archive, i)) continue;
|
||||
|
||||
QString filename(file_stat.m_filename);
|
||||
if (regexModel.match(filename).hasMatch()) {
|
||||
qDebug() << "found model:" << filename;
|
||||
models.append(ModelFile());
|
||||
ModelFile & newModel = models.last();
|
||||
newModel.filename = QFileInfo(filename).fileName();
|
||||
if (readFromArchive(newModel.data, &zip_archive, i) < 0) {
|
||||
lastErrorMessage = QObject::tr("Can't extract file %1").arg(filename);
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (QString::compare(filename, "RADIO/radio.bin", Qt::CaseInsensitive) == 0) {
|
||||
if (readFromArchive(radio, &zip_archive, i) < 0) {
|
||||
lastErrorMessage = QObject::tr("Can't extract file %1").arg(filename);
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (QString::compare(filename, "RADIO/models.txt", Qt::CaseInsensitive) == 0) {
|
||||
if (readFromArchive(modelList, &zip_archive, i) < 0) {
|
||||
lastErrorMessage = QObject::tr("Can't extract file %1").arg(filename);
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
qDebug() << "Unknown file " << filename;
|
||||
}
|
||||
|
||||
}
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StorageSdcard::readFile(QByteArray & data, const QString & path)
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
lastErrorMessage = QObject::tr("Error opening file %1:\n%2.").arg(path).arg(file.errorString());
|
||||
throw StorageSdcardReadFileError();
|
||||
}
|
||||
data = file.readAll();
|
||||
file.close();
|
||||
qDebug() << "File" << path << "read, size:" << data.size();
|
||||
}
|
||||
|
||||
int StorageSdcard::readSdcard(const QString & path)
|
||||
{
|
||||
try {
|
||||
readFile(radio, path + "/RADIO/radio.bin");
|
||||
readFile(modelList, path + "RADIO/models.txt");
|
||||
|
||||
QDir dir(path + "MODELS/");
|
||||
QStringList filters;
|
||||
filters << "*.bin";
|
||||
foreach(QString filename, dir.entryList(filters, QDir::Files)) {
|
||||
qDebug() << "found" << filename;
|
||||
models.append(ModelFile());
|
||||
ModelFile & newModel = models.last();
|
||||
newModel.filename = QFileInfo(filename).fileName();
|
||||
readFile(newModel.data, path + "MODELS/" + filename);
|
||||
}
|
||||
}
|
||||
catch (StorageSdcardReadFileError) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StorageSdcard::writeFile(const QByteArray & data, const QString & path)
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QFile::WriteOnly)) {
|
||||
lastErrorMessage = QObject::tr("Error opening file %1:\n%2.").arg(path).arg(file.errorString());
|
||||
throw StorageSdcardWriteFileError();
|
||||
}
|
||||
file.write(data.data(), data.size());
|
||||
file.close();
|
||||
qDebug() << "File" << path << "written, size:" << data.size();
|
||||
}
|
||||
|
||||
int StorageSdcard::writeSdcard(const QString & path)
|
||||
{
|
||||
try {
|
||||
QDir dir(path);
|
||||
dir.mkdir("RADIO");
|
||||
writeFile(radio, path + "/RADIO/radio.bin");
|
||||
writeFile(modelList, path + "RADIO/models.txt");
|
||||
|
||||
dir.mkdir("MODELS");
|
||||
for (QList<ModelFile>::const_iterator i = models.begin(); i != models.end(); ++i) {
|
||||
qDebug() << "writing" << i->filename;
|
||||
writeFile(i->data, path + "MODELS/" + i->filename);
|
||||
}
|
||||
}
|
||||
catch (StorageSdcardWriteFileError) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MZ_ALLOCATION_SIZE (32*1024)
|
||||
|
||||
int StorageSdcard::writeOtx(const QString & path)
|
||||
{
|
||||
qDebug() << "Saving to archive" << path;
|
||||
mz_zip_archive zip_archive;
|
||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||
|
||||
if (!mz_zip_writer_init_heap(&zip_archive, 0, MZ_ALLOCATION_SIZE)) {
|
||||
lastErrorMessage = QObject::tr("Error initializing OTX archive writer");
|
||||
qDebug() << lastErrorMessage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// add radio.bin
|
||||
if (!mz_zip_writer_add_mem(&zip_archive, "RADIO/radio.bin", radio.data(), radio.size(), MZ_DEFAULT_LEVEL)) {
|
||||
lastErrorMessage = QObject::tr("Error adding %1 to OTX archive").arg("RADIO/radio.bin");
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// add models.txt
|
||||
if (!mz_zip_writer_add_mem(&zip_archive, "RADIO/models.txt", modelList.data(), modelList.size(), MZ_DEFAULT_LEVEL)) {
|
||||
lastErrorMessage = QObject::tr("Error adding %1 to OTX archive").arg("RADIO/models.txt");
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// add all models
|
||||
for (QList<ModelFile>::iterator i = models.begin(); i != models.end(); ++i) {
|
||||
QString filename = "MODELS/" + i->filename;
|
||||
qDebug() << "\tadding model:" << filename << "size" << i->data.size();
|
||||
if (!mz_zip_writer_add_mem(&zip_archive, filename.toLatin1(), i->data.data(), i->data.size(), MZ_DEFAULT_LEVEL)) {
|
||||
lastErrorMessage = QObject::tr("Error adding %1 to OTX archive").arg(filename);
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// finalize archive and get contents
|
||||
char * archiveContents;
|
||||
size_t archiveSize;
|
||||
if (!mz_zip_writer_finalize_heap_archive(&zip_archive, (void **)&archiveContents, &archiveSize)) {
|
||||
lastErrorMessage = QObject::tr("Error creating OTX archive");
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
qDebug() << "Archive size" << archiveSize;
|
||||
|
||||
// write contents to file
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
lastErrorMessage = QObject::tr("Error creating OTX file %1:\n%2.").arg(path).arg(file.errorString());
|
||||
qDebug() << lastErrorMessage;
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qint64 result = file.write(archiveContents, archiveSize);
|
||||
if(result != (qint64)archiveSize) {
|
||||
lastErrorMessage = QObject::tr("Error writing file %1:\n%2.").arg(path).arg(file.errorString());
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return -1;
|
||||
}
|
||||
file.close();
|
||||
|
||||
mz_zip_writer_end(&zip_archive);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const QByteArray & StorageSdcard::getModelData(const QString & filename) const
|
||||
{
|
||||
for (QList<ModelFile>::const_iterator i = models.begin(); i != models.end(); ++i) {
|
||||
if (filename == i->filename) return i->data;
|
||||
}
|
||||
throw StorageSdcardModelNotFound();
|
||||
}
|
||||
|
||||
|
||||
QList<ModelFile>::iterator StorageSdcard::getModelIterator(const QString & filename)
|
||||
{
|
||||
for (QList<ModelFile>::iterator i = models.begin(); i != models.end(); ++i) {
|
||||
if (filename == i->filename) return i;
|
||||
}
|
||||
return models.end();
|
||||
}
|
||||
|
||||
QList<ModelFile>::const_iterator StorageSdcard::getModelIterator(const QString & filename) const
|
||||
{
|
||||
for (QList<ModelFile>::const_iterator i = models.begin(); i != models.end(); ++i) {
|
||||
if (filename == i->filename) return i;
|
||||
}
|
||||
return models.end();
|
||||
}
|
||||
|
||||
QList<QString> StorageSdcard::getModelsFileNames() const
|
||||
{
|
||||
QList<QString> result;
|
||||
for (QList<ModelFile>::const_iterator i = models.begin(); i != models.end(); ++i) {
|
||||
result.append(i->filename);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef storage_sdcard_h
|
||||
#define storage_sdcard_h
|
||||
|
||||
#include <QList>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
||||
/*
|
||||
This class implements a storage model used for radios that
|
||||
store all settings on the SD card (currently only Hours)
|
||||
|
||||
Disk storage format:
|
||||
* uses extension OTX
|
||||
* its a normal ZIP archive containing the same directory
|
||||
structure as the SD card in the radio. Only the relevant
|
||||
directories and files are included.
|
||||
*/
|
||||
|
||||
class StorageSdcardModelNotFound {};
|
||||
class StorageSdcardReadFileError {};
|
||||
class StorageSdcardWriteFileError {};
|
||||
|
||||
// representation of modelXX.bin file
|
||||
struct ModelFile {
|
||||
QString filename; // file name (without path)
|
||||
QByteArray data; // file contents
|
||||
};
|
||||
|
||||
|
||||
class StorageSdcard {
|
||||
public:
|
||||
/*
|
||||
Reads models and radio settings from:
|
||||
* if a file is specified in path, from that file (OTX archive format)
|
||||
* if a path is specified, from that path (where it expects to find files like on the SD card)
|
||||
*/
|
||||
int read(const QString & path);
|
||||
|
||||
/*
|
||||
|Writes models and radio settings to:
|
||||
* if a file is specified in path, to that file (OTX archive format)
|
||||
* if a path is specified, to that path (layout created is like on the SD card)
|
||||
*/
|
||||
int write(const QString & path);
|
||||
|
||||
/*
|
||||
Returns a model data for specified model
|
||||
*/
|
||||
const QByteArray & getModelData(const QString & filename) const;
|
||||
|
||||
/*
|
||||
Returns a model iterator for specified model
|
||||
*/
|
||||
QList<ModelFile>::iterator getModelIterator(const QString & filename);
|
||||
QList<ModelFile>::const_iterator getModelIterator(const QString & filename) const;
|
||||
|
||||
/*
|
||||
Returns a list of all model bin files (their filenames)
|
||||
*/
|
||||
QList<QString> getModelsFileNames() const;
|
||||
|
||||
QString lastErrorMessage;
|
||||
QByteArray radio; // radio settings (radio.bin)
|
||||
QByteArray modelList; // model names and categories (models.txt)
|
||||
QList<ModelFile> models; // collection of model data (modelXX.bin)
|
||||
|
||||
private:
|
||||
int readOtx(const QString & path);
|
||||
int readSdcard(const QString & path);
|
||||
int writeOtx(const QString & path);
|
||||
int writeSdcard(const QString & path);
|
||||
|
||||
void readFile(QByteArray & data, const QString & path);
|
||||
void writeFile(const QByteArray & data, const QString & path);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h> // TODO BSS remove
|
||||
#include "xmlinterface.h"
|
||||
#include "radio.hxx"
|
||||
|
||||
using namespace std;
|
||||
|
||||
XmlInterface::XmlInterface(QTextStream &stream):
|
||||
stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
bool XmlInterface::load(RadioData &radioData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// auto_ptr<radio> r ( radio());
|
||||
|
||||
//r->global_settings().ownerName("Bertrand");
|
||||
|
||||
/* for (hello_t::name_const_iterator i (h->name ().begin ());
|
||||
i != h->name ().end ();
|
||||
++i)
|
||||
{
|
||||
cerr << h->greeting () << ", " << *i << "!" << endl;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
catch (const xml_schema::exception& e)
|
||||
{
|
||||
cerr << e << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool XmlInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void saveGeneralSettings(GeneralSettings & settings, global_settings & gs)
|
||||
{
|
||||
Calibration rudderCalib(settings.calibMid[0], settings.calibSpanNeg[0], settings.calibSpanPos[0]);
|
||||
Calibration throttleCalib(settings.calibMid[1], settings.calibSpanNeg[1], settings.calibSpanPos[1]);
|
||||
Calibration aileronCalib(settings.calibMid[2], settings.calibSpanNeg[2], settings.calibSpanPos[2]);
|
||||
Calibration elevatorCalib(settings.calibMid[3], settings.calibSpanNeg[3], settings.calibSpanPos[3]);
|
||||
Calibration p1Calib(settings.calibMid[4], settings.calibSpanNeg[4], settings.calibSpanPos[4]);
|
||||
Calibration p2Calib(settings.calibMid[5], settings.calibSpanNeg[5], settings.calibSpanPos[5]);
|
||||
Calibration p3Calib(settings.calibMid[6], settings.calibSpanNeg[6], settings.calibSpanPos[6]);
|
||||
gs.calibration(calibration(rudderCalib, throttleCalib, aileronCalib, elevatorCalib, p1Calib, p2Calib, p3Calib));
|
||||
|
||||
// TODO BSS settings.currModel;
|
||||
gs.contrast(settings.contrast);
|
||||
gs.battery(battery(settings.txVoltageCalibration, settings.vBatWarn));
|
||||
|
||||
gs.ppm_input_calibration(ppm_input_calibration(settings.PPM_Multiplier,
|
||||
PPMCalibration(settings.trainer.calib[0]),
|
||||
PPMCalibration(settings.trainer.calib[1]),
|
||||
PPMCalibration(settings.trainer.calib[2]),
|
||||
PPMCalibration(settings.trainer.calib[3])));
|
||||
gs.view(settings.view);
|
||||
warnings warns;
|
||||
warnings::warning_sequence & ws (warns.warning());
|
||||
if (settings.disableThrottleWarning)
|
||||
ws.push_back(warning("throttle", false));
|
||||
/* TODO if (settings.disableSwitchWarning)
|
||||
ws.push_back(warning("switchs", false)); */
|
||||
if (settings.disableMemoryWarning)
|
||||
ws.push_back(warning("memory", false));
|
||||
if (settings.disableAlarmWarning)
|
||||
ws.push_back(warning("silent", false));
|
||||
if (!ws.empty())
|
||||
gs.warnings(warns);
|
||||
gs.beeper(settings.beeperMode);
|
||||
sticks stks(settings.stickMode);
|
||||
gs.sticks(stks);
|
||||
gs.inactivity_timer(settings.inactivityTimer);
|
||||
if (settings.minuteBeep || settings.preBeep || settings.flashBeep) {
|
||||
timer_beeps tb;
|
||||
if (settings.minuteBeep)
|
||||
tb.minute(true);
|
||||
if (settings.preBeep)
|
||||
tb.countdown(true);
|
||||
if (settings.flashBeep)
|
||||
tb.screen_flash(true);
|
||||
gs.timer_beeps(tb);
|
||||
}
|
||||
/* TODO if (settings.disableSplashScreen)
|
||||
gs.splash_screen(false); */
|
||||
/* TODO if (settings.backlightDelay)
|
||||
gs.light_auto_off_timer(settings.lightAutoOff); */
|
||||
gs.default_channel_order(settings.templateSetup);
|
||||
if (strlen(settings.ownerName))
|
||||
gs.owner_name(settings.ownerName);
|
||||
}
|
||||
|
||||
void saveModel(ModelData & m, model & xm)
|
||||
{
|
||||
/* TODO
|
||||
model::timer_sequence & timer_sequence (xm.timer());
|
||||
for (int i=0; i<2; i++) {
|
||||
TimerData & t = m.timers[i];
|
||||
if (t.mode) {
|
||||
timer xt(TimerSwitch::value(t.mode+TMR_NUM_OPTION), direction::value(t.dir), timer::value_type(t.val/3600, (t.val%3600)/60, t.val%60));
|
||||
timer_sequence.push_back(xt);
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (m.moduleData[0].protocol != PULSES_PPM || m.moduleData[0].channelsCount != 8 || m.moduleData[0].ppm.delay != 300 || m.moduleData[0].ppm.pulsePol != 0) {
|
||||
modulation mod;
|
||||
mod.type(modulation::type_type::value(m.moduleData[0].protocol));
|
||||
mod.channels(m.moduleData[0].channelsCount);
|
||||
mod.delay(m.moduleData[0].ppm.delay);
|
||||
mod.polarity(modulation::polarity_type::value(m.moduleData[0].ppm.pulsePol));
|
||||
xm.modulation(mod);
|
||||
}
|
||||
{
|
||||
trims xtrims;
|
||||
xtrims.extended(m.extendedTrims);
|
||||
xtrims.throttleTrim(m.thrTrim);
|
||||
xm.trims(xtrims);
|
||||
}
|
||||
if (m.beepANACenter) {
|
||||
centerBeep xcb;
|
||||
if (m.beepANACenter & (1 << 0)) xcb.rudder(true);
|
||||
if (m.beepANACenter & (1 << 1)) xcb.elevator(true);
|
||||
if (m.beepANACenter & (1 << 2)) xcb.throttle(true);
|
||||
if (m.beepANACenter & (1 << 3)) xcb.aileron(true);
|
||||
if (m.beepANACenter & (1 << 4)) xcb.p1(true);
|
||||
if (m.beepANACenter & (1 << 5)) xcb.p2(true);
|
||||
if (m.beepANACenter & (1 << 6)) xcb.p3(true);
|
||||
xm.centerBeep(xcb);
|
||||
}
|
||||
|
||||
phases xphases;
|
||||
phases::phase_sequence & phases_sequence (xphases.phase());
|
||||
for (int i=0; i<C9X_MAX_FLIGHT_MODES; i++) {
|
||||
FlightModeData & p = m.flightModeData[i];
|
||||
if (i == 0 || p.swtch.type!=SWITCH_TYPE_NONE) {
|
||||
TrimType xtrim[4];
|
||||
for (int j=0; j<4; j++) {
|
||||
if (m.flightModeData[i].trimRef[j] >= 0)
|
||||
xtrim[j].phaseRef(m.flightModeData[i].trimRef[j]);
|
||||
else
|
||||
xtrim[j].value(m.flightModeData[i].trim[j]);
|
||||
}
|
||||
trims1 xtrims(xtrim[0], xtrim[1], xtrim[2], xtrim[3]);
|
||||
phase xphase(xtrims, i);
|
||||
if (p.fadeIn) xphase.fadeIn(p.fadeIn);
|
||||
if (p.fadeOut) xphase.fadeOut(p.fadeOut);
|
||||
phases_sequence.push_back(xphase);
|
||||
}
|
||||
}
|
||||
xm.phases(xphases);
|
||||
}
|
||||
|
||||
bool XmlInterface::save(RadioData &radioData)
|
||||
{
|
||||
GeneralSettings &settings = radioData.generalSettings;
|
||||
|
||||
try
|
||||
{
|
||||
xml_schema::namespace_infomap map;
|
||||
map[""].name = "";
|
||||
map[""].schema = "radio.xsd";
|
||||
|
||||
radio r;
|
||||
|
||||
// the general settings
|
||||
global_settings gs;
|
||||
saveGeneralSettings(settings, gs);
|
||||
r.global_settings(gs);
|
||||
|
||||
// the models
|
||||
models xml_models;
|
||||
models::model_sequence & model_sequence (xml_models.model());
|
||||
for (int i=0; i<C9X_MAX_MODELS; i++) {
|
||||
ModelData & m = radioData.models[i];
|
||||
if (m.used) {
|
||||
model xm(m.name);
|
||||
saveModel(m, xm);
|
||||
model_sequence.push_back(xm);
|
||||
}
|
||||
}
|
||||
if (!model_sequence.empty())
|
||||
r.models(xml_models);
|
||||
|
||||
std::stringstream ss;
|
||||
radio_(ss, r, map);
|
||||
|
||||
stream << QString::fromStdString(ss.str());
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const xml_schema::exception& e)
|
||||
{
|
||||
cerr << e << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef xml_interface_h
|
||||
#define xml_interface_h
|
||||
|
||||
#include "eeprominterface.h"
|
||||
#include <QTextStream>
|
||||
|
||||
class XmlInterface
|
||||
{
|
||||
public:
|
||||
|
||||
XmlInterface(QTextStream & stream);
|
||||
|
||||
bool load(RadioData &);
|
||||
|
||||
virtual bool loadxml(RadioData &radioData, QDomDocument &doc);
|
||||
|
||||
bool save(RadioData &radioData);
|
||||
|
||||
protected:
|
||||
|
||||
QTextStream & stream;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user