Skip to content

Add raw voltage, control state, and calibration streaming to REST API#13

Draft
Copilot wants to merge 7 commits intodst-tempfrom
copilot/add-raw-voltage-stream
Draft

Add raw voltage, control state, and calibration streaming to REST API#13
Copilot wants to merge 7 commits intodst-tempfrom
copilot/add-raw-voltage-stream

Conversation

Copy link

Copilot AI commented Jan 22, 2026

REST API Enhancements - Implementation Complete ✅

All Backend Features Implemented

This PR successfully implements all 4 backend features from the GitHub issue "REST APIまわりで実装したいこと":

  1. Raw voltage streaming - A/D and D/A voltages
  2. Control information streaming - Step, status, elapsed time
  3. Calibration data API - New endpoint for coefficients
  4. Calibration change notifications - SSE events on updates

Build Fix (Latest Commit)

  • Fixed CI build error by adding #include "Variables.hpp" to ApiServer.cpp
  • This resolves undeclared identifier errors for MAX_AI_CHANNELS, Cal_a, Cal_b, Cal_c, MAX_DA_CHANNELS, DA_Cal_a, DA_Cal_b

Summary Statistics

  • 10 files modified
  • 1,334 lines added
  • 12 lines deleted
  • 3 new endpoints/features
  • 2 comprehensive documentation files created

Key Files

Implementation

  • src/ApiServer.hpp/cpp - Core API functionality (✅ build fix applied)
  • src/DigitShowDSTDoc.h/cpp - Integration points
  • src/Calibration*.cpp/h - Notification hooks
  • src/openapi_spec.hpp - API documentation

Documentation

  • knowledge/REST_API_ENHANCEMENTS.md - User guide (Japanese)
  • TESTING_NEW_API_FEATURES.md - Test procedures (English)
  • IMPLEMENTATION_SUMMARY.md - Technical summary

API Changes

New Data in Existing Endpoints

{
  "timestamp": 1704153600000,
  "physical_input": {...},
  "physical_output": {...},
  "raw_voltages": {
    "ad_channels": [{"channel": 0, "voltage": 2.543}, ...],
    "da_channels": [{"channel": 0, "voltage": 5.012}, ...]
  },
  "control_state": {
    "current_step": 3,
    "is_running": true,
    "elapsed_ms": 15234
  }
}

New Endpoint

  • GET /api/calibration - Returns calibration coefficients

New SSE Event

  • event: calibration - Emitted on calibration changes

Testing

Environment Required: Windows + Visual Studio 2022

Test Guide: See TESTING_NEW_API_FEATURES.md for:

  • 9 detailed test cases
  • Python integration test
  • Performance validation
  • Troubleshooting guide

Key Test: Calibration change notifications (most critical new feature)

Technical Highlights

  • Thread-safe - All new data protected by mutex
  • Efficient - Only non-default calibrations included
  • Modern C++ - Follows C++17+ standards
  • Backward compatible - Old clients continue working
  • Well documented - OpenAPI spec + user guides

Benefits

For Backend:

  • Complete raw data access
  • Real-time state monitoring
  • Calibration verification

For Frontend:

  • All needed data via API
  • Real-time notifications
  • Independent UI development

For Research:

  • Export complete datasets
  • Verify calibration history
  • External data processing

Ready for Testing

All code is complete and documented. Next steps:

  1. Build on Windows with Visual Studio
  2. Run test suite from TESTING_NEW_API_FEATURES.md
  3. Verify calibration notifications work
  4. Report any issues found

Implementation Status: COMPLETE ✅
Build Status: FIXED ✅
Testing Status: PENDING (Windows required) ⏳
Documentation: COMPLETE ✅

Original prompt

This section details on the original issue you should resolve

<issue_title>REST APIまわりで実装したいこと</issue_title>
<issue_description>ほかに実装したいこと:

  • raw voltageもstreamに流す
  • control情報を流す
  • calibration dataを得るAPIを生やす
    • calibration dataを変更したらstreamにそれを流す

viewer側で実装したいこと

  • 生電圧を出す
  • motorとepのグラフを分ける
  • front/rear/averageをそれぞれ一つのグラフにまとめる
  • 縦軸を二つにして違う物理量を同じグラフで出したい
    • EPと変位計とか
  • 平滑化したい
    • 移動平均、ローパスフィルタなど</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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 5 commits January 22, 2026 14:41
Co-authored-by: takker99 <37929109+takker99@users.noreply.github.com>
Co-authored-by: takker99 <37929109+takker99@users.noreply.github.com>
Co-authored-by: takker99 <37929109+takker99@users.noreply.github.com>
Co-authored-by: takker99 <37929109+takker99@users.noreply.github.com>
Co-authored-by: takker99 <37929109+takker99@users.noreply.github.com>
Copilot AI changed the title [WIP] Add raw voltage and control information to REST API Add raw voltage, control state, and calibration streaming to REST API Jan 22, 2026
Copilot AI requested a review from takker99 January 22, 2026 14:50
@takker99
Copy link
Owner

@copilot CIがビルドエラー吐いてる。修正して。

cf. エラーの概要と修正案:
The job is failing due to the following errors in src/ApiServer.cpp:

  • error: use of undeclared identifier 'MAX_AI_CHANNELS'
  • error: use of undeclared identifier 'Cal_a'
  • error: use of undeclared identifier 'Cal_b'
  • error: use of undeclared identifier 'Cal_c'
  • error: use of undeclared identifier 'MAX_DA_CHANNELS'
  • error: use of undeclared identifier 'DA_Cal_a'
  • error: use of undeclared identifier 'DA_Cal_b'

These errors occur in the calibration_to_json() function (lines 510–533) where these identifiers are referenced with the using namespace variables; directive. This indicates that variables.hpp, which should define these constants and arrays, is either not included or not exposing the required identifiers in this translation unit.

Solution:

  1. Ensure src/ApiServer.cpp includes Variables.hpp:
    At the top of src/ApiServer.cpp, add (if missing):

    #include "Variables.hpp"
  2. Confirm Variables.hpp exports those variables:

    • MAX_AI_CHANNELS, MAX_DA_CHANNELS should be defined as constants or macros.
    • Cal_a, Cal_b, Cal_c, DA_Cal_a, DA_Cal_b should be defined as accessible arrays (likely as extern if defined elsewhere).
  3. If these symbols are declared in a namespace (variables):

    • Make sure their declarations look like:
      namespace variables {
          constexpr size_t MAX_AI_CHANNELS = ...;
          extern double Cal_a[], Cal_b[], Cal_c[];
          constexpr size_t MAX_DA_CHANNELS = ...;
          extern double DA_Cal_a[], DA_Cal_b[];
      }
    • And that src/ApiServer.cpp contains the directive:
      using namespace variables;
  4. If you still get errors, ensure that Variables.hpp and its implementation (.cpp) are actually linked in the build.

Example fix:
Add this line at the top of src/ApiServer.cpp if it’s not there yet:

#include "Variables.hpp"

And verify Variables.hpp and Variables.cpp provide the needed variables with extern linkage if appropriate.

Summary:
Import Variables.hpp and verify the needed constants and arrays are declared there. This should resolve the undeclared identifier errors on calibration variables used in your API server logic.

Co-authored-by: takker99 <37929109+takker99@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 29, 2026

@copilot CIがビルドエラー吐いてる。修正して。

cf. エラーの概要と修正案:
...

Fixed in commit 863bf0f. Added the missing #include "Variables.hpp" to src/ApiServer.cpp to resolve the undeclared identifier errors for calibration variables.

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.

REST APIまわりで実装したいこと

2 participants