Added move function

This commit is contained in:
Tim Keller 2021-11-16 04:32:53 +00:00
parent 8f46908d38
commit 362a5ef113
4 changed files with 33 additions and 4 deletions

View file

@ -270,6 +270,21 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
break; break;
} }
case commands::MOVE: {
NRF_LOG_INFO("[FS_S] -> Move");
MoveHeader* header = (MoveHeader*) om->om_data;
uint16_t plen = header->OldPathLength;
// Null Terminate string
header->pathstr[plen] = 0;
char path[header->NewPathLength + 1] {0};
memcpy(path, &header->pathstr[plen + 1], header->NewPathLength);
MoveResponse resp {};
resp.command = commands::MOVE_STATUS;
int res = fs.Rename(header->pathstr, path);
resp.status = (res == 0) ? 1 : 2;
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(MoveResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
}
default: default:
break; break;
} }

View file

@ -15,8 +15,7 @@ namespace Pinetime {
class Ble; class Ble;
class FSService { class FSService {
public: public:
FSService(Pinetime::System::SystemTask& systemTask, FSService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::FS& fs);
Pinetime::Controllers::FS& fs);
void Init(); void Init();
int OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); int OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
@ -172,6 +171,18 @@ namespace Pinetime {
commands command; commands command;
uint8_t status; uint8_t status;
}; };
using MoveHeader = struct __attribute__((packed)) {
commands command;
uint8_t padding;
uint16_t OldPathLength;
uint16_t NewPathLength;
char pathstr[];
};
using MoveResponse = struct __attribute__((packed)) {
commands command;
uint8_t status;
};
int FSCommandHandler(uint16_t connectionHandle, os_mbuf* om); int FSCommandHandler(uint16_t connectionHandle, os_mbuf* om);
void prepareReadDataResp(ReadHeader* header, ReadResponse* resp); void prepareReadDataResp(ReadHeader* header, ReadResponse* resp);

View file

@ -95,7 +95,9 @@ int FS::DirRewind(lfs_dir_t* dir) {
int FS::DirCreate(const char* path) { int FS::DirCreate(const char* path) {
return lfs_mkdir(&lfs, path); return lfs_mkdir(&lfs, path);
} }
int FS::Rename(const char* oldPath, const char* newPath){
return lfs_rename(&lfs,oldPath,newPath);
}
int FS::Stat(const char* path, lfs_info* info) { int FS::Stat(const char* path, lfs_info* info) {
return lfs_stat(&lfs, path, info); return lfs_stat(&lfs, path, info);
} }

View file

@ -28,6 +28,7 @@ namespace Pinetime {
int DirCreate(const char* path); int DirCreate(const char* path);
lfs_ssize_t GetFSSize(); lfs_ssize_t GetFSSize();
int Rename(const char* oldPath, const char* newPath);
int Stat(const char* path, lfs_info* info); int Stat(const char* path, lfs_info* info);
void VerifyResource(); void VerifyResource();