diff options
Diffstat (limited to 'CommandTerminal')
-rw-r--r-- | CommandTerminal/CmdGetSurveyDataFile.cpp | 38 |
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; - } |