List Dir works?
This commit is contained in:
parent
f841b8c984
commit
6393a17d74
|
@ -1,6 +1,7 @@
|
||||||
#include <nrf_log.h>
|
#include <nrf_log.h>
|
||||||
#include "FSService.h"
|
#include "FSService.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
|
#include "systemtask/SystemTask.h"
|
||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
|
@ -13,8 +14,9 @@ int FSServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gat
|
||||||
return fsService->OnFSServiceRequested(conn_handle, attr_handle, ctxt);
|
return fsService->OnFSServiceRequested(conn_handle, attr_handle, ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
FSService::FSService(Pinetime::Controllers::FS& fs)
|
FSService::FSService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::FS& fs)
|
||||||
: fs {fs},
|
: systemTask {systemTask},
|
||||||
|
fs {fs},
|
||||||
characteristicDefinition {{.uuid = &fsVersionUuid.u,
|
characteristicDefinition {{.uuid = &fsVersionUuid.u,
|
||||||
.access_cb = FSServiceCallback,
|
.access_cb = FSServiceCallback,
|
||||||
.arg = this,
|
.arg = this,
|
||||||
|
@ -60,8 +62,13 @@ int FSService::OnFSServiceRequested(uint16_t connectionHandle, uint16_t attribut
|
||||||
|
|
||||||
int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
|
int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
|
||||||
auto command = static_cast<commands>(om->om_data[0]);
|
auto command = static_cast<commands>(om->om_data[0]);
|
||||||
NRF_LOG_INFO("[FS_S] -> FSCommandHandler %d",command);
|
NRF_LOG_INFO("[FS_S] -> FSCommandHandler Command %d", command);
|
||||||
fs.Mount();
|
// Just always make sure we are awake...
|
||||||
|
systemTask.PushMessage(Pinetime::System::Messages::StartFileTransfer);
|
||||||
|
vTaskDelay(10);
|
||||||
|
while (systemTask.IsSleeping()) {
|
||||||
|
vTaskDelay(100); // 50ms
|
||||||
|
}
|
||||||
switch (command) {
|
switch (command) {
|
||||||
/*
|
/*
|
||||||
case commands::READ: {
|
case commands::READ: {
|
||||||
|
@ -203,6 +210,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
|
||||||
char path[plen + 1] = {0};
|
char path[plen + 1] = {0};
|
||||||
memcpy(path, header->pathstr, plen);
|
memcpy(path, header->pathstr, plen);
|
||||||
NRF_LOG_INFO("[FS_S] -> DIR %.10s", path);
|
NRF_LOG_INFO("[FS_S] -> DIR %.10s", path);
|
||||||
|
|
||||||
lfs_dir_t dir = {};
|
lfs_dir_t dir = {};
|
||||||
struct lfs_info info = {};
|
struct lfs_info info = {};
|
||||||
|
|
||||||
|
@ -212,9 +220,11 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
|
||||||
resp.totalentries = 0;
|
resp.totalentries = 0;
|
||||||
resp.entry = 0;
|
resp.entry = 0;
|
||||||
|
|
||||||
int res = fs.DirOpen(path, &dir);
|
if (fs.DirOpen(path, &dir)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
NRF_LOG_INFO("[FS_S] ->diropen %d ", res);
|
// NRF_LOG_INFO("[FS_S] ->diropen %d ", res);
|
||||||
while (fs.DirRead(&dir, &info)) {
|
while (fs.DirRead(&dir, &info)) {
|
||||||
resp.totalentries++;
|
resp.totalentries++;
|
||||||
}
|
}
|
||||||
|
@ -222,9 +232,11 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
|
||||||
|
|
||||||
fs.DirRewind(&dir);
|
fs.DirRewind(&dir);
|
||||||
|
|
||||||
while (true) {
|
// NRF_LOG_INFO("[FS_S] ->diropen %d ", res);
|
||||||
|
|
||||||
|
while (resp.entry < resp.totalentries) {
|
||||||
int res = fs.DirRead(&dir, &info);
|
int res = fs.DirRead(&dir, &info);
|
||||||
if(res <= 0){
|
if (res <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
|
@ -243,23 +255,26 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
|
||||||
strcpy(resp.path, info.name);
|
strcpy(resp.path, info.name);
|
||||||
resp.path_length = strlen(info.name);
|
resp.path_length = strlen(info.name);
|
||||||
NRF_LOG_INFO("[FS_S] ->Path %s ,", info.name);
|
NRF_LOG_INFO("[FS_S] ->Path %s ,", info.name);
|
||||||
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse)+resp.path_length);
|
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse) + resp.path_length);
|
||||||
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
|
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
|
||||||
vTaskDelay(10); // Allow stuff to actually go out over the BLE conn
|
vTaskDelay(100); // Allow stuff to actually go out over the BLE conn
|
||||||
resp.entry++;
|
resp.entry++;
|
||||||
}
|
}
|
||||||
fs.DirClose(&dir);
|
|
||||||
|
if (fs.DirClose(&dir)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
resp.file_size = 0;
|
resp.file_size = 0;
|
||||||
resp.path_length = 0;
|
resp.path_length = 0;
|
||||||
resp.flags = 0;
|
resp.flags = 0;
|
||||||
// TODO Handle Size of response better.
|
// TODO Handle Size of response better.
|
||||||
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse)+resp.path_length);
|
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse) + resp.path_length);
|
||||||
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
|
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
|
||||||
NRF_LOG_INFO("[FS_S] -> done ");
|
NRF_LOG_INFO("[FS_S] -> done ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs.UnMount();
|
systemTask.PushMessage(Pinetime::System::Messages::StopFileTransfer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Loads resp with file data given a valid filepath header and resp
|
// Loads resp with file data given a valid filepath header and resp
|
||||||
|
|
|
@ -15,13 +15,15 @@ namespace Pinetime {
|
||||||
class Ble;
|
class Ble;
|
||||||
class FSService {
|
class FSService {
|
||||||
public:
|
public:
|
||||||
FSService(Pinetime::Controllers::FS& fs);
|
FSService(Pinetime::System::SystemTask& systemTask,
|
||||||
|
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);
|
||||||
void NotifyFSRaw(uint16_t connectionHandle);
|
void NotifyFSRaw(uint16_t connectionHandle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Pinetime::System::SystemTask& systemTask;
|
||||||
Pinetime::Controllers::FS& fs;
|
Pinetime::Controllers::FS& fs;
|
||||||
static constexpr uint16_t FSServiceId {0xFEBB};
|
static constexpr uint16_t FSServiceId {0xFEBB};
|
||||||
static constexpr uint16_t fsVersionId {0x0100};
|
static constexpr uint16_t fsVersionId {0x0100};
|
||||||
|
@ -30,7 +32,7 @@ namespace Pinetime {
|
||||||
static constexpr uint8_t maxpathlen = 100;
|
static constexpr uint8_t maxpathlen = 100;
|
||||||
static constexpr ble_uuid16_t fsServiceUuid {
|
static constexpr ble_uuid16_t fsServiceUuid {
|
||||||
.u {.type = BLE_UUID_TYPE_16},
|
.u {.type = BLE_UUID_TYPE_16},
|
||||||
.value = {0xFEBB}};// {0x72, 0x65, 0x66, 0x73, 0x6e, 0x61, 0x72, 0x54, 0x65, 0x6c, 0x69, 0x46, 0xBB, 0xFE, 0xAF, 0xAD}};
|
.value = {0xFEBB}}; // {0x72, 0x65, 0x66, 0x73, 0x6e, 0x61, 0x72, 0x54, 0x65, 0x6c, 0x69, 0x46, 0xBB, 0xFE, 0xAF, 0xAD}};
|
||||||
|
|
||||||
static constexpr ble_uuid128_t fsVersionUuid {
|
static constexpr ble_uuid128_t fsVersionUuid {
|
||||||
.u {.type = BLE_UUID_TYPE_128},
|
.u {.type = BLE_UUID_TYPE_128},
|
||||||
|
@ -144,7 +146,7 @@ namespace Pinetime {
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
|
||||||
heartRateService {systemTask, heartRateController},
|
heartRateService {systemTask, heartRateController},
|
||||||
motionService{systemTask, motionController},
|
motionService{systemTask, motionController},
|
||||||
fs {fs},
|
fs {fs},
|
||||||
fsService {fs},
|
fsService {systemTask,fs},
|
||||||
serviceDiscovery({¤tTimeClient, &alertNotificationClient}) {
|
serviceDiscovery({¤tTimeClient, &alertNotificationClient}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace Pinetime {
|
||||||
StopRinging,
|
StopRinging,
|
||||||
MeasureBatteryTimerExpired,
|
MeasureBatteryTimerExpired,
|
||||||
BatteryPercentageUpdated,
|
BatteryPercentageUpdated,
|
||||||
|
StartFileTransfer,
|
||||||
|
StopFileTransfer,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,6 +342,19 @@ void SystemTask::Work() {
|
||||||
doNotGoToSleep = false;
|
doNotGoToSleep = false;
|
||||||
xTimerStart(dimTimer, 0);
|
xTimerStart(dimTimer, 0);
|
||||||
break;
|
break;
|
||||||
|
case Messages::StartFileTransfer:
|
||||||
|
NRF_LOG_INFO("[systemtask] FS Started");
|
||||||
|
doNotGoToSleep = true;
|
||||||
|
if (isSleeping && !isWakingUp)
|
||||||
|
GoToRunning();
|
||||||
|
//TODO add intent of fs access icon or something
|
||||||
|
break;
|
||||||
|
case Messages::StopFileTransfer:
|
||||||
|
NRF_LOG_INFO("[systemtask] FS Stopped");
|
||||||
|
doNotGoToSleep = false;
|
||||||
|
xTimerStart(dimTimer, 0);
|
||||||
|
//TODO add intent of fs access icon or something
|
||||||
|
break;
|
||||||
case Messages::OnTouchEvent:
|
case Messages::OnTouchEvent:
|
||||||
if (touchHandler.GetNewTouchInfo()) {
|
if (touchHandler.GetNewTouchInfo()) {
|
||||||
touchHandler.UpdateLvglTouchPoint();
|
touchHandler.UpdateLvglTouchPoint();
|
||||||
|
|
Loading…
Reference in a new issue