InfiniTimeOrg / InfiniTimeOrg/InfiniTime

FS doesnt seem to work from BLE service - FileOpen, DirOpen etc

Open
#2,262 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
3.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Im trying to implement a data file in my BLE service loaded by NimbleController, using FS, but have encountered a brick wall.

When using "F:/events.dat", I am constantly getting errors back - either -2 (no entry), or -84 (corrupt).
When using "/events.dat", the device just crashes.

The same things are happening for DirOpen, using "F:/" and "/" paths respectively.

Im trying to follow whats being done in built in services and controllers, like Settings, which seem to work without issue. Also, my code works fine on Infinisim.

This issue does not occur if I transplant my code into an app like a watch face.

Am I doing something wrong here?

debug_log is a function ive defined for logging to the screen, defined much like printf.

void TestService::SaveEventsLog() {
  debug_log("app", "SaveEventsLog");

  lfs_file_t saveFile;

  int file_operation_result = fs.FileOpen(&saveFile, "F:/events.dat", LFS_O_WRONLY | LFS_O_CREAT);
  if (file_operation_result < LFS_ERR_OK) {
    debug_log("app", "saveFile open failed: %d", file_operation_result);

    if (file_operation_result == LFS_ERR_CORRUPT) {
      fs.FileDelete("F:/events.dat");
      debug_log("app", "saveFile corrupt - deleting");
    }
    return;
  }

  debug_log("app", "saveFile opened");

  struct SaveData {
    uint8_t version = 1;
    std::vector<EventLogEntry> data;
  } saveData;

  saveData.data = eventLog;

  file_operation_result = fs.FileWrite(&saveFile, reinterpret_cast<uint8_t*>(&saveData), sizeof(saveData));
  if (file_operation_result < LFS_ERR_OK) {
    debug_log("app", "saveFile write failed: %d", file_operation_result);
  } else {
    debug_log("app", "saveFile saved");
  }

  file_operation_result = fs.FileClose(&saveFile);
  if (file_operation_result < LFS_ERR_OK) {
    debug_log("app", "saveFile close failed: %d", file_operation_result);
  } else {
    debug_log("app", "saveFile closed");
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the TestService code with the built-in Settings service and controllers, then inspect FS.FileOpen, FS.DirOpen, and NimbleController behavior in a BLE service. Reproduce the F:/ and / path cases and compare them with Infinisim and watch-face behavior; done means identifying why the service receives these errors or crashes and documenting the working access pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.