Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed
Diff: file_manager.cpp
- Revision:
- 2:e699312248f3
- Parent:
- 1:58d2021e301d
--- a/file_manager.cpp Mon Dec 05 01:07:30 2016 +0000
+++ b/file_manager.cpp Mon Dec 05 22:46:14 2016 +0000
@@ -1,12 +1,16 @@
#include "file_manager.hpp"
+#define MAX_TEXT_LEN 400
+
extern Serial pc;
+char buffer[MAX_TEXT_LEN];
+
void file_manager::print_files(void)
{
- pc.printf("1. %s\n", path_sisk);
- pc.printf("2. %s\n", path_agh);
- pc.printf("3. %s\n", path_krk);
+ pc.printf("1. %s\r\n", path_sisk);
+ pc.printf("2. %s\r\n", path_agh);
+ pc.printf("3. %s\r\n", path_krk);
}
void file_manager::get_string(void)
@@ -34,13 +38,13 @@
//
// len = char_counter;
//
-// pc.printf("\r\n");
+// pc.printf("\r\r\n");
// pc.putc('Y');
}
void file_manager::get_path(void)
{
- pc.printf("Current file to write to is: %s.\n", current_path);
+ pc.printf("Current file to write to is: %s.\r\n", current_path);
}
void file_manager::set_path(void)
@@ -50,12 +54,12 @@
if (fp != NULL)
{
- pc.printf("First close the file!\n");
+ pc.printf("First close the file!\r\n");
return;
}
this->get_path();
- pc.printf("Write the number of new file to write to. \n");
+ pc.printf("Write the number of new file to write to. \r\n");
this->print_files();
do
@@ -74,27 +78,27 @@
current_path = path_krk;
break;
default:
- pc.printf("Incorrect number, try again.\n");
+ pc.printf("Incorrect number, try again.\r\n");
correct_number = false;
}
}while(!correct_number);
- pc.printf("Setting path to: %s.\n", current_path);
+ pc.printf("Setting path to: %s.\r\n", current_path);
}
bool file_manager::open_file(char option)
{
if (fp != NULL)
{
- pc.printf("File already opened!\n");
+ pc.printf("File already opened!\r\n");
return false;
}
- fp = fopen("/a.txt", "w");
+ fp = fopen(this->current_path, &option);
if (fp != NULL)
{
- pc.printf("Opened file: %s.\n", this->current_path);
+ pc.printf("Opened file: %s.\r\n", this->current_path);
}
return true;
@@ -104,7 +108,7 @@
{
if (fp == NULL)
{
- pc.printf("File already closed!\n");
+ pc.printf("File already closed!\r\n");
return false;
}
@@ -119,7 +123,7 @@
{
this->open_file('w');
-
+
this->close_file();
}
@@ -133,3 +137,30 @@
this->close_file();
}
+
+void file_manager::read_file(void)
+{
+ long lSize;
+ size_t result;
+
+ this->open_file('r');
+
+ fseek(fp , 0 , SEEK_END);
+ lSize = ftell (fp);
+ rewind(fp);
+
+ // copy the file into the buffer:
+ result = fread(buffer, 1, lSize, fp);
+ if (result != lSize)
+ {
+ pc.printf("Reading error");
+ }
+ else
+ {
+ pc.printf("File: %s.\r\r\n", this->current_path);
+ }
+
+
+ this->close_file();
+
+}
\ No newline at end of file