Zugriff auf die SD-Karte über ECMD: Unterschied zwischen den Versionen
K |
|||
| Zeile 1: | Zeile 1: | ||
== Übersicht == | == Übersicht == | ||
| − | * | + | * vfs create [Dateiname] Erstellt die angegebene Datei. |
| − | * | + | * vfs write [Dateiname] [Text] Schreibt den Text in die angegebene Datei.(Datei MUSS existieren) |
| − | * | + | * vfs read [Dateiname] Ließt eine Datei ein und gibt der Text über die serielle Schnittstelle aus. (WICHTIG: Die Variable buffer[] muss auf die benötigte Größe angepasst werden!) |
| − | * | + | * vfs remove [Dateiname] Setzt die Größe der Datei auf 0 |
| + | * vfs exists [dateiname] Prüft, ob die Datei existiert. (OK=Existiert, parse error=existiert nicht) | ||
== Aktivieren der Funktionen == | == Aktivieren der Funktionen == | ||
Die Funktionen sind momentan noch nicht in der Standard-Version vorhanden. Sie müssen somit manuell nachgerüstet werden. | Die Funktionen sind momentan noch nicht in der Standard-Version vorhanden. Sie müssen somit manuell nachgerüstet werden. | ||
| − | Dazu muss man als erstes die Datei "hardware/storage/sd_reader/ | + | Dazu muss man als erstes die Datei "core/vfs/vfs_ecmd.c" erstellen und folgenden Code einfügen: |
| − | + | #include <avr/pgmspace.h> | |
| − | + | #include "config.h" | |
| + | #include "hardware/storage/sd_reader/sd_raw.h" | ||
| + | #include "hardware/storage/sd_reader/fat.h" | ||
| + | #include "core/vfs/vfs.h" | ||
| + | #include "hardware/storage/sd_reader/vfs_sd.h" | ||
| + | #include "core/debug.h" | ||
| + | #include "protocols/ecmd/ecmd-base.h" | ||
int16_t | int16_t | ||
| − | + | parse_cmd_vfs_create (char *cmd, char *output, uint16_t len) | |
{ | { | ||
| − | |||
while (*cmd == ' ') cmd ++; | while (*cmd == ' ') cmd ++; | ||
/* Do this to protect the server from crashing when the filename contains a space */ | /* Do this to protect the server from crashing when the filename contains a space */ | ||
| Zeile 22: | Zeile 28: | ||
} | } | ||
cmd[x] = 0; | cmd[x] = 0; | ||
| − | + | struct vfs_file_handle_t *handle=vfs_create(cmd); | |
| − | + | if (handle == 0) return ECMD_ERR_PARSE_ERROR; | |
| + | vfs_close(handle); | ||
return ECMD_FINAL_OK; | return ECMD_FINAL_OK; | ||
} | } | ||
| − | |||
int16_t | int16_t | ||
| − | + | parse_cmd_vfs_write (char *cmd, char *output, uint16_t len) | |
{ | { | ||
| − | |||
while (*cmd == ' ') cmd ++; | while (*cmd == ' ') cmd ++; | ||
int x=0; | int x=0; | ||
| Zeile 37: | Zeile 42: | ||
} | } | ||
cmd[x] = 0; | cmd[x] = 0; | ||
| − | + | struct vfs_file_handle_t *handle=vfs_open(cmd); | |
| + | if (handle == 0) return ECMD_ERR_PARSE_ERROR; | ||
cmd[x] = ' '; | cmd[x] = ' '; | ||
while (*cmd != ' ') cmd ++; | while (*cmd != ' ') cmd ++; | ||
| − | + | vfs_truncate (handle, strlen(cmd)); | |
| − | + | vfs_write (handle, cmd, | |
| − | + | strlen(cmd)); | |
| − | + | vfs_close(handle); | |
return ECMD_FINAL_OK; | return ECMD_FINAL_OK; | ||
} | } | ||
| − | |||
int16_t | int16_t | ||
| − | + | parse_cmd_vfs_read (char *cmd, char *output, uint16_t len) | |
{ | { | ||
| − | |||
while (*cmd == ' ') cmd ++; | while (*cmd == ' ') cmd ++; | ||
/* Do this to protect the server from crashing when the filename contains a space */ | /* Do this to protect the server from crashing when the filename contains a space */ | ||
| Zeile 58: | Zeile 62: | ||
} | } | ||
cmd[x] = 0; | cmd[x] = 0; | ||
| − | + | struct vfs_file_handle_t *handle=vfs_open(cmd); | |
| − | char buffer[ | + | if (handle == 0) return ECMD_ERR_PARSE_ERROR; |
| − | int size = | + | char buffer[1024]=""; |
| − | + | int size = vfs_size (handle); | |
| − | + | vfs_read (handle, buffer, | |
| + | size); | ||
printf(buffer); //DEBUG (How can I return a whole string???) | printf(buffer); //DEBUG (How can I return a whole string???) | ||
| − | + | vfs_close(handle); | |
| − | return | + | return ECMD_FINAL_OK; |
| + | } | ||
| + | int16_t | ||
| + | parse_cmd_vfs_remove (char *cmd, char *output, uint16_t len) //DUMMY | ||
| + | { | ||
| + | while (*cmd == ' ') cmd ++; | ||
| + | /* Do this to protect the server from crashing when the filename contains a space */ | ||
| + | int x=0; | ||
| + | while (cmd[x] != ' ') { | ||
| + | x++; | ||
| + | } | ||
| + | cmd[x] = 0; | ||
| + | struct vfs_file_handle_t *handle=vfs_open(cmd); | ||
| + | if (handle == 0) return ECMD_ERR_PARSE_ERROR; | ||
| + | vfs_truncate (handle, 0); | ||
| + | vfs_close(handle); | ||
| + | return ECMD_FINAL_OK; | ||
} | } | ||
| − | |||
int16_t | int16_t | ||
| − | + | parse_cmd_vfs_exists (char *cmd, char *output, uint16_t len) | |
{ | { | ||
| − | |||
while (*cmd == ' ') cmd ++; | while (*cmd == ' ') cmd ++; | ||
/* Do this to protect the server from crashing when the filename contains a space */ | /* Do this to protect the server from crashing when the filename contains a space */ | ||
| Zeile 79: | Zeile 98: | ||
} | } | ||
cmd[x] = 0; | cmd[x] = 0; | ||
| − | + | struct vfs_file_handle_t *handle=vfs_open(cmd); | |
| − | + | if (handle == 0) return ECMD_ERR_PARSE_ERROR; | |
| − | + | vfs_close(handle); | |
return ECMD_FINAL_OK; | return ECMD_FINAL_OK; | ||
} | } | ||
| + | /* | ||
| + | -- Ethersex META -- | ||
| + | block([[VFS-ECMD]]) | ||
| + | ecmd_feature(vfs_read, "vfs read",PATH, Returns the content of the given file.) | ||
| + | ecmd_feature(vfs_exists, "vfs exists",PATH, Check whether the given file exists ) | ||
| + | ecmd_feature(vfs_write, "vfs write",PATH_TEXT, Write the given data to the specified file.) | ||
| + | ecmd_feature(vfs_create, "vfs create",PATH, Create a new file.) | ||
| + | ecmd_feature(vfs_remove, "vfs remove",PATH, Remove a file.) | ||
| + | */ | ||
| + | |||
| + | Nun muss noch die Datei zum Makefile hinzugefügt werden. Dazu einfach noch oben folgende Zeile einfügen: | ||
| + | $(VFS_SUPPORT)_SRC += core/vfs/vfs_ecmd.c | ||
| − | + | Als letztes "make menuconfig" ausführen. Man muss nichts ändern aber einfach neu speichern. | |
| − | |||
| − | |||
| − | |||
| − | |||
== Verwenden der Befehle == | == Verwenden der Befehle == | ||
Die Befehle können über alle ecmd-fähigen Module aufgerufen werden. (Seriell, HTTPD, ...) | Die Befehle können über alle ecmd-fähigen Module aufgerufen werden. (Seriell, HTTPD, ...) | ||
| − | Nur der Read-Befehl gibt immer über seriell aus. | + | Nur der Read-Befehl gibt immer über seriell aus. (Sollte vermieden werden( |
== TODO == | == TODO == | ||
| − | |||
* Ordentlichen Remove-Befehl | * Ordentlichen Remove-Befehl | ||
| + | * Bei write können nur sehr wenige Zeichen geschrieben werden. | ||
[[Category:Ethersex]] | [[Category:Ethersex]] | ||
[[Category:Hardware]] | [[Category:Hardware]] | ||
[[Category:SD-Karte]] | [[Category:SD-Karte]] | ||
Aktuelle Version vom 28. Dezember 2010, 17:04 Uhr
Inhaltsverzeichnis
Übersicht
- vfs create [Dateiname] Erstellt die angegebene Datei.
- vfs write [Dateiname] [Text] Schreibt den Text in die angegebene Datei.(Datei MUSS existieren)
- vfs read [Dateiname] Ließt eine Datei ein und gibt der Text über die serielle Schnittstelle aus. (WICHTIG: Die Variable buffer[] muss auf die benötigte Größe angepasst werden!)
- vfs remove [Dateiname] Setzt die Größe der Datei auf 0
- vfs exists [dateiname] Prüft, ob die Datei existiert. (OK=Existiert, parse error=existiert nicht)
Aktivieren der Funktionen
Die Funktionen sind momentan noch nicht in der Standard-Version vorhanden. Sie müssen somit manuell nachgerüstet werden.
Dazu muss man als erstes die Datei "core/vfs/vfs_ecmd.c" erstellen und folgenden Code einfügen:
#include <avr/pgmspace.h>
#include "config.h"
#include "hardware/storage/sd_reader/sd_raw.h"
#include "hardware/storage/sd_reader/fat.h"
#include "core/vfs/vfs.h"
#include "hardware/storage/sd_reader/vfs_sd.h"
#include "core/debug.h"
#include "protocols/ecmd/ecmd-base.h"
int16_t
parse_cmd_vfs_create (char *cmd, char *output, uint16_t len)
{
while (*cmd == ' ') cmd ++;
/* Do this to protect the server from crashing when the filename contains a space */
int x=0;
while (cmd[x] != ' ') {
x++;
}
cmd[x] = 0;
struct vfs_file_handle_t *handle=vfs_create(cmd);
if (handle == 0) return ECMD_ERR_PARSE_ERROR;
vfs_close(handle);
return ECMD_FINAL_OK;
}
int16_t
parse_cmd_vfs_write (char *cmd, char *output, uint16_t len)
{
while (*cmd == ' ') cmd ++;
int x=0;
while (cmd[x] != ' ') {
x++;
}
cmd[x] = 0;
struct vfs_file_handle_t *handle=vfs_open(cmd);
if (handle == 0) return ECMD_ERR_PARSE_ERROR;
cmd[x] = ' ';
while (*cmd != ' ') cmd ++;
vfs_truncate (handle, strlen(cmd));
vfs_write (handle, cmd,
strlen(cmd));
vfs_close(handle);
return ECMD_FINAL_OK;
}
int16_t
parse_cmd_vfs_read (char *cmd, char *output, uint16_t len)
{
while (*cmd == ' ') cmd ++;
/* Do this to protect the server from crashing when the filename contains a space */
int x=0;
while (cmd[x] != ' ') {
x++;
}
cmd[x] = 0;
struct vfs_file_handle_t *handle=vfs_open(cmd);
if (handle == 0) return ECMD_ERR_PARSE_ERROR;
char buffer[1024]="";
int size = vfs_size (handle);
vfs_read (handle, buffer,
size);
printf(buffer); //DEBUG (How can I return a whole string???)
vfs_close(handle);
return ECMD_FINAL_OK;
}
int16_t
parse_cmd_vfs_remove (char *cmd, char *output, uint16_t len) //DUMMY
{
while (*cmd == ' ') cmd ++;
/* Do this to protect the server from crashing when the filename contains a space */
int x=0;
while (cmd[x] != ' ') {
x++;
}
cmd[x] = 0;
struct vfs_file_handle_t *handle=vfs_open(cmd);
if (handle == 0) return ECMD_ERR_PARSE_ERROR;
vfs_truncate (handle, 0);
vfs_close(handle);
return ECMD_FINAL_OK;
}
int16_t
parse_cmd_vfs_exists (char *cmd, char *output, uint16_t len)
{
while (*cmd == ' ') cmd ++;
/* Do this to protect the server from crashing when the filename contains a space */
int x=0;
while (cmd[x] != ' ') {
x++;
}
cmd[x] = 0;
struct vfs_file_handle_t *handle=vfs_open(cmd);
if (handle == 0) return ECMD_ERR_PARSE_ERROR;
vfs_close(handle);
return ECMD_FINAL_OK;
}
/*
-- Ethersex META --
block(VFS-ECMD)
ecmd_feature(vfs_read, "vfs read",PATH, Returns the content of the given file.)
ecmd_feature(vfs_exists, "vfs exists",PATH, Check whether the given file exists )
ecmd_feature(vfs_write, "vfs write",PATH_TEXT, Write the given data to the specified file.)
ecmd_feature(vfs_create, "vfs create",PATH, Create a new file.)
ecmd_feature(vfs_remove, "vfs remove",PATH, Remove a file.)
*/
Nun muss noch die Datei zum Makefile hinzugefügt werden. Dazu einfach noch oben folgende Zeile einfügen:
$(VFS_SUPPORT)_SRC += core/vfs/vfs_ecmd.c
Als letztes "make menuconfig" ausführen. Man muss nichts ändern aber einfach neu speichern.
Verwenden der Befehle
Die Befehle können über alle ecmd-fähigen Module aufgerufen werden. (Seriell, HTTPD, ...) Nur der Read-Befehl gibt immer über seriell aus. (Sollte vermieden werden(
TODO
- Ordentlichen Remove-Befehl
- Bei write können nur sehr wenige Zeichen geschrieben werden.