-
Notifications
You must be signed in to change notification settings - Fork 0
runcam 6 Interface and registry #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,308 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <iostream> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <vector> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <queue> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <windows.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <thread> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <chrono> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <functional> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <conio.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "New_RunCam_registry.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // --- CRC8 DVB-S2 Calculator --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t crc8_dvb_s2(const uint8_t* data, size_t len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t crc = 0x00; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (size_t i = 0; i < len; ++i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| crc ^= data[i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (int j = 0; j < 8; ++j) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (crc & 0x80) crc = (crc << 1) ^ 0xD5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else crc <<= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return crc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // --- FSM States --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum class RunCamState { Idle, WaitingResponse, Success, Error, Timeout, Disconnected }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum class RxState { WaitHeader, Buffering }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // --- Request Context --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct RunCamRequest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<uint8_t> packet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| int retries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| DWORD sendTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool awaitingResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::function<void(const std::vector<uint8_t>&, bool)> callback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // --- RunCam Serial Class --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| class RunCamSerialFSM { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool blindMode = true; // DEFAULT ON - Send commands without waiting for response, assume success. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| HANDLE hSerial = INVALID_HANDLE_VALUE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RunCamState state = RunCamState::Idle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::queue<RunCamRequest> requestQueue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RunCamRequest currentRequest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| int maxRetries = 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| int timeoutMs = 500; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RxState rxState = RxState::WaitHeader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<uint8_t> rxBuffer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_t currentExpectedLen = 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_t currentExpectedLen = 5; | |
| size_t currentExpectedLen = 0; |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header byte is hard-coded as 0xCC here even though RC_HEADER is defined in the registry. Using the shared constant avoids divergence if the header ever changes and keeps the parser consistent with the sender.
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prompt accepts an arbitrary string, but the connection path is built as \\.\\COM + input. If the user types COM3 (common expectation from the prompt), it will try \\.\\COMCOM3 and fail. Either clarify the prompt to request only the port number (e.g., "3 for COM3") or normalize inputs that already include COM/\\.\\COM.
| std::cout << "Enter COM Port: "; | |
| std::string comPort; | |
| std::cin >> comPort; | |
| std::cin.ignore(1000, '\n'); // Clear buffer | |
| if (!cam.connect("\\\\.\\COM" + comPort)) { | |
| std::cout << "Enter COM Port (e.g., 3 or COM3): "; | |
| std::string comPort; | |
| std::cin >> comPort; | |
| std::cin.ignore(1000, '\n'); // Clear buffer | |
| // Normalize COM port input so that users can enter "3", "COM3", or a full path like "\\\\.\\COM3". | |
| std::string devicePath; | |
| if (comPort.rfind("\\\\.\\", 0) == 0) { | |
| // User entered a full device path such as "\\\\.\\COM3" | |
| devicePath = comPort; | |
| } else if (comPort.rfind("COM", 0) == 0 || comPort.rfind("com", 0) == 0) { | |
| // User entered "COM3" (case-insensitive); prepend the "\\\\.\\" prefix | |
| devicePath = "\\\\.\\" + comPort; | |
| } else { | |
| // Assume user entered only the numeric part, e.g., "3" | |
| devicePath = "\\\\.\\COM" + comPort; | |
| } | |
| if (!cam.connect(devicePath)) { |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The menu label shows Change Mode as (0x05), but the action constant used by RunCamHex::CHANGE_MODE is ACT_CHANGE_MODE = 0x02. This mismatch will confuse users when correlating menu text to actual packets; update the displayed value (or print both command and action bytes).
| std::cout << " [5] Change Mode (0x05)" << std::endl; | |
| std::cout << " [5] Change Mode (cmd 0x05, act 0x02)" << std::endl; |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::hex is set on this stream and never restored. Stream formatting flags persist, which can lead to later integer output unexpectedly being printed in hex; consider restoring std::dec after printing the command id (or use a local std::ostringstream).
| std::cout << "\n--- WRITE TEXT (" << std::hex << (int)textCmdID << ") ---" << std::endl; | |
| std::cout << "\n--- WRITE TEXT (" << std::hex << (int)textCmdID << std::dec << ") ---" << std::endl; |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input validation is missing for text write parameters: text.length() is truncated to uint8_t, and negative/out-of-range x/y values will wrap when cast to uint8_t. Please clamp/validate x and y against the documented ranges and reject/limit text lengths beyond what the protocol supports before building the packet.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #ifndef NEW_TEST_RUNCAM_REGISTRY_H | ||
| #define NEW_TEST_RUNCAM_REGISTRY_H | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| // --- PROTOCOL CONSTANTS --- | ||
| const uint8_t RC_HEADER = 0xCC; | ||
|
|
||
| // --- 1. COMMAND IDs --- | ||
| enum CommandID : uint8_t { | ||
| CMD_GET_INFO = 0x00, | ||
| CMD_CAM_CONTROL = 0x01, | ||
| CMD_5KEY_PRESS = 0x02, | ||
| CMD_5KEY_RELEASE = 0x03, | ||
| CMD_OSD_HANDSHAKE = 0x04, | ||
| CMD_GET_SETTINGS = 0x10, | ||
| CMD_READ_DETAIL = 0x11, | ||
| CMD_WRITE_SETTING = 0x13, | ||
| CMD_WRITE_STRING = 0x22 | ||
| }; | ||
|
|
||
| // --- 2. CAMERA CONTROL ACTIONS (Payloads for CMD 0x01) --- | ||
| enum ControlAction : uint8_t { | ||
| ACT_WIFI_BTN = 0x00, | ||
| ACT_POWER_BTN = 0x01, | ||
| ACT_CHANGE_MODE = 0x02, | ||
| ACT_START_REC = 0x03, | ||
| ACT_STOP_REC = 0x04 | ||
| }; | ||
|
|
||
| // --- 3. 5-KEY OSD ACTIONS (Payloads for CMD 0x02) --- | ||
| enum OSDAction : uint8_t { | ||
| OSD_ENTER = 0x01, | ||
| OSD_LEFT = 0x02, | ||
| OSD_RIGHT = 0x03, | ||
| OSD_UP = 0x04, | ||
| OSD_DOWN = 0x05 | ||
| }; | ||
|
|
||
| // --- 4. PRE-CALCULATED PACKETS --- | ||
| namespace RunCamHex { | ||
| const std::vector<uint8_t> GET_INFO = {0xCC, 0x00, 0x00}; | ||
| const std::vector<uint8_t> START_REC = {0xCC, 0x01, 0x03}; | ||
| const std::vector<uint8_t> STOP_REC = {0xCC, 0x01, 0x04}; | ||
| const std::vector<uint8_t> OSD_OPEN = {0xCC, 0x04, 0x01}; | ||
| const std::vector<uint8_t> OSD_CLOSE = {0xCC, 0x04, 0x02}; | ||
| const std::vector<uint8_t> CHANGE_MODE = {RC_HEADER, CMD_CAM_CONTROL, ACT_CHANGE_MODE}; | ||
| const std::vector<uint8_t> WIFI_BTN = {RC_HEADER, CMD_CAM_CONTROL, ACT_WIFI_BTN}; | ||
| const std::vector<uint8_t> OSD_ENTER_PRESS = {RC_HEADER, CMD_5KEY_PRESS, OSD_ENTER}; | ||
| const std::vector<uint8_t> OSD_ENTER_RELEASE = {RC_HEADER, CMD_5KEY_RELEASE, OSD_ENTER}; | ||
| const std::vector<uint8_t> GET_SETTINGS = {RC_HEADER, CMD_GET_SETTINGS, 0x00}; | ||
| const std::vector<uint8_t> READ_DETAIL = {RC_HEADER, CMD_READ_DETAIL, 0x00}; | ||
| const std::vector<uint8_t> WRITE_SETTING = {RC_HEADER, CMD_WRITE_SETTING, 0x00}; | ||
|
Comment on lines
+41
to
+54
|
||
| } | ||
|
|
||
| #endif // NEW_TEST_RUNCAM_REGISTRY_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These includes appear unused in this file (
<thread>,<chrono>,<conio.h>). Removing unused headers speeds up builds and reduces the chance of platform/define collisions.