summaryrefslogtreecommitdiff
path: root/CommandTerminal
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2015-12-03 10:52:20 -0600
committerMike Fiore <mfiore@multitech.com>2015-12-03 10:52:20 -0600
commitd5853121cf1d74f65a98a27080506455c9abedab (patch)
tree8c6e8a6dc5641f942327cd75f0ac856df82905e3 /CommandTerminal
parent29960cf233c3ccf8c938764052feddfdac113d1d (diff)
downloadmtdot-box-evb-factory-firmware-d5853121cf1d74f65a98a27080506455c9abedab.tar.gz
mtdot-box-evb-factory-firmware-d5853121cf1d74f65a98a27080506455c9abedab.tar.bz2
mtdot-box-evb-factory-firmware-d5853121cf1d74f65a98a27080506455c9abedab.zip
implement AT command to display survey data file contents
Diffstat (limited to 'CommandTerminal')
-rw-r--r--CommandTerminal/CmdGetSurveyDataFile.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/CommandTerminal/CmdGetSurveyDataFile.cpp b/CommandTerminal/CmdGetSurveyDataFile.cpp
index 11d9ae3..3fa4e46 100644
--- a/CommandTerminal/CmdGetSurveyDataFile.cpp
+++ b/CommandTerminal/CmdGetSurveyDataFile.cpp
@@ -1,4 +1,6 @@
#include "CmdGetSurveyDataFile.h"
+#include "FileName.h"
+#include "MTSLog.h"
CmdGetSurveyDataFile::CmdGetSurveyDataFile(mDot* dot, mts::MTSSerial& serial) :
Command(dot, "Get Survey Data File", "AT+GSDF", "Outputs the survey data file to the command port"), _serial(serial)
@@ -8,12 +10,38 @@ CmdGetSurveyDataFile::CmdGetSurveyDataFile(mDot* dot, mts::MTSSerial& serial) :
uint32_t CmdGetSurveyDataFile::action(std::vector<std::string> args)
{
-//ToDo: Output the file contents line by line.
- if (!_dot->saveConfig()) {
- setErrorMessage("Failed to save to flash");
- return 1;
+ mDot::mdot_file file;
+ int buf_size = 512;
+ char buf[buf_size];
+ int read;
+ int read_size;
+
+ file = _dot->openUserFile(file_name, mDot::FM_RDONLY);
+ if (file.fd < 0) {
+ setErrorMessage("Failed to open file");
+ return 1;
}
+
+ while (read < file.size) {
+ read_size = (file.size - read) > buf_size ? buf_size : file.size - read;
+ int size = _dot->readUserFile(file, (void*)buf, read_size);
+ if (size < 0) {
+ setErrorMessage("Failed to read file");
+ _dot->closeUserFile(file);
+ return 1;
+ }
+
+ for (int i = 0; i < size; i++) {
+ if (buf[i] == '\n')
+ _serial.writef("\r\n");
+ else
+ _serial.writef("%c", buf[i]);
+ }
+
+ read += size;
+ }
+
+ _dot->closeUserFile(file);
return 0;
-
}