|
@@ -0,0 +1,172 @@
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdarg.h>
|
|
|
+#include <string>
|
|
|
+#include "gfativaflash.h"
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+static std::string _formatString(const char *fmt, ...)
|
|
|
+{
|
|
|
+ int n;
|
|
|
+ std::string s;
|
|
|
+ char *p = NULL;
|
|
|
+ va_list ap;
|
|
|
+ va_start(ap, fmt);
|
|
|
+ n = ::vasprintf(&p, fmt, ap);
|
|
|
+ va_end(ap);
|
|
|
+ if(n >= 0)
|
|
|
+ {
|
|
|
+ s = p;
|
|
|
+ free(p);
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+TivaFlash::TivaFlash(QObject *pParent) : QObject(pParent), m_statNum(0), m_nodeAddr(0), m_mbSlaveId(0), m_verbosity(-1)
|
|
|
+{
|
|
|
+ setObjectName("TivaFlash");
|
|
|
+}
|
|
|
+
|
|
|
+TivaFlash::~TivaFlash(void)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::execFlashUtil(const char *pszOpt)
|
|
|
+{
|
|
|
+ FILE* pd;
|
|
|
+ char buffer[256];
|
|
|
+ std::string strCmd;
|
|
|
+
|
|
|
+ strCmd = _formatString("\"%s\" %s 2>&1", m_tivaFlashUtilPath.c_str(), pszOpt);
|
|
|
+
|
|
|
+ if(m_verbosity >= 0)
|
|
|
+ strCmd += _formatString(" -v%d", m_verbosity);
|
|
|
+
|
|
|
+ if((pd = popen(strCmd.c_str(), "r")))
|
|
|
+ {
|
|
|
+ while(fgets(buffer, sizeof buffer, pd))
|
|
|
+ {
|
|
|
+ onCmdOutput(buffer);
|
|
|
+ }
|
|
|
+
|
|
|
+ pclose(pd);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+std::string TivaFlash::statNumOrNodeAddr(void) const
|
|
|
+{
|
|
|
+ std::string ret;
|
|
|
+
|
|
|
+ if(m_nodeAddr)
|
|
|
+ ret = _formatString("--node-addr=%d", m_nodeAddr);
|
|
|
+ else if(m_statNum)
|
|
|
+ ret = _formatString("--stat-num=%d", m_statNum);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+void TivaFlash::onCmdOutput(const char *pszOut) const
|
|
|
+{
|
|
|
+ emit execOut(QString(pszOut));
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::showHelp(void)
|
|
|
+{
|
|
|
+ const char *pszOpt = "--help";
|
|
|
+ return execFlashUtil(pszOpt);
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::showMatSer(void)
|
|
|
+{
|
|
|
+ std::string strOpt;
|
|
|
+ strOpt = _formatString("--show-mat-ser --itf-name=\"%s\" %s", m_itfName.c_str(), statNumOrNodeAddr().c_str());
|
|
|
+ if(m_mbSlaveId)
|
|
|
+ strOpt += _formatString(" --mb-slave-id=%d", m_mbSlaveId);
|
|
|
+ return execFlashUtil(strOpt.c_str());
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+QString TivaFlash::tivaFlashUtilPath(void) const
|
|
|
+{
|
|
|
+ return QString::fromStdString(m_tivaFlashUtilPath);
|
|
|
+}
|
|
|
+
|
|
|
+void TivaFlash::setTivaFlashUtilPath(const QString &val)
|
|
|
+{
|
|
|
+ m_tivaFlashUtilPath = val.toStdString();
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+QString TivaFlash::itfName(void) const
|
|
|
+{
|
|
|
+ return QString::fromStdString(m_itfName);
|
|
|
+}
|
|
|
+
|
|
|
+void TivaFlash::setItfName(const QString &val)
|
|
|
+{
|
|
|
+ m_itfName = val.toStdString();
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::statNum(void) const
|
|
|
+{
|
|
|
+ return m_statNum;
|
|
|
+}
|
|
|
+
|
|
|
+void TivaFlash::setStatNum(int val)
|
|
|
+{
|
|
|
+ m_statNum = val;
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::nodeAddr(void) const
|
|
|
+{
|
|
|
+ return m_nodeAddr;
|
|
|
+}
|
|
|
+
|
|
|
+void TivaFlash::setNodeAddr(int val)
|
|
|
+{
|
|
|
+ m_nodeAddr = val;
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::mbSlaveId(void) const
|
|
|
+{
|
|
|
+ return m_mbSlaveId;
|
|
|
+}
|
|
|
+
|
|
|
+void TivaFlash::setMbSlaveId(int val)
|
|
|
+{
|
|
|
+ m_mbSlaveId = val;
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int TivaFlash::verbosity(void) const
|
|
|
+{
|
|
|
+ return m_verbosity;
|
|
|
+}
|
|
|
+
|
|
|
+void TivaFlash::setVerbosity(int val)
|
|
|
+{
|
|
|
+ m_verbosity = val;
|
|
|
+}
|