Skip to content

Commit 8c6e6c6

Browse files
committed
Added move function
1 parent 342ac19 commit 8c6e6c6

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/components/ble/FSService.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
270270
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
271271
break;
272272
}
273+
case commands::MOVE: {
274+
NRF_LOG_INFO("[FS_S] -> Move");
275+
MoveHeader* header = (MoveHeader*) om->om_data;
276+
uint16_t plen = header->OldPathLength;
277+
// Null Terminate string
278+
header->pathstr[plen] = 0;
279+
char path[header->NewPathLength + 1] {0};
280+
memcpy(path, &header->pathstr[plen + 1], header->NewPathLength);
281+
MoveResponse resp {};
282+
resp.command = commands::MOVE_STATUS;
283+
int res = fs.Rename(header->pathstr, path);
284+
resp.status = (res == 0) ? 1 : 2;
285+
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(MoveResponse));
286+
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
287+
}
273288
default:
274289
break;
275290
}

src/components/ble/FSService.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ namespace Pinetime {
1515
class Ble;
1616
class FSService {
1717
public:
18-
FSService(Pinetime::System::SystemTask& systemTask,
19-
Pinetime::Controllers::FS& fs);
18+
FSService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::FS& fs);
2019
void Init();
2120

2221
int OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
@@ -116,7 +115,7 @@ namespace Pinetime {
116115
uint64_t modTime;
117116
uint32_t freespace;
118117
};
119-
118+
120119
using WritePacing = struct __attribute__((packed)) {
121120
commands command;
122121
uint8_t status;
@@ -172,6 +171,18 @@ namespace Pinetime {
172171
commands command;
173172
uint8_t status;
174173
};
174+
using MoveHeader = struct __attribute__((packed)) {
175+
commands command;
176+
uint8_t padding;
177+
uint16_t OldPathLength;
178+
uint16_t NewPathLength;
179+
char pathstr[];
180+
};
181+
182+
using MoveResponse = struct __attribute__((packed)) {
183+
commands command;
184+
uint8_t status;
185+
};
175186

176187
int FSCommandHandler(uint16_t connectionHandle, os_mbuf* om);
177188
void prepareReadDataResp(ReadHeader* header, ReadResponse* resp);

src/components/fs/FS.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ int FS::DirRewind(lfs_dir_t* dir) {
9595
int FS::DirCreate(const char* path) {
9696
return lfs_mkdir(&lfs, path);
9797
}
98-
98+
int FS::Rename(const char* oldPath, const char* newPath){
99+
return lfs_rename(&lfs,oldPath,newPath);
100+
}
99101
int FS::Stat(const char* path, lfs_info* info) {
100102
return lfs_stat(&lfs, path, info);
101103
}

src/components/fs/FS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Pinetime {
2828
int DirCreate(const char* path);
2929

3030
lfs_ssize_t GetFSSize();
31+
int Rename(const char* oldPath, const char* newPath);
3132
int Stat(const char* path, lfs_info* info);
3233
void VerifyResource();
3334

0 commit comments

Comments
 (0)