Skip to content

Rework config manager to use VEX API instead of std::fstream#41

Open
Copilot wants to merge 4 commits intodevfrom
copilot/fix-40
Open

Rework config manager to use VEX API instead of std::fstream#41
Copilot wants to merge 4 commits intodevfrom
copilot/fix-40

Conversation

Copy link
Copy Markdown

Copilot AI commented Jun 4, 2025

This PR completely reworks the config manager's file operations to use the VEX Brain.SDcard API instead of standard C++ file streams, as requested in the issue.

Changes Made

VEX API Integration

Replaced all std::ifstream/std::ofstream operations with VEX Brain.SDcard API calls:

  • Brain.SDcard.isInserted() - Check if SD card is available
  • Brain.SDcard.exists(filename) - Check if file exists
  • Brain.SDcard.size(filename) - Get file size
  • Brain.SDcard.loadfile(filename, buffer, len) - Read file contents
  • Brain.SDcard.savefile(filename, buffer, len) - Write file contents
  • Brain.SDcard.appendfile(filename, buffer, len) - Append to file

Files Modified

  • configManager.h - Added VEX API helper function declarations
  • configManager.cpp - Added VEX API wrapper functions (readFileToString, writeStringToFile, etc.)
  • sdcard.cpp - Converted all config file operations to use VEX API
  • logging.cpp - Updated log file writing to use Brain.SDcard.appendfile()
  • gifplayer.cpp - Updated GIF file loading to use Brain.SDcard.loadfile()

Functions Converted

  • resetOrInitializeConfig() - Config file creation
  • writeMaintenanceData() - Maintenance data persistence
  • setDriveMode() - Drive mode config updates
  • readMaintenanceData() - Maintenance data loading
  • setValuesFromConfig() - Config file parsing
  • parseConfig() - Main config initialization
  • SD_Card_Logging() - Log file operations
  • emu_open() - GIF file loading

Before/After Example

Before (using std::fstream):

std::ofstream configFile(configFileName);
if (!configFile) {
    // error handling
}
configFile << "DRIVEMODE=Tank\n";
configFile.close();

After (using VEX API):

std::string content = "DRIVEMODE=Tank\n";
if (!writeStringToFile(configFileName, content, true)) {
    // error handling  
}

Benefits

  • ✅ Consistent VEX API usage throughout codebase
  • ✅ Better integration with VEX hardware platform
  • ✅ Improved SD card error handling with VEX-specific checks
  • ✅ Removed dependency on std::fstream library
  • ✅ Maintains all existing functionality and interfaces

The changes are minimal and surgical - only the file I/O implementation was changed while preserving all existing functionality. No working code was removed or modified beyond the necessary API conversion.

Fixes #40.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits June 4, 2025 12:51
Co-authored-by: Voidless7125 <167136334+Voidless7125@users.noreply.github.com>
Co-authored-by: Voidless7125 <167136334+Voidless7125@users.noreply.github.com>
Co-authored-by: Voidless7125 <167136334+Voidless7125@users.noreply.github.com>
Copilot AI changed the title [WIP] Rework on config manager cpp Rework config manager to use VEX API instead of std::fstream Jun 4, 2025
Copilot AI requested a review from Voidless7125 June 4, 2025 12:59
@Voidless7125 Voidless7125 marked this pull request as ready for review June 17, 2025 19:25
Copilot AI review requested due to automatic review settings June 17, 2025 19:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reworks the file I/O operations in the configuration manager and related modules to use the VEX Brain.SDcard API instead of the traditional std::fstream library. Key changes include the integration of VEX API calls in logging, GIF player, and configuration functions, as well as the addition of helper functions to support file operations with the VEX hardware.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/display/logging.cpp Replaced std::ofstream with VEX API for log file appending and improved SD card error handling.
src/display/gifplayer/gifplayer.cpp Updated file reading operations to use VEX SD card API and added validations for card status and file existence.
src/config/extern/sdcard.cpp Converted config file operations to use VEX API, with modifications to file content construction.
src/config/extern/configManager.cpp Added VEX API helper functions for reading, writing, and checking file existence/size.
include/vex.h Removed unused header inclusion in favor of modern C++ headers.
include/config/extern/configManager.h Declared new helper functions for file I/O using VEX API.
Comments suppressed due to low confidence (1)

src/config/extern/sdcard.cpp:78

  • The version string concatenation is not appended to the 'configContent' variable, so the version information may be missing from the final configuration file. Consider appending it using 'configContent += "VERSION=)" + Version + "\n";' to ensure it is included.
    VERSION=)" + Version + "\n";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework on config manager cpp

3 participants