Browse Source

update

master
zhaohe 1 year ago
parent
commit
eb97dc9cd2
  1. 3
      .vscode/settings.json
  2. 2
      CMakeLists.txt
  3. 22
      README.md
  4. 73
      mainwindow.cpp
  5. 2
      mainwindow.h
  6. 200
      mainwindow.ui
  7. 314
      src/camera_light_src_timing_controller/clst_controler.cpp
  8. 86
      src/camera_light_src_timing_controller/clst_controler.hpp
  9. 57
      src/camera_light_src_timing_controller/clst_controler_sig_type.cpp
  10. 169
      src/camera_light_src_timing_controller/clst_controler_sig_type.hpp
  11. 2
      zaf_protocol

3
.vscode/settings.json

@ -87,6 +87,5 @@
"qserialportinfo": "cpp",
"qmessagebox": "cpp"
},
"files.autoGuessEncoding": true,
"files.encoding": "gbk",
"files.autoGuessEncoding": false,
}

2
CMakeLists.txt

@ -32,6 +32,8 @@ set(PROJECT_SOURCES
src/camera_light_src_timing_controller/clst_controler.cpp
src/camera_light_src_timing_controller/qt_serial_datachannel.cpp
src/camera_light_src_timing_controller/clst_controler_sig_type.cpp
zaf_protocol/zaf_ecode.c
zaf_protocol/zaf_protocol.c
# libxsync/src/xsync_v2.cpp

22
README.md

@ -1,17 +1,7 @@
```
Timecode测试
端口:19903
协议:UDP
消息 :01 00 00 00 05 02 08 00
解析结果:08:25:00:01
xync测试
端口:13014
协议:UDP
消息 :
F0 00 20 00 00 00 00 FF 00 00 F0 42 17 00 00 00 E1 FF FF FF 01 00 00 00 78 00 00 00 00 00 00 00 E6 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00
```
TODO:
1. 显示FPGA版本号
2. 显示STM32版本号
3. 显示PC软件版本号
4. 修改窗口名称
```

73
mainwindow.cpp

@ -9,7 +9,6 @@
#include "./ui_mainwindow.h"
#include "camera_light_src_timing_controller/qt_serial_datachannel.hpp"
#include "logger.hpp"
#include "xsync_regs.hpp"
using namespace iflytop;
using namespace clst;
@ -29,9 +28,9 @@ static const char *fmt(const char *fmt, ...) {
}
static const uint32_t str2int(QString str) {
// 如果0x开头,16进制转换
// 如果0b开头,2进制转换
// 否则10进制转换
// 如果0x开头,??16进制转换
// 如果0b开头,??2进制转换
// 否则??10进制转换
// 去除掉str中_
str.remove("_");
@ -77,6 +76,41 @@ void MainWindow::doinui_slot(QFunction func) {
if (func.get()) func.get()();
}
void MainWindow::updatePage() {
{
float Freq;
uint32_t PluseCnt;
uint32_t SeqCtrlPluseCntMax;
Freq = ui->InterClk_Freq_Text->text().toFloat();
PluseCnt = ui->InterClk_PluseCnt_Text->text().toUInt();
SeqCtrlPluseCntMax = ui->InterClk_SeqCtrlPluseCntMax_Text->text().toUInt();
DO(m_clstc->InterClk_setFreq(Freq));
DO(m_clstc->InterClk_setPluseCnt(PluseCnt));
DO(m_clstc->InterClk_setSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
}
}
void MainWindow::refreshPage() {
{
float Freq;
uint32_t PluseCnt;
uint32_t SeqCtrlPluseCntMax;
float TriOutSignalFreq;
DO(m_clstc->InterClk_getFreq(Freq));
DO(m_clstc->InterClk_getPluseCnt(PluseCnt));
DO(m_clstc->InterClk_getSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
ui->InterClk_Freq_Text->setText(QString::number(Freq, 'f', 2));
ui->InterClk_PluseCnt_Text->setText(QString::number(PluseCnt));
ui->InterClk_SeqCtrlPluseCntMax_Text->setText(QString::number(SeqCtrlPluseCntMax));
ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
}
}
void MainWindow::constructUI() {
/*******************************************************************************
* serialPortCB *
@ -87,7 +121,7 @@ void MainWindow::constructUI() {
}
/*******************************************************************************
* *
* ?? *
*******************************************************************************/
ui->serialBaudrateCB->addItem("9600");
ui->serialBaudrateCB->addItem("14400");
@ -122,7 +156,7 @@ void MainWindow::constructUI() {
G_QTDataChannel.setStopBits(QSerialPort::OneStop);
if (!G_QTDataChannel.open()) {
QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占");
QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??");
return;
}
ui->serialOpenKey->setText("关闭");
@ -143,7 +177,12 @@ void MainWindow::constructUI() {
* *
*******************************************************************************/
connect(ui->refreshPageKey, &QPushButton::clicked, this, [=](bool check) { //
refreshPage();
});
connect(ui->UpdateCfg_Key, &QPushButton::clicked, this, [=](bool check) { //
updatePage();
refreshPage();
});
/*******************************************************************************
@ -151,7 +190,7 @@ void MainWindow::constructUI() {
*******************************************************************************/
connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->storageConfigs());
ui->informationBrowser->setText("保存配置");
ui->informationBrowser->setText("保存配置成功");
});
/*******************************************************************************
@ -159,7 +198,7 @@ void MainWindow::constructUI() {
*******************************************************************************/
connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->reboot());
ui->informationBrowser->setText("重启设备");
ui->informationBrowser->setText("重启设备成功");
});
/*******************************************************************************
@ -167,11 +206,11 @@ void MainWindow::constructUI() {
*******************************************************************************/
connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->factoryReset());
ui->informationBrowser->setText("恢复出厂设置");
ui->informationBrowser->setText("恢复出厂设置成功");
});
/*******************************************************************************
* *
* ?? *
*******************************************************************************/
ui->RegAdd->setText("0x00000000");
@ -180,7 +219,7 @@ void MainWindow::constructUI() {
uint32_t value = 0;
DO(m_clstc->reg_read(addr, value, 100));
ui->regReadbakVal->setText(fmt("0x%08X", value));
ui->informationBrowser->setText(fmt("读0x%04x成功", addr));
ui->informationBrowser->setText(fmt("0x%04x成功", addr));
});
connect(ui->regWriteKey, &QPushButton::clicked, this, [=](bool check) { //
@ -189,7 +228,17 @@ void MainWindow::constructUI() {
uint32_t readkbak = 0;
DO(m_clstc->reg_write(addr, value, readkbak, 100));
ui->regReadbakVal->setText(fmt("0x%04x", readkbak));
ui->informationBrowser->setText(fmt("写0x%04x成功", addr));
ui->informationBrowser->setText(fmt("写入0x%08x成功", addr));
});
connect(ui->InterClk_trigger_Key, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->InterClk_trigger());
ui->informationBrowser->setText(fmt("触发成功"));
refreshPage();
});
connect(ui->InterClk_stop_Key, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->InterClk_stop());
ui->informationBrowser->setText(fmt("停止触发成功"));
});
}

2
mainwindow.h

@ -73,6 +73,8 @@ class MainWindow : public QMainWindow {
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void refreshPage();
void updatePage();
private slots:
/**

200
mainwindow.ui

@ -17,7 +17,7 @@
</sizepolicy>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>相机光源和时序控制器</string>
</property>
<widget class="QWidget" name="top">
<layout class="QVBoxLayout" name="verticalLayout">
@ -228,6 +228,13 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="UpdateCfg_Key">
<property name="text">
<string>提交配置</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="storageConfigKey">
<property name="text">
<string>保存配置</string>
@ -428,21 +435,204 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="tabBarAutoHide">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab0">
<attribute name="title">
<string>触发源配置</string>
<string>外部触发源配置</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>内部触发源配置</string>
</attribute>
<widget class="QGroupBox" name="InternalTriggerGB">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>300</width>
<height>191</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>200</height>
</size>
</property>
<property name="title">
<string>内部触发源配置</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="2" column="0">
<widget class="QLabel" name="InterClk_Freq_Lable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>触发时钟(HZ)</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="InterClk_PluseCnt_Lable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>触发脉冲数量(0等于无限)</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="InterClk_PluseCnt_Text">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="InterClk_SeqCtrlPluseCntMax_Text">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="InterClk_trigger_Key">
<property name="text">
<string>触发</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="InterClk_SeqCtrlPluseCntMax_Lable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>顺序触发模式最大计数</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="InterClk_Freq_Text">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="InterClk_TriOutSignalFreq_Lable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>输出频率探测(HZ)</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="InterClk_TriOutSignalFreq_Text">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="InterClk_stop_Key">
<property name="text">
<string>停止</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab1">
<attribute name="title">
<string>光源配置</string>
<string>光源时序配置</string>
</attribute>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>相机驱动配置</string>
<string>快门时序配置</string>
</attribute>
</widget>
</widget>

314
src/camera_light_src_timing_controller/clst_controler.cpp

@ -9,8 +9,12 @@ using namespace clst;
#define TAG "CLSTControler"
#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + __packet->ndata * 4 + 3)
#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + (__packet->ndata) * sizeof(uint32_t) + 1 /*checksum*/ + 2 /*tail*/)
#define DO_CMD(exptr) \
{ \
zaf_error_code_t ecode = exptr; \
if (ecode != kaf_ec_success) return ecode; \
}
CLSTControler *CLSTControler::ins() {
static CLSTControler *ins = nullptr;
if (ins == nullptr) {
@ -70,7 +74,7 @@ void CLSTControler::processRxData(uint8_t *rx, uint32_t rxlen) {
* 1. findHeader
* 2. processRx
*
* ²âÊÔÖ¸Áî:
* æµè¯æŒä»¤:
* 5A 5A 02 00 01 00 01 00 01 00 01 00 00 00 06 A5 A5
*
*/
@ -177,8 +181,6 @@ zaf_error_code_t CLSTControler::sendPacket(zaf_packet_header_t *packet, uint32_t
return kaf_ec_overtime;
}
#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + (__packet->ndata) * sizeof(uint32_t) + 1 /*checksum*/ + 2 /*tail*/)
zaf_error_code_t CLSTControler::reg_write(uint32_t regadd, uint32_t regvalue, uint32_t &regbackvalue, int32_t overtime_ms) { //
lock_guard<mutex> lock(m_tx_lock);
@ -212,6 +214,12 @@ zaf_error_code_t CLSTControler::reg_write(uint32_t regadd, uint32_t regvalue, ui
regbackvalue = rxpacket->data[1];
return kaf_ec_success;
}
uint32_t CLSTControler::reg_read_v2(uint32_t regadd) {
uint32_t regvalue = 0;
reg_read(regadd, regvalue, 30);
return regvalue;
}
zaf_error_code_t CLSTControler::reg_read(uint32_t regadd, uint32_t &regvalue, int32_t overtime_ms) {
lock_guard<mutex> lock(m_tx_lock);
@ -279,7 +287,7 @@ zaf_error_code_t CLSTControler::factoryReset() {
txdata[txpacklen - 2] = PACKET_TAIL & 0xFF;
txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF;
zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100);
zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 1500);
if (ecode != kaf_ec_success) return ecode;
return kaf_ec_success;
@ -335,8 +343,300 @@ zaf_error_code_t CLSTControler::storageConfigs() {
txdata[txpacklen - 2] = PACKET_TAIL & 0xFF;
txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF;
zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100);
zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 1500);
if (ecode != kaf_ec_success) return ecode;
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::readFreq(uint32_t reg, float &freqfloat) {
uint32_t freq_cnt = 0;
DO_CMD(reg_read(reg, freq_cnt, 30));
if (freq_cnt == 0) {
freqfloat = 0;
}
if (freq_cnt != 0) {
uint32_t freq_1000x = ((1.0 / (freq_cnt * 1.0 / (100 * 1000 * 1000))) * 1000 + 0.5); //+0.5???c++ ??????????????????
// ZLOGI(TAG, "freq_10x %f", freq_10x);
freqfloat = freq_1000x / 1000.0;
} else {
freqfloat = 0;
}
if (freqfloat < 0.05) {
freqfloat = 0;
}
return kaf_ec_success;
}
/*******************************************************************************
* ???? *
*******************************************************************************/
zaf_error_code_t CLSTControler::InterClk_setFreq(float freq) { //
DO_CMD(InterClk_stop());
ZLOGI(TAG, "InterClk_setFreq %f", freq);
double T = 1.0 / freq;
double T_ns = T * 1000 * 1000 * 1000;
double cnt = T_ns / 10 + 0.5; // 100MHZ <=> 10ns
uint32_t cnt_u32 = uint32_t(cnt);
ZLOGI(TAG, "InterClk_setFreq %f %d", freq, cnt_u32);
return reg_write(kreg_internal_clk_freq_cnt, cnt_u32);
}
zaf_error_code_t CLSTControler::InterClk_setPluseCnt(uint32_t cnt) { //
return reg_write(kreg_internal_clk_pluse_cnt, cnt);
}
zaf_error_code_t CLSTControler::InterClk_setSeqCtrlPluseCntMax(uint32_t cnt) { //
if (cnt == 0) return kaf_ec_param_error;
return reg_write(kreg_internal_clk_tri_sequential_control_pluse_cnt_max, cnt - 1);
}
zaf_error_code_t CLSTControler::InterClk_getFreq(float &freq) { //
return readFreq(kreg_internal_clk_freq_cnt, freq);
}
zaf_error_code_t CLSTControler::InterClk_getPluseCnt(uint32_t &cnt) { //
return reg_read(kreg_internal_clk_pluse_cnt, cnt);
}
zaf_error_code_t CLSTControler::InterClk_getSeqCtrlPluseCntMax(uint32_t &cnt) { //
DO_CMD(reg_read(kreg_internal_clk_tri_sequential_control_pluse_cnt_max, cnt));
cnt++;
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::InterClk_readTriOutSignalFreq(float &freq) { //
return readFreq(kreg_internal_clk_tri_out_signal_freq, freq);
}
zaf_error_code_t CLSTControler::InterClk_trigger() { //
return reg_write(kreg_internal_clk_ctrl, 1);
}
zaf_error_code_t CLSTControler::InterClk_stop() { //
return reg_write(kreg_internal_clk_ctrl, 0);
}
/*******************************************************************************
* TTL????? *
*******************************************************************************/
// kreg_trigger_in1_module
// kreg_trigger_in1_src_slect
// kreg_trigger_in1_fileter_coefficient
// kreg_trigger_in1_freq_detect_bias
// kreg_trigger_in1_mode
// kreg_trigger_in1_trigger_mode_trigger_edge
// kreg_trigger_in1_trigger_mode_freq_division
// kreg_trigger_in1_trigger_mode_freq_multiplication
// kreg_trigger_in1_sequential_control_pluse_cnt_max
// kreg_trigger_in1_in_signal_freq
// kreg_trigger_in1_out_signal_freq
zaf_error_code_t CLSTControler::TriInX_setSrcSelect(int32_t index, ExtTriggerSrcType src) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_src_slect + (index - 1) * 32, src.getVal());
}
zaf_error_code_t CLSTControler::TriInX_setFileterCoefficient(int32_t index, uint32_t coefficient) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_fileter_coefficient + (index - 1) * 32, coefficient);
}
zaf_error_code_t CLSTControler::TriInX_setFreqDetectBias(int32_t index, uint32_t bias) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_freq_detect_bias + (index - 1) * 32, bias);
}
zaf_error_code_t CLSTControler::TriInX_setMode(int32_t index, SigProcessMode mode) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_mode + (index - 1) * 32, mode.getVal());
}
zaf_error_code_t CLSTControler::TriInX_setTriggerModeTriggerEdge(int32_t index, TriggerEdge edge) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_trigger_mode_trigger_edge + (index - 1) * 32, edge);
}
zaf_error_code_t CLSTControler::TriInX_setTriggerModeFreqDivision(int32_t index, uint32_t division) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_trigger_mode_freq_division + (index - 1) * 32, division);
}
zaf_error_code_t CLSTControler::TriInX_setTriggerModeFreqMultiplication(int32_t index, uint32_t multiplication) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_trigger_mode_freq_multiplication + (index - 1) * 32, multiplication);
}
zaf_error_code_t CLSTControler::TriInX_setSequentialControlPluseCntMax(int32_t index, uint32_t cnt) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_trigger_in1_sequential_control_pluse_cnt_max + (index - 1) * 32, cnt);
}
zaf_error_code_t CLSTControler::TriInX_getSrcSelect(int32_t index, ExtTriggerSrcType &src) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t val;
DO_CMD(reg_read(kreg_trigger_in1_src_slect + (index - 1) * 32, val));
src = ExtTriggerSrcType(val);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::TriInX_getFileterCoefficient(int32_t index, uint32_t &coefficient) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_read(kreg_trigger_in1_fileter_coefficient + (index - 1) * 32, coefficient);
}
zaf_error_code_t CLSTControler::TriInX_getFreqDetectBias(int32_t index, uint32_t &bias) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_read(kreg_trigger_in1_freq_detect_bias + (index - 1) * 32, bias);
}
zaf_error_code_t CLSTControler::TriInX_getMode(int32_t index, SigProcessMode &mode) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t reakbak = 0;
DO_CMD(reg_read(kreg_trigger_in1_mode + (index - 1) * 32, reakbak));
mode = SigProcessMode(reakbak);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::TriInX_getTriggerModeTriggerEdge(int32_t index, TriggerEdge &edge) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t val;
DO_CMD(reg_read(kreg_trigger_in1_trigger_mode_trigger_edge + (index - 1) * 32, val));
edge = TriggerEdge(val);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::TriInX_getTriggerModeFreqDivision(int32_t index, uint32_t &division) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_read(kreg_trigger_in1_trigger_mode_freq_division + (index - 1) * 32, division);
}
zaf_error_code_t CLSTControler::TriInX_getTriggerModeFreqMultiplication(int32_t index, uint32_t &multiplication) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_read(kreg_trigger_in1_trigger_mode_freq_multiplication + (index - 1) * 32, multiplication);
}
zaf_error_code_t CLSTControler::TriInX_readInSignalFreq(int32_t index, float &freq) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return readFreq(kreg_trigger_in1_in_signal_freq + (index - 1) * 32, freq);
}
zaf_error_code_t CLSTControler::TriInX_readOutSignalFreq(int32_t index, float &freq) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return readFreq(kreg_trigger_in1_out_signal_freq + (index - 1) * 32, freq);
return kaf_ec_success;
}
/*******************************************************************************
* ???? *
*******************************************************************************/
zaf_error_code_t CLSTControler::LightSrcX_setTriSrc(int32_t index, InternalSig src) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_light_ctrol_module1_source_select + (index - 1) * 32, src);
}
zaf_error_code_t CLSTControler::LightSrcX_setTriggerModePluseWidth(int32_t index, uint32_t width) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_light_ctrol_module1_trigger_mode_pluse_width + (index - 1) * 32, width * 10); // 0.1us
}
zaf_error_code_t CLSTControler::LightSrcX_setTriggerModeFirstPluseOffset(int32_t index, uint32_t offset) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_write(kreg_light_ctrol_module1_trigger_mode_first_pluse_offset + (index - 1) * 32, offset * 10); // 0.1us
}
zaf_error_code_t CLSTControler::LightSrcX_setLightIntensityDuty(int32_t index, float duty) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t freqcnt = 0;
DO_CMD(reg_read(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, freqcnt));
uint32_t cnt = freqcnt * (duty / 100.0);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::LightSrcX_setLightDriverFreq(int32_t index, float freq) { //
double T = 1.0 / freq;
double T_ns = T * 1000 * 1000 * 1000;
double cnt = T_ns / 10 + 0.5; // 100MHZ <=> 10ns
uint32_t cnt_u32 = uint32_t(cnt);
return reg_write(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, cnt_u32);
}
zaf_error_code_t CLSTControler::LightSrcX_getTriSrc(int32_t index, InternalSig &src) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t val;
DO_CMD(reg_read(kreg_light_ctrol_module1_source_select + (index - 1) * 32, val));
src = InternalSig(val);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::LightSrcX_getTriggerModePluseWidth(int32_t index, uint32_t &width) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t val;
DO_CMD(reg_read(kreg_light_ctrol_module1_trigger_mode_pluse_width + (index - 1) * 32, val));
width = val / 10;
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::LightSrcX_getTriggerModeFirstPluseOffset(int32_t index, uint32_t &offset) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t val;
DO_CMD(reg_read(kreg_light_ctrol_module1_trigger_mode_first_pluse_offset + (index - 1) * 32, val));
offset = val / 10;
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::LightSrcX_getLightIntensityDuty(int32_t index, float &duty) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
uint32_t freqcnt = 0;
DO_CMD(reg_read(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, freqcnt));
uint32_t cnt = 0;
DO_CMD(reg_read(kreg_light_ctrol_module1_light_intensity_cnt + (index - 1) * 32, cnt));
duty = (cnt * 100.0 / freqcnt);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::LightSrcX_getLightDriverFreq(int32_t index, float &freq) { //
return readFreq(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, freq);
}
zaf_error_code_t CLSTControler::LightSrcX_readLightSrcErrorState(int32_t index, uint32_t &state) { //
if (index < 1 || index > 4) return kaf_ec_param_error;
return reg_read(kreg_light_ctrol_module1_light_src_error_state + (index - 1) * 32, state);
}
zaf_error_code_t CLSTControler::LightSrcX_readInSigFreqDetect(int32_t index, float &freq) { //
return readFreq(kreg_light_ctrol_module1_in_sig_freq_detect + (index - 1) * 32, freq);
}
zaf_error_code_t CLSTControler::LightSrcX_readOutSigFreqDetect(int32_t index, float &freq) { //
return readFreq(kreg_light_ctrol_module1_out_sig_freq_detect + (index - 1) * 32, freq);
}
/*******************************************************************************
* *
*******************************************************************************/
zaf_error_code_t CLSTControler::ShutterX_setOutputCtrlMode(int32_t index, SigProcessMode mode) { //
return reg_write(kreg_ttl_output_module1_output_ctrl_mode + (index - 1) * 32, mode);
}
zaf_error_code_t CLSTControler::ShutterX_setLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t state) { //
uint32_t readbak_state = 0;
DO_CMD(reg_read(kreg_ttl_output_module1_lt_en_bind + (index - 1) * 32, readbak_state));
if (state == 1) {
readbak_state |= (1 << lt_en_sig_index);
} else {
readbak_state &= ~(1 << lt_en_sig_index);
}
DO_CMD(reg_write(kreg_ttl_output_module1_lt_en_bind + (index - 1) * 32, readbak_state));
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::ShutterX_setLtEnOffset(int32_t index, uint32_t offset) { //
return reg_write(kreg_ttl_output_module1_lt_en_offset + (index - 1) * 32, offset * 10); // 0.1us
}
zaf_error_code_t CLSTControler::ShutterX_setInSigSelect(int32_t index, InternalSig sig) { //
return reg_write(kreg_ttl_output_module1_in_sig_select + (index - 1) * 32, sig);
}
zaf_error_code_t CLSTControler::ShutterX_getOutputCtrlMode(int32_t index, SigProcessMode &mode) { //
uint32_t val;
DO_CMD(reg_read(kreg_ttl_output_module1_output_ctrl_mode + (index - 1) * 32, val));
mode = SigProcessMode(val);
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::ShutterX_getLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t &state) { //
uint32_t readbak_state = 0;
DO_CMD(reg_read(kreg_ttl_output_module1_lt_en_bind + (index - 1) * 32, readbak_state));
state = (readbak_state >> lt_en_sig_index) & 0x01;
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::ShutterX_getLtEnOffset(int32_t index, uint32_t &offset) { //
uint32_t val;
DO_CMD(reg_read(kreg_ttl_output_module1_lt_en_offset + (index - 1) * 32, val));
offset = val / 10;
return kaf_ec_success;
}
zaf_error_code_t CLSTControler::ShutterX_getInSigSelect(int32_t index, InternalSig &sig) { //
uint32_t val;
DO_CMD(reg_read(kreg_ttl_output_module1_in_sig_select + (index - 1) * 32, val));
sig = InternalSig(val);
return kaf_ec_success;
}

86
src/camera_light_src_timing_controller/clst_controler.hpp

@ -12,6 +12,7 @@
#include <thread>
#include <vector>
#include "clst_controler_sig_type.hpp"
#include "zaf_protocol/zaf_protocol.h"
#define SDK_VERSION 1
@ -76,15 +77,96 @@ class CLSTControler {
zaf_error_code_t reboot();
zaf_error_code_t storageConfigs();
void initDevice();
public:
zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t &regbackvalue, int32_t overtime_ms);
zaf_error_code_t reg_read(uint32_t regadd, uint32_t &regvalue, int32_t overtime_ms);
zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t &regbackvalue, int32_t overtime_ms = 30);
zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue) {
uint32_t regbackvalue;
return reg_write(regadd, regvalue, regbackvalue, 30);
}
zaf_error_code_t reg_read(uint32_t regadd, uint32_t &regvalue, int32_t overtime_ms = 30);
uint32_t reg_read_v2(uint32_t regadd);
public:
/*******************************************************************************
* *
*******************************************************************************/
zaf_error_code_t InterClk_setFreq(float freq);
zaf_error_code_t InterClk_setPluseCnt(uint32_t cnt);
zaf_error_code_t InterClk_setSeqCtrlPluseCntMax(uint32_t cnt);
zaf_error_code_t InterClk_getFreq(float &freq);
zaf_error_code_t InterClk_getPluseCnt(uint32_t &cnt);
zaf_error_code_t InterClk_getSeqCtrlPluseCntMax(uint32_t &cnt);
zaf_error_code_t InterClk_readTriOutSignalFreq(float &freq);
zaf_error_code_t InterClk_trigger();
zaf_error_code_t InterClk_stop();
/*******************************************************************************
* TTL外部触发源 *
*******************************************************************************/
zaf_error_code_t TriInX_setSrcSelect(int32_t index, ExtTriggerSrcType src); // 0
zaf_error_code_t TriInX_setFileterCoefficient(int32_t index, uint32_t coefficient);
zaf_error_code_t TriInX_setFreqDetectBias(int32_t index, uint32_t bias);
zaf_error_code_t TriInX_setMode(int32_t index, SigProcessMode mode);
zaf_error_code_t TriInX_setTriggerModeTriggerEdge(int32_t index, TriggerEdge edge);
zaf_error_code_t TriInX_setTriggerModeFreqDivision(int32_t index, uint32_t division);
zaf_error_code_t TriInX_setTriggerModeFreqMultiplication(int32_t index, uint32_t multiplication);
zaf_error_code_t TriInX_setSequentialControlPluseCntMax(int32_t index, uint32_t cnt);
zaf_error_code_t TriInX_getSrcSelect(int32_t index, ExtTriggerSrcType &src);
zaf_error_code_t TriInX_getFileterCoefficient(int32_t index, uint32_t &coefficient);
zaf_error_code_t TriInX_getFreqDetectBias(int32_t index, uint32_t &bias);
zaf_error_code_t TriInX_getMode(int32_t index, SigProcessMode &mode);
zaf_error_code_t TriInX_getTriggerModeTriggerEdge(int32_t index, TriggerEdge &edge);
zaf_error_code_t TriInX_getTriggerModeFreqDivision(int32_t index, uint32_t &division);
zaf_error_code_t TriInX_getTriggerModeFreqMultiplication(int32_t index, uint32_t &multiplication);
zaf_error_code_t TriInX_readInSignalFreq(int32_t index, float &freq);
zaf_error_code_t TriInX_readOutSignalFreq(int32_t index, float &freq);
/*******************************************************************************
* *
*******************************************************************************/
zaf_error_code_t LightSrcX_setTriSrc(int32_t index, InternalSig src);
zaf_error_code_t LightSrcX_setTriggerModePluseWidth(int32_t index, uint32_t width);
zaf_error_code_t LightSrcX_setTriggerModeFirstPluseOffset(int32_t index, uint32_t offset);
zaf_error_code_t LightSrcX_setLightIntensityDuty(int32_t index, float duty);
zaf_error_code_t LightSrcX_setLightDriverFreq(int32_t index, float freq);
zaf_error_code_t LightSrcX_getTriSrc(int32_t index, InternalSig &src);
zaf_error_code_t LightSrcX_getTriggerModePluseWidth(int32_t index, uint32_t &width);
zaf_error_code_t LightSrcX_getTriggerModeFirstPluseOffset(int32_t index, uint32_t &offset);
zaf_error_code_t LightSrcX_getLightIntensityDuty(int32_t index, float &duty);
zaf_error_code_t LightSrcX_getLightDriverFreq(int32_t index, float &freq);
zaf_error_code_t LightSrcX_readLightSrcErrorState(int32_t index, uint32_t &state);
zaf_error_code_t LightSrcX_readInSigFreqDetect(int32_t index, float &freq);
zaf_error_code_t LightSrcX_readOutSigFreqDetect(int32_t index, float &freq);
/*******************************************************************************
* *
*******************************************************************************/
zaf_error_code_t ShutterX_setOutputCtrlMode(int32_t index, SigProcessMode mode);
zaf_error_code_t ShutterX_setLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t state);
zaf_error_code_t ShutterX_setLtEnOffset(int32_t index, uint32_t offset);
zaf_error_code_t ShutterX_setInSigSelect(int32_t index, InternalSig sig);
zaf_error_code_t ShutterX_getOutputCtrlMode(int32_t index, SigProcessMode &mode);
zaf_error_code_t ShutterX_getLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t &state);
zaf_error_code_t ShutterX_getLtEnOffset(int32_t index, uint32_t &offset);
zaf_error_code_t ShutterX_getInSigSelect(int32_t index, InternalSig &sig);
private:
void processRxData(uint8_t *rx, uint32_t rxlen);
void processRxPacket(zaf_packet_header_t *packet);
zaf_error_code_t sendPacket(zaf_packet_header_t *packet, uint32_t len, uint32_t overtime);
zaf_error_code_t readFreq(uint32_t reg, float &freq);
};
} // namespace clst

57
src/camera_light_src_timing_controller/clst_controler_sig_type.cpp

@ -0,0 +1,57 @@
#include "clst_controler_sig_type.hpp"
using namespace iflytop;
using namespace clst;
map<string, ExtTriggerSrcType::EnumType_t> ExtTriggerSrcType::emap = {
{"OPTOCOUPLER_INPUT", OPTOCOUPLER_INPUT}, //
{"DIFF_INPUT", DIFF_INPUT}, //
};
map<string, TriggerEdge::EnumType_t> TriggerEdge::emap = {
{"RISING", RISING}, //
{"FALLING", FALLING}, //
{"BOTH", BOTH} //
};
map<string, SigProcessMode::EnumType_t> SigProcessMode::emap = {
{"TRIGGER_MODE", TRIGGER_MODE}, //
{"TRANSPARENT_MODE", TRANSPARENT_MODE}, //
{"BIND_MODE", BIND_MODE} //
};
map<string, InternalSig::EnumType_t> InternalSig::emap = {
{"LOGIC0", LOGIC0}, //
{"LOGIC1", LOGIC1}, //
{"INTERNAL_TRIGGER", INTERNAL_TRIGGER}, //
{"INTERNAL_TRIGGER_I1", INTERNAL_TRIGGER_I1}, //
{"INTERNAL_TRIGGER_I2", INTERNAL_TRIGGER_I2}, //
{"INTERNAL_TRIGGER_I3", INTERNAL_TRIGGER_I3}, //
{"INTERNAL_TRIGGER_I4", INTERNAL_TRIGGER_I4}, //
{"EXT_TRIGGER_1", EXT_TRIGGER_1}, //
{"EXT_TRIGGER_1_I1", EXT_TRIGGER_1_I1}, //
{"EXT_TRIGGER_1_I2", EXT_TRIGGER_1_I2}, //
{"EXT_TRIGGER_1_I3", EXT_TRIGGER_1_I3}, //
{"EXT_TRIGGER_1_I4", EXT_TRIGGER_1_I4}, //
{"EXT_TRIGGER_2", EXT_TRIGGER_2}, //
{"EXT_TRIGGER_2_I1", EXT_TRIGGER_2_I1}, //
{"EXT_TRIGGER_2_I2", EXT_TRIGGER_2_I2}, //
{"EXT_TRIGGER_2_I3", EXT_TRIGGER_2_I3}, //
{"EXT_TRIGGER_2_I4", EXT_TRIGGER_2_I4}, //
{"EXT_TRIGGER_3", EXT_TRIGGER_3}, //
{"EXT_TRIGGER_3_I1", EXT_TRIGGER_3_I1}, //
{"EXT_TRIGGER_3_I2", EXT_TRIGGER_3_I2}, //
{"EXT_TRIGGER_3_I3", EXT_TRIGGER_3_I3}, //
{"EXT_TRIGGER_3_I4", EXT_TRIGGER_3_I4}, //
{"EXT_TRIGGER_4", EXT_TRIGGER_4}, //
{"EXT_TRIGGER_4_I1", EXT_TRIGGER_4_I1}, //
{"EXT_TRIGGER_4_I2", EXT_TRIGGER_4_I2}, //
{"EXT_TRIGGER_4_I3", EXT_TRIGGER_4_I3}, //
{"EXT_TRIGGER_4_I4", EXT_TRIGGER_4_I4}, //
};

169
src/camera_light_src_timing_controller/clst_controler_sig_type.hpp

@ -0,0 +1,169 @@
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
#include "zaf_protocol/zaf_protocol.h"
namespace iflytop {
namespace clst {
using namespace std;
class ExtTriggerSrcType {
public:
typedef enum {
OPTOCOUPLER_INPUT = 0, // 光耦输入
DIFF_INPUT = 1, // 差分输入
} EnumType_t;
private:
static map<string, EnumType_t> emap;
public:
EnumType_t val;
ExtTriggerSrcType() { val = OPTOCOUPLER_INPUT; }
ExtTriggerSrcType(EnumType_t e) { val = e; }
ExtTriggerSrcType(uint32_t e) { val = (EnumType_t)e; }
ExtTriggerSrcType(string string) { emap.find(string) != emap.end() ? val = emap[string] : val = OPTOCOUPLER_INPUT; }
string toString() { return toString(val); }
string toString(EnumType_t ein) {
for (auto &item : emap) {
if (item.second == ein) return item.first;
}
return "unkown";
}
uint32_t getVal() { return val; }
operator uint32_t() { return val; }
};
class TriggerEdge {
public:
typedef enum {
RISING = 0, // 上升沿触发
FALLING = 1, // 下降沿触发
BOTH = 2, // 上升沿和下降沿触发
} EnumType_t;
private:
static map<string, EnumType_t> emap;
public:
EnumType_t val;
TriggerEdge() { val = RISING; }
TriggerEdge(EnumType_t e) { val = e; }
TriggerEdge(uint32_t e) { val = (EnumType_t)e; }
TriggerEdge(string string) { emap.find(string) != emap.end() ? val = emap[string] : val = RISING; }
string toString() { return toString(val); }
string toString(EnumType_t ein) {
for (auto &item : emap) {
if (item.second == ein) return item.first;
}
return "unkown";
}
uint32_t getVal() { return val; }
operator uint32_t() { return val; }
};
class SigProcessMode {
public:
typedef enum {
TRIGGER_MODE = 0, // 触发模式
TRANSPARENT_MODE = 1, // 透传模式
BIND_MODE = 2 // 绑定模式
} EnumType_t;
private:
static map<string, EnumType_t> emap;
public:
EnumType_t val;
SigProcessMode() { val = TRIGGER_MODE; }
SigProcessMode(EnumType_t e) { val = e; }
SigProcessMode(uint32_t e) { val = (EnumType_t)e; }
SigProcessMode(string string) { emap.find(string) != emap.end() ? val = emap[string] : val = TRIGGER_MODE; }
string toString() { return toString(val); }
string toString(EnumType_t ein) {
for (auto &item : emap) {
if (item.second == ein) return item.first;
}
return "unkown";
}
uint32_t getVal() { return val; }
operator uint32_t() { return val; }
};
class InternalSig {
public:
typedef enum {
LOGIC0 = 0,
LOGIC1 = 1,
INTERNAL_TRIGGER = 2,
INTERNAL_TRIGGER_I1 = 3,
INTERNAL_TRIGGER_I2 = 4,
INTERNAL_TRIGGER_I3 = 5,
INTERNAL_TRIGGER_I4 = 6,
EXT_TRIGGER_1 = 7,
EXT_TRIGGER_1_I1 = 8,
EXT_TRIGGER_1_I2 = 9,
EXT_TRIGGER_1_I3 = 10,
EXT_TRIGGER_1_I4 = 11,
EXT_TRIGGER_2 = 12,
EXT_TRIGGER_2_I1 = 13,
EXT_TRIGGER_2_I2 = 14,
EXT_TRIGGER_2_I3 = 15,
EXT_TRIGGER_2_I4 = 16,
EXT_TRIGGER_3 = 17,
EXT_TRIGGER_3_I1 = 18,
EXT_TRIGGER_3_I2 = 19,
EXT_TRIGGER_3_I3 = 20,
EXT_TRIGGER_3_I4 = 21,
EXT_TRIGGER_4 = 22,
EXT_TRIGGER_4_I1 = 23,
EXT_TRIGGER_4_I2 = 24,
EXT_TRIGGER_4_I3 = 25,
EXT_TRIGGER_4_I4 = 26,
} EnumType_t;
private:
static map<string, EnumType_t> emap;
public:
EnumType_t val;
InternalSig() { val = LOGIC0; }
InternalSig(EnumType_t e) { val = e; }
InternalSig(uint32_t e) { val = (EnumType_t)e; }
InternalSig(string string) { emap.find(string) != emap.end() ? val = emap[string] : val = LOGIC0; }
string toString() { return toString(val); }
string toString(EnumType_t ein) {
for (auto &item : emap) {
if (item.second == ein) return item.first;
}
return "unkown";
}
uint32_t getVal() { return val; }
operator uint32_t() { return val; }
};
} // namespace clst
} // namespace iflytop

2
zaf_protocol

@ -1 +1 @@
Subproject commit 19d549a123f6dcf6e1a47b012a64bf659740638d
Subproject commit d29b00371520aea2566aa09cba2384e3e937a908
Loading…
Cancel
Save