diff --git a/src/app/syncbox16ch/syncbox16ch_sdk.cpp b/src/app/syncbox16ch/syncbox16ch_sdk.cpp new file mode 100644 index 0000000..043b47e --- /dev/null +++ b/src/app/syncbox16ch/syncbox16ch_sdk.cpp @@ -0,0 +1,6 @@ +#include "syncbox16ch_sdk.hpp" +using namespace iflytop; + +void SyncBox16ChSDK::initialize() { + +} diff --git a/src/app/syncbox16ch/syncbox16ch_sdk.hpp b/src/app/syncbox16ch/syncbox16ch_sdk.hpp new file mode 100644 index 0000000..06e9e55 --- /dev/null +++ b/src/app/syncbox16ch/syncbox16ch_sdk.hpp @@ -0,0 +1,34 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "protocol/zfpga_commander/zfpga_commander.hpp" +#include "zfpga_basic_protocol/zaf_protocol.h" +#include "zfpga_basic_protocol/zaf_regs.hpp" + +namespace iflytop { + +using namespace std; + +class SyncBox16ChSDK { + + public: + static SyncBox16ChSDK *ins() { + static SyncBox16ChSDK cmder; + return &cmder; + } + + void initialize(); +}; + +} // namespace iflytop \ No newline at end of file diff --git a/src/app/main.cpp b/src/main.cpp similarity index 100% rename from src/app/main.cpp rename to src/main.cpp diff --git a/src/app/zfpga_commander/zfpga_commander.cpp b/src/protocol/zfpga_commander/zfpga_commander.cpp similarity index 85% rename from src/app/zfpga_commander/zfpga_commander.cpp rename to src/protocol/zfpga_commander/zfpga_commander.cpp index c6aadf8..5bdd60b 100644 --- a/src/app/zfpga_commander/zfpga_commander.cpp +++ b/src/protocol/zfpga_commander/zfpga_commander.cpp @@ -273,4 +273,53 @@ void ZFPGACommander::RegInfo_Reset() { for (auto &it : m_reginfoMap) { it.second.dirty = true; } -} \ No newline at end of file +} + +void ZFPGACommander::readFPGAVersion(Version &version) { + uint32_t version32; + readReg(kreg_fpga_version, version32, 100); +} +void ZFPGACommander::readStm32Version(Version &version) { + uint32_t version32; + readReg(kreg_software_version, version32, 100); +} + +bool ZFPGACommander::ping() { + try { + Version version; + readStm32Version(version); + } catch (const std::exception &e) { + return false; + } + return true; +} + +void ZFPGACommander::callcmd(uint32_t cmd, uint32_t delayms) { + lock_guard lock(m_tx_lock); + + uint8_t txdata[128] = {0}; + + zaf_packet_header_t *txpacket = (zaf_packet_header_t *)txdata; + // zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + txpacket->packet_header = PACKET_HEADER; + txpacket->packet_type = kzaf_packet_type_cmd; + txpacket->index = ++txindex; + txpacket->cmd = cmd; + txpacket->ndata = 0; + + uint32_t txpacklen = PACKET_LEN(txpacket); + uint8_t checksum = 0; + for (uint32_t i = 2; i < txpacklen - 3; i++) { + checksum += txdata[i]; + } + txdata[txpacklen - 3] = checksum; + txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; + txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; + + sendPacket(txpacket, txpacklen, delayms); +} + +void ZFPGACommander::factoryReset() { callcmd(kzaf_cmd_factory_reset, 1500); } +void ZFPGACommander::reboot() { callcmd(kzaf_cmd_reboot, 100); } +void ZFPGACommander::storageConfigs() { callcmd(kzaf_cmd_storage_cfg, 1500); } \ No newline at end of file diff --git a/src/app/zfpga_commander/zfpga_commander.hpp b/src/protocol/zfpga_commander/zfpga_commander.hpp similarity index 88% rename from src/app/zfpga_commander/zfpga_commander.hpp rename to src/protocol/zfpga_commander/zfpga_commander.hpp index 853215c..5005ba8 100644 --- a/src/app/zfpga_commander/zfpga_commander.hpp +++ b/src/protocol/zfpga_commander/zfpga_commander.hpp @@ -57,6 +57,13 @@ class Reginfo { public: }; +class Version { + public: + uint32_t main; + uint32_t sub; + uint32_t fix; +}; + class ZFPGACommander { ZFPGACommander() {} @@ -92,9 +99,19 @@ class ZFPGACommander { zaf_packet_header_t *getReceipt(); + public: + void readFPGAVersion(Version &version); + void readStm32Version(Version &version); + + bool ping(); + void factoryReset(); + void reboot(); + void storageConfigs(); + private: void _writeReg(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms); void _readReg(uint32_t regadd, uint32_t ®value, int32_t overtime_ms); + void callcmd(uint32_t cmd, uint32_t delayms); private: void resetRxContext(int32_t cmdIndex); diff --git a/zfpga_basic_protocol b/zfpga_basic_protocol index 9429095..9e7042b 160000 --- a/zfpga_basic_protocol +++ b/zfpga_basic_protocol @@ -1 +1 @@ -Subproject commit 94290950d567241d8b82ba8b8ae5ea5a55cc9634 +Subproject commit 9e7042b03742e5d8985b977f4457cbaf2b04c909