Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Raptor Engineering Public Development
dsview
Commits
800f4c61
Commit
800f4c61
authored
9 years ago
by
DreamSourceLab
Browse files
Options
Download
Email Patches
Plain Diff
Add file save support @ OSC & DAQ mode
parent
df05c5c9
master
No related merge requests found
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
767 additions
and
352 deletions
+767
-352
DSView/pv/data/analogsnapshot.cpp
DSView/pv/data/analogsnapshot.cpp
+2
-2
DSView/pv/device/file.cpp
DSView/pv/device/file.cpp
+4
-1
DSView/pv/devicemanager.cpp
DSView/pv/devicemanager.cpp
+1
-1
DSView/pv/mainwindow.cpp
DSView/pv/mainwindow.cpp
+3
-3
DSView/pv/sigsession.cpp
DSView/pv/sigsession.cpp
+59
-23
DSView/pv/sigsession.h
DSView/pv/sigsession.h
+1
-1
DSView/pv/toolbars/filebar.cpp
DSView/pv/toolbars/filebar.cpp
+5
-11
DSView/pv/view/analogsignal.cpp
DSView/pv/view/analogsignal.cpp
+1
-3
DSView/pv/view/dsosignal.cpp
DSView/pv/view/dsosignal.cpp
+30
-7
DSView/pv/view/logicsignal.cpp
DSView/pv/view/logicsignal.cpp
+5
-0
DSView/pv/view/logicsignal.h
DSView/pv/view/logicsignal.h
+2
-1
DSView/pv/view/view.cpp
DSView/pv/view/view.cpp
+5
-2
libsigrok4DSL/hardware/DSL/dscope.c
libsigrok4DSL/hardware/DSL/dscope.c
+2
-2
libsigrok4DSL/hardware/DSL/dslogic.c
libsigrok4DSL/hardware/DSL/dslogic.c
+96
-84
libsigrok4DSL/hardware/demo/demo.c
libsigrok4DSL/hardware/demo/demo.c
+269
-179
libsigrok4DSL/libsigrok.h
libsigrok4DSL/libsigrok.h
+6
-0
libsigrok4DSL/session_driver.c
libsigrok4DSL/session_driver.c
+145
-11
libsigrok4DSL/session_file.c
libsigrok4DSL/session_file.c
+131
-21
No files found.
DSView/pv/data/analogsnapshot.cpp
View file @
800f4c61
...
...
@@ -47,7 +47,7 @@ const float AnalogSnapshot::LogEnvelopeScaleFactor =
const
uint64_t
AnalogSnapshot
::
EnvelopeDataUnit
=
64
*
1024
;
// bytes
AnalogSnapshot
::
AnalogSnapshot
(
const
sr_datafeed_analog
&
analog
,
uint64_t
_total_sample_len
,
unsigned
int
channel_num
)
:
Snapshot
(
sizeof
(
uint16_t
),
_total_sample_len
,
channel_num
)
Snapshot
(
sizeof
(
uint16_t
)
*
channel_num
,
_total_sample_len
,
channel_num
)
{
boost
::
lock_guard
<
boost
::
recursive_mutex
>
lock
(
_mutex
);
memset
(
_envelope_levels
,
0
,
sizeof
(
_envelope_levels
));
...
...
@@ -66,7 +66,7 @@ void AnalogSnapshot::append_payload(
const
sr_datafeed_analog
&
analog
)
{
boost
::
lock_guard
<
boost
::
recursive_mutex
>
lock
(
_mutex
);
append_data
(
analog
.
data
,
analog
.
num_samples
);
append_data
(
analog
.
data
,
analog
.
num_samples
);
// Generate the first mip-map from the data
append_payload_to_envelope_levels
();
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/device/file.cpp
View file @
800f4c61
...
...
@@ -23,6 +23,8 @@
#include "inputfile.h"
#include "sessionfile.h"
#include <QFileInfo>
#include <boost/filesystem.hpp>
#include <libsigrok4DSL/libsigrok.h>
...
...
@@ -39,7 +41,8 @@ File::File(QString path) :
QString
File
::
format_device_title
()
const
{
return
_path
;
QFileInfo
fi
(
_path
);
return
fi
.
fileName
();
}
File
*
File
::
create
(
QString
name
)
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/devicemanager.cpp
View file @
800f4c61
...
...
@@ -102,7 +102,7 @@ std::list<boost::shared_ptr<device::DevInst> > DeviceManager::driver_scan(
//release_driver(driver);
// Check If DSL hardware driver
if
(
strcmp
(
driver
->
name
,
"
demo"
)
!=
0
)
{
if
(
str
n
cmp
(
driver
->
name
,
"
virtual"
,
7
)
)
{
QDir
dir
(
QCoreApplication
::
applicationDirPath
());
if
(
!
dir
.
cd
(
"res"
))
return
driver_devices
;
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/mainwindow.cpp
View file @
800f4c61
...
...
@@ -319,8 +319,7 @@ void MainWindow::update_device_list()
errorMessage
,
infoMessage
));
}
if
(
strcmp
(
selected_device
->
dev_inst
()
->
driver
->
name
,
"demo"
)
!=
0
&&
strcmp
(
selected_device
->
dev_inst
()
->
driver
->
name
,
"virtual-session"
)
!=
0
)
{
if
(
strncmp
(
selected_device
->
dev_inst
()
->
driver
->
name
,
"virtual"
,
7
))
{
_logo_bar
->
dsl_connected
(
true
);
QString
ses_name
=
config_path
+
QString
::
fromUtf8
(
selected_device
->
dev_inst
()
->
driver
->
name
)
+
...
...
@@ -521,7 +520,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
QString
driver_name
=
_session
.
get_device
()
->
dev_inst
()
->
driver
->
name
;
QString
mode_name
=
QString
::
number
(
_session
.
get_device
()
->
dev_inst
()
->
mode
);
QString
file_name
=
dir
.
absolutePath
()
+
"/"
+
driver_name
+
mode_name
+
".dsc"
;
if
(
!
file_name
.
isEmpty
())
if
(
strncmp
(
driver_name
.
toLocal8Bit
(),
"virtual"
,
7
)
&&
!
file_name
.
isEmpty
())
store_session
(
file_name
);
}
event
->
accept
();
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/sigsession.cpp
View file @
800f4c61
...
...
@@ -177,19 +177,45 @@ void SigSession::set_file(QString name) throw(QString)
}
}
void
SigSession
::
save_file
(
const
QString
name
){
const
deque
<
boost
::
shared_ptr
<
pv
::
data
::
LogicSnapshot
>
>
&
snapshots
=
_logic_data
->
get_snapshots
();
if
(
snapshots
.
empty
())
return
;
const
boost
::
shared_ptr
<
pv
::
data
::
LogicSnapshot
>
&
snapshot
=
snapshots
.
front
();
void
SigSession
::
save_file
(
const
QString
name
,
int
type
){
unsigned
char
*
data
;
int
unit_size
;
uint64_t
sample_count
;
if
(
type
==
ANALOG
)
{
const
deque
<
boost
::
shared_ptr
<
pv
::
data
::
AnalogSnapshot
>
>
&
snapshots
=
_analog_data
->
get_snapshots
();
if
(
snapshots
.
empty
())
return
;
const
boost
::
shared_ptr
<
pv
::
data
::
AnalogSnapshot
>
&
snapshot
=
snapshots
.
front
();
data
=
(
unsigned
char
*
)
snapshot
->
get_data
();
unit_size
=
snapshot
->
unit_size
();
sample_count
=
snapshot
->
get_sample_count
();
}
else
if
(
type
==
DSO
)
{
const
deque
<
boost
::
shared_ptr
<
pv
::
data
::
DsoSnapshot
>
>
&
snapshots
=
_dso_data
->
get_snapshots
();
if
(
snapshots
.
empty
())
return
;
const
boost
::
shared_ptr
<
pv
::
data
::
DsoSnapshot
>
&
snapshot
=
snapshots
.
front
();
data
=
(
unsigned
char
*
)
snapshot
->
get_data
();
// snapshot->unit_size() is not valid for dso, replaced by enabled channel number
unit_size
=
get_ch_num
(
SR_CHANNEL_DSO
);
sample_count
=
snapshot
->
get_sample_count
();
}
else
{
const
deque
<
boost
::
shared_ptr
<
pv
::
data
::
LogicSnapshot
>
>
&
snapshots
=
_logic_data
->
get_snapshots
();
if
(
snapshots
.
empty
())
return
;
const
boost
::
shared_ptr
<
pv
::
data
::
LogicSnapshot
>
&
snapshot
=
snapshots
.
front
();
data
=
(
unsigned
char
*
)
snapshot
->
get_data
();
unit_size
=
snapshot
->
unit_size
();
sample_count
=
snapshot
->
get_sample_count
();
}
sr_session_save
(
name
.
toLocal8Bit
().
data
(),
_dev_inst
->
dev_inst
(),
(
unsigned
char
*
)
snapshot
->
get_data
(),
snapshot
->
unit_size
(),
snapshot
->
get_sample_count
());
data
,
unit_size
,
sample_count
);
}
QList
<
QString
>
SigSession
::
getSuportedExportFormats
(){
...
...
@@ -365,8 +391,8 @@ void SigSession::set_default_device(boost::function<void (const QString)> error_
// Try and find the DreamSourceLab device and select that by default
BOOST_FOREACH
(
boost
::
shared_ptr
<
pv
::
device
::
DevInst
>
dev
,
devices
)
if
(
dev
->
dev_inst
()
&&
strcmp
(
dev
->
dev_inst
()
->
driver
->
name
,
"
demo"
)
!=
0
)
{
str
n
cmp
(
dev
->
dev_inst
()
->
driver
->
name
,
"
virtual"
,
7
)
!=
0
)
{
default_device
=
dev
;
break
;
}
...
...
@@ -423,7 +449,10 @@ void SigSession::start_capture(bool instant,
}
// update setting
_instant
=
instant
;
if
(
strcmp
(
_dev_inst
->
dev_inst
()
->
driver
->
name
,
"virtual-session"
))
_instant
=
instant
;
else
_instant
=
true
;
if
(
~
_instant
)
_view_timer
.
blockSignals
(
false
);
...
...
@@ -545,7 +574,7 @@ void SigSession::sample_thread_proc(boost::shared_ptr<device::DevInst> dev_inst,
assert
(
s
);
boost
::
shared_ptr
<
view
::
LogicSignal
>
logicSig
;
if
(
logicSig
=
dynamic_pointer_cast
<
view
::
LogicSignal
>
(
s
))
{
if
(
logicSig
->
get
_trig
()
!=
0
)
{
if
(
logicSig
->
has
_trig
())
{
ds_trigger_set_en
(
true
);
logicSig
->
set_trig
(
logicSig
->
get_trig
());
}
...
...
@@ -628,12 +657,14 @@ void SigSession::add_group()
_group_traces
.
push_back
(
signal
);
_group_cnt
++
;
if
(
_capture_state
==
Stopped
)
{
const
deque
<
boost
::
shared_ptr
<
data
::
LogicSnapshot
>
>
&
snapshots
=
_logic_data
->
get_snapshots
();
if
(
!
snapshots
.
empty
())
{
//if (!_cur_group_snapshot)
//{
// Create a new data snapshot
_cur_group_snapshot
=
boost
::
shared_ptr
<
data
::
GroupSnapshot
>
(
new
data
::
GroupSnapshot
(
_logic_data
->
get_
snapshots
()
.
front
(),
signal
->
get_index_list
()));
new
data
::
GroupSnapshot
(
snapshots
.
front
(),
signal
->
get_index_list
()));
//_cur_group_snapshot->append_payload();
_group_data
->
push_snapshot
(
_cur_group_snapshot
);
_cur_group_snapshot
.
reset
();
...
...
@@ -724,10 +755,6 @@ void SigSession::init_signals()
if
(
logic_probe_count
!=
0
)
{
_logic_data
.
reset
(
new
data
::
Logic
());
assert
(
_logic_data
);
_group_data
.
reset
(
new
data
::
Group
());
assert
(
_group_data
);
_group_cnt
=
0
;
}
if
(
dso_probe_count
!=
0
)
{
...
...
@@ -739,10 +766,17 @@ void SigSession::init_signals()
_analog_data
.
reset
(
new
data
::
Analog
());
assert
(
_analog_data
);
}
_group_data
.
reset
(
new
data
::
Group
());
assert
(
_group_data
);
_group_cnt
=
0
;
}
// Make the logic probe list
{
_group_traces
.
clear
();
vector
<
boost
::
shared_ptr
<
view
::
GroupSignal
>
>
().
swap
(
_group_traces
);
for
(
const
GSList
*
l
=
_dev_inst
->
dev_inst
()
->
channels
;
l
;
l
=
l
->
next
)
{
const
sr_channel
*
const
probe
=
(
const
sr_channel
*
)
l
->
data
;
...
...
@@ -853,8 +887,10 @@ void SigSession::refresh(int holdtime)
_analog_data
->
clear
();
_cur_analog_snapshot
.
reset
();
}
_data_lock
=
true
;
_refresh_timer
.
start
(
holdtime
);
if
(
strncmp
(
_dev_inst
->
dev_inst
()
->
driver
->
name
,
"virtual"
,
7
))
{
_data_lock
=
true
;
_refresh_timer
.
start
(
holdtime
);
}
data_updated
();
}
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/sigsession.h
View file @
800f4c61
...
...
@@ -117,7 +117,7 @@ public:
void
set_file
(
QString
name
)
throw
(
QString
);
void
save_file
(
const
QString
name
);
void
save_file
(
const
QString
name
,
int
type
);
void
set_default_device
(
boost
::
function
<
void
(
const
QString
)
>
error_handler
);
void
export_file
(
const
QString
name
,
QWidget
*
parent
,
const
QString
ext
);
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/toolbars/filebar.cpp
View file @
800f4c61
...
...
@@ -200,22 +200,16 @@ void FileBar::on_actionSave_triggered()
msg
.
setStandardButtons
(
QMessageBox
::
Ok
);
msg
.
setIcon
(
QMessageBox
::
Warning
);
msg
.
exec
();
}
else
if
(
_session
.
get_device
()
->
dev_inst
()
->
mode
!=
LOGIC
)
{
QMessageBox
msg
(
this
);
msg
.
setText
(
tr
(
"File Save"
));
msg
.
setInformativeText
(
tr
(
"DSView currently only support saving logic data to file!"
));
msg
.
setStandardButtons
(
QMessageBox
::
Ok
);
msg
.
setIcon
(
QMessageBox
::
Warning
);
msg
.
exec
();
}
else
{
}
else
{
QString
file_name
=
QFileDialog
::
getSaveFileName
(
this
,
tr
(
"Save File"
),
""
,
tr
(
"DSView Data (*.dsl)"
));
this
,
tr
(
"Save File"
),
""
,
tr
(
"DSView Data (*.dsl)"
));
if
(
!
file_name
.
isEmpty
())
{
QFileInfo
f
(
file_name
);
if
(
f
.
suffix
().
compare
(
"dsl"
))
file_name
.
append
(
tr
(
".dsl"
));
_session
.
save_file
(
file_name
);
_session
.
save_file
(
file_name
,
_session
.
get_device
()
->
dev_inst
()
->
mode
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/view/analogsignal.cpp
View file @
800f4c61
...
...
@@ -137,8 +137,7 @@ void AnalogSignal::paint_trace(QPainter &p,
//p.setPen(QPen(_colour, 2, Qt::SolidLine));
QPointF
*
points
=
new
QPointF
[
sample_count
];
QPointF
*
point
=
points
;
QPointF
*
point
=
points
;
for
(
int64_t
sample
=
start
;
sample
!=
end
;
sample
++
)
{
const
float
x
=
(
sample
/
samples_per_pixel
-
pixels_offset
)
+
left
;
...
...
@@ -147,7 +146,6 @@ void AnalogSignal::paint_trace(QPainter &p,
}
p
.
drawPolyline
(
points
,
point
-
points
);
//delete[] samples;
delete
[]
points
;
}
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/view/dsosignal.cpp
View file @
800f4c61
...
...
@@ -120,8 +120,6 @@ DsoSignal::DsoSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
//_trig_vpos(probe->index * 0.5 + 0.25),
//_zeroPos(probe->index * 0.5 + 0.25)
_trig_vpos
(
0.5
),
_zeroPos
(
0.5
),
_zero_off
(
255
/
2.0
),
_autoV
(
false
),
_autoH
(
false
),
_hover_en
(
false
),
...
...
@@ -495,6 +493,19 @@ bool DsoSignal::load_settings()
_dev_inst
->
set_config
(
_probe
,
NULL
,
SR_CONF_COUPLING
,
g_variant_new_byte
(
_acCoupling
));
// -- vpos
double
vpos
;
gvar
=
_dev_inst
->
get_config
(
_probe
,
NULL
,
SR_CONF_VPOS
);
if
(
gvar
!=
NULL
)
{
vpos
=
g_variant_get_double
(
gvar
);
g_variant_unref
(
gvar
);
}
else
{
qDebug
()
<<
"ERROR: config_get SR_CONF_COUPLING failed."
;
return
false
;
}
_zeroPos
=
min
(
max
((
0.5
-
vpos
/
(
_vDial
->
get_value
()
*
DS_CONF_DSO_VDIVS
)),
0.0
),
1.0
);
_zero_off
=
_zeroPos
*
255
;
if
(
_view
)
{
_view
->
set_need_update
(
true
);
_view
->
update
();
...
...
@@ -657,6 +668,7 @@ uint64_t DsoSignal::get_factor()
void
DsoSignal
::
set_ms_show
(
bool
show
)
{
_ms_show
=
show
;
_view
->
set_need_update
(
true
);
}
bool
DsoSignal
::
get_ms_show
()
const
...
...
@@ -1093,7 +1105,12 @@ bool DsoSignal::mouse_press(int right, const QPoint pt)
const
QRectF
x10_rect
=
get_rect
(
DSO_X10
,
y
,
right
);
const
QRectF
x100_rect
=
get_rect
(
DSO_X100
,
y
,
right
);
if
(
enabled
())
{
if
(
chEn_rect
.
contains
(
pt
))
{
if
(
strcmp
(
_dev_inst
->
dev_inst
()
->
driver
->
name
,
"virtual-session"
)
&&
!
_view
->
session
().
get_data_lock
())
set_enable
(
!
enabled
());
return
true
;
}
else
if
(
enabled
())
{
if
(
vDec_rect
.
contains
(
pt
))
{
go_vDialPre
();
}
else
if
(
vInc_rect
.
contains
(
pt
))
{
...
...
@@ -1114,10 +1131,8 @@ bool DsoSignal::mouse_press(int right, const QPoint pt)
setted
=
true
;
}
}
}
else
if
(
chEn_rect
.
contains
(
pt
))
{
if
(
!
_view
->
session
().
get_data_lock
())
set_enable
(
!
enabled
());
}
else
if
(
acdc_rect
.
contains
(
pt
))
{
}
else
if
(
strcmp
(
_dev_inst
->
dev_inst
()
->
driver
->
name
,
"virtual-session"
)
&&
acdc_rect
.
contains
(
pt
))
{
if
(
strcmp
(
_view
->
session
().
get_device
()
->
dev_inst
()
->
driver
->
name
,
"DSLogic"
)
==
0
)
set_acCoupling
((
get_acCoupling
()
+
1
)
%
2
);
else
...
...
@@ -1284,6 +1299,14 @@ void DsoSignal::paint_measure(QPainter &p)
_ms_string
[
DSO_MS_VMEA
]
=
"Vmean: "
+
(
abs
(
value_vmean
)
>
1000
?
QString
::
number
(
value_vmean
/
1000.0
,
'f'
,
2
)
+
"V"
:
QString
::
number
(
value_vmean
,
'f'
,
2
)
+
"mV"
);
}
}
}
else
{
_ms_string
[
DSO_MS_VMAX
]
=
"Vmax: #####"
;
_ms_string
[
DSO_MS_VMIN
]
=
"Vmin: #####"
;
_ms_string
[
DSO_MS_PERD
]
=
"Perd: #####"
;
_ms_string
[
DSO_MS_FREQ
]
=
"Freq: #####"
;
_ms_string
[
DSO_MS_VP2P
]
=
"Vp-p: #####"
;
_ms_string
[
DSO_MS_VRMS
]
=
"Vrms: #####"
;
_ms_string
[
DSO_MS_VMEA
]
=
"Vmean: #####"
;
}
QColor
measure_colour
=
_colour
;
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/view/logicsignal.cpp
View file @
800f4c61
...
...
@@ -105,6 +105,11 @@ boost::shared_ptr<pv::data::Logic> LogicSignal::logic_data() const
return
_data
;
}
bool
LogicSignal
::
has_trig
()
const
{
return
(
_trig
!=
NONTRIG
);
}
LogicSignal
::
LogicSetRegions
LogicSignal
::
get_trig
()
const
{
return
_trig
;
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/view/logicsignal.h
View file @
800f4c61
...
...
@@ -54,7 +54,7 @@ private:
static
const
int
StateRound
;
enum
LogicSetRegions
{
NONTRIG
=
-
1
,
NONTRIG
=
0
,
POSTRIG
,
HIGTRIG
,
NEGTRIG
,
...
...
@@ -82,6 +82,7 @@ public:
/**
*
*/
bool
has_trig
()
const
;
LogicSetRegions
get_trig
()
const
;
void
set_trig
(
int
trig
);
...
...
This diff is collapsed.
Click to expand it.
DSView/pv/view/view.cpp
View file @
800f4c61
...
...
@@ -226,8 +226,11 @@ void View::zoom(double steps, int offset)
}
}
}
_offset
=
cursor_offset
-
_scale
*
offset
;
_offset
=
max
(
min
(
_offset
,
get_max_offset
()),
get_min_offset
());
if
(
_session
.
get_device
()
->
dev_inst
()
->
mode
!=
DSO
)
{
_offset
=
cursor_offset
-
_scale
*
offset
;
_offset
=
max
(
min
(
_offset
,
get_max_offset
()),
get_min_offset
());
}
if
(
_scale
!=
_preScale
||
_offset
!=
_preOffset
)
{
_header
->
update
();
...
...
This diff is collapsed.
Click to expand it.
libsigrok4DSL/hardware/DSL/dscope.c
View file @
800f4c61
...
...
@@ -1485,10 +1485,10 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
ret
=
command_dso_ctrl
(
usb
->
devhdl
,
dso_cmd_gen
(
sdi
,
ch
,
SR_CONF_VPOS
));
}
if
(
ret
==
SR_OK
)
sr_dbg
(
"%s: setting VPOS of channel %d to %
d
mv"
,
sr_dbg
(
"%s: setting VPOS of channel %d to %
lf
mv"
,
__func__
,
ch
->
index
,
ch
->
vpos
);
else
sr_dbg
(
"%s: setting VPOS of channel %d to %
d
mv failed"
,
sr_dbg
(
"%s: setting VPOS of channel %d to %
lf
mv failed"
,
__func__
,
ch
->
index
,
ch
->
vpos
);
}
else
if
(
id
==
SR_CONF_TIMEBASE
)
{
devc
->
timebase
=
g_variant_get_uint64
(
data
);
...
...
This diff is collapsed.
Click to expand it.
libsigrok4DSL/hardware/DSL/dslogic.c
View file @
800f4c61
...
...
@@ -722,6 +722,7 @@ static int set_probes(struct sr_dev_inst *sdi, int num_probes)
if
(
sdi
->
mode
==
DSO
)
{
probe
->
vdiv
=
1000
;
probe
->
vfactor
=
1
;
probe
->
vpos
=
0
;
probe
->
coupling
=
SR_DC_COUPLING
;
probe
->
trig_value
=
0x80
;
}
...
...
@@ -1294,6 +1295,11 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
return
SR_ERR
;
*
data
=
g_variant_new_uint64
(
ch
->
vfactor
);
break
;
case
SR_CONF_VPOS
:
if
(
!
ch
)
return
SR_ERR
;
*
data
=
g_variant_new_double
(
ch
->
vpos
);
break
;
case
SR_CONF_TIMEBASE
:
if
(
!
sdi
)
return
SR_ERR
;
...
...
@@ -1558,71 +1564,75 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
}
else
if
(
id
==
SR_CONF_OPERATION_MODE
)
{
stropt
=
g_variant_get_string
(
data
,
NULL
);
ret
=
SR_OK
;
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_BUFFER
])
&&
(
devc
->
op_mode
!=
SR_OP_BUFFER
))
{
devc
->
op_mode
=
SR_OP_BUFFER
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_STREAM
])
&&
(
devc
->
op_mode
!=
SR_OP_STREAM
))
{
devc
->
op_mode
=
SR_OP_STREAM
;
devc
->
stream
=
TRUE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
10
;
adjust_probes
(
sdi
,
stream_ch_num
[
0
]);
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_INTERNAL_TEST
])
&&
(
devc
->
op_mode
!=
SR_OP_INTERNAL_TEST
))
{
devc
->
op_mode
=
SR_OP_INTERNAL_TEST
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
devc
->
limit_samples
=
DSLOGIC_MAX_LOGIC_DEPTH
;
devc
->
cur_samplerate
=
DSLOGIC_MAX_LOGIC_SAMPLERATE
;
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_EXTERNAL_TEST
])
&&
(
devc
->
op_mode
!=
SR_OP_EXTERNAL_TEST
))
{
devc
->
op_mode
=
SR_OP_EXTERNAL_TEST
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
devc
->
limit_samples
=
DSLOGIC_MAX_LOGIC_DEPTH
;
devc
->
cur_samplerate
=
DSLOGIC_MAX_LOGIC_SAMPLERATE
;
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_LOOPBACK_TEST
])
&&
(
devc
->
op_mode
!=
SR_OP_LOOPBACK_TEST
))
{
devc
->
op_mode
=
SR_OP_LOOPBACK_TEST
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
devc
->
limit_samples
=
DSLOGIC_MAX_LOGIC_DEPTH
;
devc
->
cur_samplerate
=
DSLOGIC_MAX_LOGIC_SAMPLERATE
;
}
else
{
ret
=
SR_ERR
;
if
(
sdi
->
mode
==
LOGIC
)
{
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_BUFFER
])
&&
(
devc
->
op_mode
!=
SR_OP_BUFFER
))
{
devc
->
op_mode
=
SR_OP_BUFFER
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_STREAM
])
&&
(
devc
->
op_mode
!=
SR_OP_STREAM
))
{
devc
->
op_mode
=
SR_OP_STREAM
;
devc
->
stream
=
TRUE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
10
;
adjust_probes
(
sdi
,
stream_ch_num
[
0
]);
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_INTERNAL_TEST
])
&&
(
devc
->
op_mode
!=
SR_OP_INTERNAL_TEST
))
{
devc
->
op_mode
=
SR_OP_INTERNAL_TEST
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
devc
->
limit_samples
=
DSLOGIC_MAX_LOGIC_DEPTH
;
devc
->
cur_samplerate
=
DSLOGIC_MAX_LOGIC_SAMPLERATE
;
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_EXTERNAL_TEST
])
&&
(
devc
->
op_mode
!=
SR_OP_EXTERNAL_TEST
))
{
devc
->
op_mode
=
SR_OP_EXTERNAL_TEST
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
devc
->
limit_samples
=
DSLOGIC_MAX_LOGIC_DEPTH
;
devc
->
cur_samplerate
=
DSLOGIC_MAX_LOGIC_SAMPLERATE
;
}
else
if
(
!
strcmp
(
stropt
,
opmodes
[
SR_OP_LOOPBACK_TEST
])
&&
(
devc
->
op_mode
!=
SR_OP_LOOPBACK_TEST
))
{
devc
->
op_mode
=
SR_OP_LOOPBACK_TEST
;
devc
->
stream
=
FALSE
;
devc
->
ch_mode
=
0
;
devc
->
samplerates_size
=
14
;
adjust_probes
(
sdi
,
buffer_ch_num
[
0
]);
devc
->
limit_samples
=
DSLOGIC_MAX_LOGIC_DEPTH
;
devc
->
cur_samplerate
=
DSLOGIC_MAX_LOGIC_SAMPLERATE
;
}
else
{
ret
=
SR_ERR
;
}
if
(
devc
->
cur_samplerate
>
samplerates
[
devc
->
samplerates_size
-
1
])
devc
->
cur_samplerate
=
samplerates
[
devc
->
samplerates_size
-
1
];
}
if
(
devc
->
cur_samplerate
>
samplerates
[
devc
->
samplerates_size
-
1
])
devc
->
cur_samplerate
=
samplerates
[
devc
->
samplerates_size
-
1
];
sr_dbg
(
"%s: setting pattern to %d"
,
__func__
,
devc
->
op_mode
);
}
else
if
(
id
==
SR_CONF_CHANNEL_MODE
)
{
stropt
=
g_variant_get_string
(
data
,
NULL
);
ret
=
SR_OK
;
if
(
devc
->
stream
)
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
stream_ch_modes
);
i
++
)
if
(
!
strcmp
(
stropt
,
stream_ch_modes
[
i
]))
{
devc
->
ch_mode
=
i
;
devc
->
samplerates_size
=
10
+
i
*
2
;
adjust_probes
(
sdi
,
stream_ch_num
[
i
]);
break
;
}
}
else
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
buffer_ch_modes
);
i
++
)
if
(
!
strcmp
(
stropt
,
buffer_ch_modes
[
i
]))
{
devc
->
ch_mode
=
i
;
devc
->
samplerates_size
=
14
+
i
;
adjust_probes
(
sdi
,
buffer_ch_num
[
i
]);
break
;
}
if
(
sdi
->
mode
==
LOGIC
)
{
if
(
devc
->
stream
)
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
stream_ch_modes
);
i
++
)
if
(
!
strcmp
(
stropt
,
stream_ch_modes
[
i
]))
{
devc
->
ch_mode
=
i
;
devc
->
samplerates_size
=
10
+
i
*
2
;
adjust_probes
(
sdi
,
stream_ch_num
[
i
]);
break
;
}
}
else
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
buffer_ch_modes
);
i
++
)
if
(
!
strcmp
(
stropt
,
buffer_ch_modes
[
i
]))
{
devc
->
ch_mode
=
i
;
devc
->
samplerates_size
=
14
+
i
;
adjust_probes
(
sdi
,
buffer_ch_num
[
i
]);
break
;
}
}
if
(
devc
->
cur_samplerate
>
samplerates
[
devc
->
samplerates_size
-
1
])
devc
->
cur_samplerate
=
samplerates
[
devc
->
samplerates_size
-
1
];
}
if
(
devc
->
cur_samplerate
>
samplerates
[
devc
->
samplerates_size
-
1
])
devc
->
cur_samplerate
=
samplerates
[
devc
->
samplerates_size
-
1
];
sr_dbg
(
"%s: setting channel mode to %d"
,
__func__
,
devc
->
ch_mode
);
}
else
if
(
id
==
SR_CONF_THRESHOLD
)
{
...
...
@@ -1635,32 +1645,34 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
}
else
{
ret
=
SR_ERR
;
}
if
((
ret
=
command_fpga_config
(
usb
->
devhdl
))
!=
SR_OK
)
{
sr_err
(
"Send FPGA configure command failed!"
);
}
else
{
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep
(
10
*
1000
);
char
*
fpga_bit
;
if
(
!
(
fpga_bit
=
g_try_malloc
(
strlen
(
config_path
)
+
strlen
(
devc
->
profile
->
fpga_bit33
)
+
1
)))
{
sr_err
(
"fpag_bit path malloc error!"
);
return
SR_ERR_MALLOC
;
}
strcpy
(
fpga_bit
,
config_path
);
switch
(
devc
->
th_level
)
{
case
SR_TH_3V3
:
strcat
(
fpga_bit
,
devc
->
profile
->
fpga_bit33
);;
break
;
case
SR_TH_5V0
:
strcat
(
fpga_bit
,
devc
->
profile
->
fpga_bit50
);;
break
;
default:
return
SR_ERR
;
}
ret
=
fpga_config
(
usb
->
devhdl
,
fpga_bit
);
if
(
ret
!=
SR_OK
)
{
sr_err
(
"Configure FPGA failed!"
);
if
(
sdi
->
mode
==
LOGIC
)
{
if
((
ret
=
command_fpga_config
(
usb
->
devhdl
))
!=
SR_OK
)
{
sr_err
(
"Send FPGA configure command failed!"
);
}
else
{
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep
(
10
*
1000
);
char
*
fpga_bit
;
if
(
!
(
fpga_bit
=
g_try_malloc
(
strlen
(
config_path
)
+
strlen
(
devc
->
profile
->
fpga_bit33
)
+
1
)))
{
sr_err
(
"fpag_bit path malloc error!"
);
return
SR_ERR_MALLOC
;
}
strcpy
(
fpga_bit
,
config_path
);
switch
(
devc
->
th_level
)
{
case
SR_TH_3V3
:
strcat
(
fpga_bit
,
devc
->
profile
->
fpga_bit33
);;
break
;
case
SR_TH_5V0
:
strcat
(
fpga_bit
,
devc
->
profile
->
fpga_bit50
);;
break
;
default:
return
SR_ERR
;
}
ret
=
fpga_config
(
usb
->
devhdl
,
fpga_bit
);
if
(
ret
!=
SR_OK
)
{
sr_err
(
"Configure FPGA failed!"
);
}
g_free
(
fpga_bit
);
}
g_free
(
fpga_bit
);
}
sr_dbg
(
"%s: setting threshold to %d"
,
__func__
,
devc
->
th_level
);
...
...
@@ -2225,7 +2237,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
packet
.
type
=
SR_DF_ANALOG
;
packet
.
payload
=
&
analog
;
analog
.
probes
=
(
*
(
struct
sr_dev_inst
*
)(
devc
->
cb_data
)).
channels
;
analog
.
num_samples
=
transfer
->
actual_length
/
sample_width
;
analog
.
num_samples
=
(
transfer
->
actual_length
/
sample_width
)
/
g_slist_length
(
analog
.
probes
)
;
analog
.
mq
=
SR_MQ_VOLTAGE
;
analog
.
unit
=
SR_UNIT_VOLT
;
analog
.
mqflags
=
SR_MQFLAG_AC
;
...
...
This diff is collapsed.
Click to expand it.
libsigrok4DSL/hardware/demo/demo.c
View file @
800f4c61
This diff is collapsed.
Click to expand it.
libsigrok4DSL/libsigrok.h
View file @
800f4c61
...
...
@@ -753,6 +753,12 @@ enum {
SR_CONF_ZERO
,
SR_CONF_ZERO_OVER
,
/** status for dso channel */
SR_CONF_STATUS_PERIOD
,
SR_CONF_STATUS_PCNT
,
SR_CONF_STATUS_MAX
,
SR_CONF_STATUS_MIN
,
/** Stream */
SR_CONF_STREAM
,
...
...
This diff is collapsed.
Click to expand it.
libsigrok4DSL/session_driver.c
View file @
800f4c61
...
...
@@ -54,6 +54,8 @@ struct session_vdev {
uint64_t
total_samples
;
int
unitsize
;
int
num_probes
;
uint64_t
timebase
;
struct
sr_status
mstatus
;
};
static
GSList
*
dev_insts
=
NULL
;
...
...
@@ -69,6 +71,8 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *cb_sdi)
struct
session_vdev
*
vdev
;
struct
sr_datafeed_packet
packet
;
struct
sr_datafeed_logic
logic
;
struct
sr_datafeed_dso
dso
;
struct
sr_datafeed_analog
analog
;
GSList
*
l
;
int
ret
,
got_data
;
(
void
)
fd
;
...
...
@@ -87,11 +91,31 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *cb_sdi)
ret
=
zip_fread
(
vdev
->
capfile
,
vdev
->
buf
,
CHUNKSIZE
);
if
(
ret
>
0
)
{
got_data
=
TRUE
;
packet
.
type
=
SR_DF_LOGIC
;
packet
.
payload
=
&
logic
;
logic
.
length
=
ret
;
logic
.
unitsize
=
vdev
->
unitsize
;
logic
.
data
=
vdev
->
buf
;
if
(
sdi
->
mode
==
DSO
)
{
packet
.
type
=
SR_DF_DSO
;
packet
.
payload
=
&
dso
;
dso
.
num_samples
=
ret
/
vdev
->
unitsize
;
dso
.
data
=
vdev
->
buf
;
dso
.
probes
=
sdi
->
channels
;
dso
.
mq
=
SR_MQ_VOLTAGE
;
dso
.
unit
=
SR_UNIT_VOLT
;
dso
.
mqflags
=
SR_MQFLAG_AC
;
}
else
if
(
sdi
->
mode
==
ANALOG
){
packet
.
type
=
SR_DF_ANALOG
;
packet
.
payload
=
&
analog
;
analog
.
probes
=
sdi
->
channels
;
analog
.
num_samples
=
ret
/
vdev
->
unitsize
;
analog
.
mq
=
SR_MQ_VOLTAGE
;
analog
.
unit
=
SR_UNIT_VOLT
;
analog
.
mqflags
=
SR_MQFLAG_AC
;
analog
.
data
=
vdev
->
buf
;
}
else
{
packet
.
type
=
SR_DF_LOGIC
;
packet
.
payload
=
&
logic
;
logic
.
length
=
ret
;
logic
.
unitsize
=
vdev
->
unitsize
;
logic
.
data
=
vdev
->
buf
;
}
vdev
->
bytes_read
+=
ret
;
sr_session_send
(
cb_sdi
,
&
packet
);
}
else
{
...
...
@@ -166,7 +190,9 @@ static int dev_close(struct sr_dev_inst *sdi)
return
SR_OK
;
}
static
int
config_get
(
int
id
,
GVariant
**
data
,
const
struct
sr_dev_inst
*
sdi
)
static
int
config_get
(
int
id
,
GVariant
**
data
,
const
struct
sr_dev_inst
*
sdi
,
const
struct
sr_channel
*
ch
,
const
struct
sr_channel_group
*
cg
)
{
struct
session_vdev
*
vdev
;
...
...
@@ -185,14 +211,63 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
}
else
return
SR_ERR
;
break
;
default:
case
SR_CONF_TIMEBASE
:
if
(
sdi
)
{
vdev
=
sdi
->
priv
;
*
data
=
g_variant_new_uint64
(
vdev
->
timebase
);
}
else
return
SR_ERR
;
break
;
case
SR_CONF_EN_CH
:
if
(
sdi
&&
ch
)
{
*
data
=
g_variant_new_boolean
(
ch
->
enabled
);
}
else
return
SR_ERR
;
break
;
case
SR_CONF_COUPLING
:
if
(
sdi
&&
ch
)
{
*
data
=
g_variant_new_byte
(
ch
->
coupling
);
}
else
return
SR_ERR
;
break
;
case
SR_CONF_VDIV
:
if
(
sdi
&&
ch
)
{
*
data
=
g_variant_new_uint64
(
ch
->
vdiv
);
}
else
return
SR_ERR
;
break
;
case
SR_CONF_FACTOR
:
if
(
sdi
&&
ch
)
{
*
data
=
g_variant_new_uint64
(
ch
->
vfactor
);
}
else
return
SR_ERR
;
break
;
case
SR_CONF_VPOS
:
if
(
sdi
&&
ch
)
{
*
data
=
g_variant_new_double
(
ch
->
vpos
);
}
else
return
SR_ERR
;
break
;
case
SR_CONF_MAX_DSO_SAMPLERATE
:
if
(
!
sdi
)
return
SR_ERR
;
*
data
=
g_variant_new_uint64
(
vdev
->
samplerate
);
break
;
case
SR_CONF_MAX_DSO_SAMPLELIMITS
:
if
(
!
sdi
)
return
SR_ERR
;
*
data
=
g_variant_new_uint64
(
vdev
->
total_samples
);
break
;
default:
return
SR_ERR_ARG
;
}
return
SR_OK
;
}
static
int
config_set
(
int
id
,
GVariant
*
data
,
const
struct
sr_dev_inst
*
sdi
)
static
int
config_set
(
int
id
,
GVariant
*
data
,
const
struct
sr_dev_inst
*
sdi
,
struct
sr_channel
*
ch
,
const
struct
sr_channel_group
*
cg
)
{
struct
session_vdev
*
vdev
;
...
...
@@ -204,7 +279,11 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
samplerates
[
0
]
=
vdev
->
samplerate
;
sr_info
(
"Setting samplerate to %"
PRIu64
"."
,
vdev
->
samplerate
);
break
;
case
SR_CONF_SESSIONFILE
:
case
SR_CONF_TIMEBASE
:
vdev
->
timebase
=
g_variant_get_uint64
(
data
);
sr_info
(
"Setting timebase to %"
PRIu64
"."
,
vdev
->
timebase
);
break
;
case
SR_CONF_SESSIONFILE
:
vdev
->
sessionfile
=
g_strdup
(
g_variant_get_bytestring
(
data
));
sr_info
(
"Setting sessionfile to '%s'."
,
vdev
->
sessionfile
);
break
;
...
...
@@ -223,7 +302,46 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
case
SR_CONF_CAPTURE_NUM_PROBES
:
vdev
->
num_probes
=
g_variant_get_uint64
(
data
);
break
;
default:
case
SR_CONF_EN_CH
:
ch
->
enabled
=
g_variant_get_boolean
(
data
);
break
;
case
SR_CONF_COUPLING
:
ch
->
coupling
=
g_variant_get_byte
(
data
);
break
;
case
SR_CONF_VDIV
:
ch
->
vdiv
=
g_variant_get_uint64
(
data
);
break
;
case
SR_CONF_FACTOR
:
ch
->
vfactor
=
g_variant_get_uint64
(
data
);
break
;
case
SR_CONF_VPOS
:
ch
->
vpos
=
g_variant_get_double
(
data
);
break
;
case
SR_CONF_STATUS_PERIOD
:
if
(
ch
->
index
==
0
)
vdev
->
mstatus
.
ch0_period
=
g_variant_get_uint64
(
data
);
else
vdev
->
mstatus
.
ch1_period
=
g_variant_get_uint64
(
data
);
break
;
case
SR_CONF_STATUS_PCNT
:
if
(
ch
->
index
==
0
)
vdev
->
mstatus
.
ch0_pcnt
=
g_variant_get_uint64
(
data
);
else
vdev
->
mstatus
.
ch1_pcnt
=
g_variant_get_uint64
(
data
);
break
;
case
SR_CONF_STATUS_MAX
:
if
(
ch
->
index
==
0
)
vdev
->
mstatus
.
ch0_max
=
g_variant_get_uint64
(
data
);
else
vdev
->
mstatus
.
ch1_max
=
g_variant_get_uint64
(
data
);
break
;
case
SR_CONF_STATUS_MIN
:
if
(
ch
->
index
==
0
)
vdev
->
mstatus
.
ch0_min
=
g_variant_get_uint64
(
data
);
else
vdev
->
mstatus
.
ch1_min
=
g_variant_get_uint64
(
data
);
break
;
default:
sr_err
(
"Unknown capability: %d."
,
id
);
return
SR_ERR
;
}
...
...
@@ -268,6 +386,22 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
return
SR_OK
;
}
static
int
dev_status_get
(
struct
sr_dev_inst
*
sdi
,
struct
sr_status
*
status
,
int
begin
,
int
end
)
{
(
void
)
begin
;
(
void
)
end
;
struct
session_vdev
*
vdev
;
if
(
sdi
)
{
vdev
=
sdi
->
priv
;
*
status
=
vdev
->
mstatus
;
return
SR_OK
;
}
else
{
return
SR_ERR
;
}
}
static
int
dev_acquisition_start
(
const
struct
sr_dev_inst
*
sdi
,
void
*
cb_data
)
{
...
...
@@ -324,7 +458,7 @@ SR_PRIV struct sr_dev_driver session_driver = {
.
dev_open
=
dev_open
,
.
dev_close
=
dev_close
,
.
dev_test
=
NULL
,
.
dev_status_get
=
NULL
,
.
dev_status_get
=
dev_status_get
,
.
dev_acquisition_start
=
dev_acquisition_start
,
.
dev_acquisition_stop
=
NULL
,
.
priv
=
NULL
,
...
...
This diff is collapsed.
Click to expand it.
libsigrok4DSL/session_file.c
View file @
800f4c61
...
...
@@ -121,12 +121,15 @@ SR_API int sr_session_load(const char *filename)
struct
zip_stat
zs
;
struct
sr_dev_inst
*
sdi
;
struct
sr_channel
*
probe
;
int
ret
,
devcnt
,
i
,
j
;
int
ret
,
devcnt
,
i
,
j
,
k
;
uint16_t
probenum
;
uint64_t
tmp_u64
,
total_probes
,
enabled_probes
;
uint16_t
p
;
char
**
sections
,
**
keys
,
*
metafile
,
*
val
,
s
[
11
];
char
probename
[
SR_MAX_PROBENAME_LEN
+
1
];
int
mode
=
LOGIC
;
int
channel_type
=
SR_CHANNEL_LOGIC
;
double
tmp_double
;
if
(
!
filename
)
{
sr_err
(
"%s: filename was NULL"
,
__func__
);
...
...
@@ -140,7 +143,7 @@ SR_API int sr_session_load(const char *filename)
/* read "metadata" */
if
(
zip_stat
(
archive
,
"header"
,
0
,
&
zs
)
==
-
1
)
{
sr_dbg
(
"Not a valid DS
Logic session
file."
);
sr_dbg
(
"Not a valid DS
View data
file."
);
return
SR_ERR
;
}
...
...
@@ -175,8 +178,10 @@ SR_API int sr_session_load(const char *filename)
keys
=
g_key_file_get_keys
(
kf
,
sections
[
i
],
NULL
,
NULL
);
for
(
j
=
0
;
keys
[
j
];
j
++
)
{
val
=
g_key_file_get_string
(
kf
,
sections
[
i
],
keys
[
j
],
NULL
);
if
(
!
strcmp
(
keys
[
j
],
"capturefile"
))
{
sdi
=
sr_dev_inst_new
(
LOGIC
,
devcnt
,
SR_ST_ACTIVE
,
NULL
,
NULL
,
NULL
);
if
(
!
strcmp
(
keys
[
j
],
"device mode"
))
{
mode
=
strtoull
(
val
,
NULL
,
10
);
}
else
if
(
!
strcmp
(
keys
[
j
],
"capturefile"
))
{
sdi
=
sr_dev_inst_new
(
mode
,
devcnt
,
SR_ST_ACTIVE
,
NULL
,
NULL
,
NULL
);
sdi
->
driver
=
&
session_driver
;
if
(
devcnt
==
0
)
/* first device, init the driver */
...
...
@@ -200,13 +205,19 @@ SR_API int sr_session_load(const char *filename)
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
sdi
->
driver
->
config_set
(
SR_CONF_LIMIT_SAMPLES
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
NULL
,
NULL
);
}
else
if
(
!
strcmp
(
keys
[
j
],
"total probes"
))
{
}
else
if
(
!
strcmp
(
keys
[
j
],
"hDiv"
))
{
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
sdi
->
driver
->
config_set
(
SR_CONF_TIMEBASE
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
NULL
,
NULL
);
}
else
if
(
!
strcmp
(
keys
[
j
],
"total probes"
))
{
total_probes
=
strtoull
(
val
,
NULL
,
10
);
sdi
->
driver
->
config_set
(
SR_CONF_CAPTURE_NUM_PROBES
,
g_variant_new_uint64
(
total_probes
),
sdi
,
NULL
,
NULL
);
channel_type
=
(
mode
==
DSO
)
?
SR_CHANNEL_DSO
:
(
mode
==
ANALOG
)
?
SR_CHANNEL_ANALOG
:
SR_CHANNEL_LOGIC
;
for
(
p
=
0
;
p
<
total_probes
;
p
++
)
{
snprintf
(
probename
,
SR_MAX_PROBENAME_LEN
,
"%"
PRIu64
,
p
);
if
(
!
(
probe
=
sr_channel_new
(
p
,
SR_CHANNEL_LOGIC
,
FALSE
,
if
(
!
(
probe
=
sr_channel_new
(
p
,
channel_type
,
FALSE
,
probename
)))
return
SR_ERR
;
sdi
->
channels
=
g_slist_append
(
sdi
->
channels
,
probe
);
...
...
@@ -222,7 +233,79 @@ SR_API int sr_session_load(const char *filename)
}
else
if
(
!
strncmp
(
keys
[
j
],
"trigger"
,
7
))
{
probenum
=
strtoul
(
keys
[
j
]
+
7
,
NULL
,
10
);
sr_dev_trigger_set
(
sdi
,
probenum
,
val
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"enable"
,
6
))
{
probenum
=
strtoul
(
keys
[
j
]
+
6
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_EN_CH
,
g_variant_new_boolean
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"coupling"
,
8
))
{
probenum
=
strtoul
(
keys
[
j
]
+
8
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_COUPLING
,
g_variant_new_byte
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"vDiv"
,
4
))
{
probenum
=
strtoul
(
keys
[
j
]
+
4
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_VDIV
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"vFactor"
,
7
))
{
probenum
=
strtoul
(
keys
[
j
]
+
7
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_FACTOR
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"vPos"
,
4
))
{
probenum
=
strtoul
(
keys
[
j
]
+
4
,
NULL
,
10
);
tmp_double
=
strtod
(
val
,
NULL
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_VPOS
,
g_variant_new_double
(
tmp_double
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"period"
,
6
))
{
probenum
=
strtoul
(
keys
[
j
]
+
6
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_STATUS_PERIOD
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"pcnt"
,
4
))
{
probenum
=
strtoul
(
keys
[
j
]
+
4
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_STATUS_PCNT
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"max"
,
3
))
{
probenum
=
strtoul
(
keys
[
j
]
+
3
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_STATUS_MAX
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
else
if
(
!
strncmp
(
keys
[
j
],
"min"
,
3
))
{
probenum
=
strtoul
(
keys
[
j
]
+
3
,
NULL
,
10
);
tmp_u64
=
strtoull
(
val
,
NULL
,
10
);
if
(
probenum
<
g_slist_length
(
sdi
->
channels
))
{
probe
=
g_slist_nth
(
sdi
->
channels
,
probenum
)
->
data
;
sdi
->
driver
->
config_set
(
SR_CONF_STATUS_MIN
,
g_variant_new_uint64
(
tmp_u64
),
sdi
,
probe
,
NULL
);
}
}
}
g_strfreev
(
keys
);
}
...
...
@@ -257,8 +340,9 @@ SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
struct
zip
*
zipfile
;
struct
zip_source
*
versrc
,
*
metasrc
,
*
logicsrc
;
int
tmpfile
,
ret
,
probecnt
;
uint64_t
samplerate
;
uint64_t
samplerate
,
timeBase
,
tmp_u64
;
char
rawname
[
16
],
metafile
[
32
],
*
s
;
struct
sr_status
status
;
if
(
!
filename
)
{
sr_err
(
"%s: filename was NULL"
,
__func__
);
...
...
@@ -271,42 +355,68 @@ SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
return
SR_ERR
;
/* init "metadata" */
strcpy
(
metafile
,
"DS
Logic
-meta-XXXXXX"
);
strcpy
(
metafile
,
"DS
View
-meta-XXXXXX"
);
if
((
tmpfile
=
g_mkstemp
(
metafile
))
==
-
1
)
return
SR_ERR
;
close
(
tmpfile
);
meta
=
g_fopen
(
metafile
,
"wb"
);
fprintf
(
meta
,
"[version]
\n
"
);
fprintf
(
meta
,
"DS
Logic
version = %s
\n
"
,
PACKAGE_VERSION
);
fprintf
(
meta
,
"DS
View
version = %s
\n
"
,
PACKAGE_VERSION
);
/* metadata */
fprintf
(
meta
,
"[header]
\n
"
);
if
(
sdi
->
driver
)
if
(
sdi
->
driver
)
{
fprintf
(
meta
,
"driver = %s
\n
"
,
sdi
->
driver
->
name
);
fprintf
(
meta
,
"device mode = %d
\n
"
,
sdi
->
mode
);
}
/* metadata */
fprintf
(
meta
,
"capturefile = data
\n
"
);
fprintf
(
meta
,
"unitsize = %d
\n
"
,
unitsize
);
fprintf
(
meta
,
"total samples = %d
\n
"
,
units
);
fprintf
(
meta
,
"total probes = %d
\n
"
,
g_slist_length
(
sdi
->
channels
));
if
(
sr_dev_has_option
(
sdi
,
SR_CONF_SAMPLERATE
))
{
if
(
sr_config_get
(
sdi
->
driver
,
sdi
,
NULL
,
NULL
,
SR_CONF_SAMPLERATE
,
&
gvar
)
==
SR_OK
)
{
samplerate
=
g_variant_get_uint64
(
gvar
);
s
=
sr_samplerate_string
(
samplerate
);
fprintf
(
meta
,
"samplerate = %s
\n
"
,
s
);
g_free
(
s
);
g_variant_unref
(
gvar
);
}
if
(
sr_config_get
(
sdi
->
driver
,
sdi
,
NULL
,
NULL
,
SR_CONF_SAMPLERATE
,
&
gvar
)
==
SR_OK
)
{
samplerate
=
g_variant_get_uint64
(
gvar
);
s
=
sr_samplerate_string
(
samplerate
);
fprintf
(
meta
,
"samplerate = %s
\n
"
,
s
);
g_free
(
s
);
g_variant_unref
(
gvar
);
}
if
(
sdi
->
mode
==
DSO
&&
sr_config_get
(
sdi
->
driver
,
sdi
,
NULL
,
NULL
,
SR_CONF_TIMEBASE
,
&
gvar
)
==
SR_OK
)
{
timeBase
=
g_variant_get_uint64
(
gvar
);
fprintf
(
meta
,
"hDiv = %d
\n
"
,
timeBase
);
g_variant_unref
(
gvar
);
}
probecnt
=
1
;
for
(
l
=
sdi
->
channels
;
l
;
l
=
l
->
next
)
{
probe
=
l
->
data
;
if
(
probe
->
enabled
)
{
if
(
probe
->
enabled
||
sdi
->
mode
==
DSO
)
{
if
(
probe
->
name
)
fprintf
(
meta
,
"probe%d = %s
\n
"
,
probe
->
index
,
probe
->
name
);
if
(
probe
->
trigger
)
fprintf
(
meta
,
" trigger%d = %s
\n
"
,
probe
->
index
,
probe
->
trigger
);
if
(
sdi
->
mode
==
DSO
)
{
fprintf
(
meta
,
" enable%d = %d
\n
"
,
probe
->
index
,
probe
->
enabled
);
fprintf
(
meta
,
" coupling%d = %d
\n
"
,
probe
->
index
,
probe
->
coupling
);
fprintf
(
meta
,
" vDiv%d = %d
\n
"
,
probe
->
index
,
probe
->
vdiv
);
fprintf
(
meta
,
" vFactor%d = %d
\n
"
,
probe
->
index
,
probe
->
vfactor
);
fprintf
(
meta
,
" vPos%d = %lf
\n
"
,
probe
->
index
,
probe
->
vpos
);
if
(
sr_status_get
(
sdi
,
&
status
,
0
,
0
)
==
SR_OK
)
{
if
(
probe
->
index
==
0
)
{
fprintf
(
meta
,
" period%d = %d
\n
"
,
probe
->
index
,
status
.
ch0_period
);
fprintf
(
meta
,
" pcnt%d = %d
\n
"
,
probe
->
index
,
status
.
ch0_pcnt
);
fprintf
(
meta
,
" max%d = %d
\n
"
,
probe
->
index
,
status
.
ch0_max
);
fprintf
(
meta
,
" min%d = %d
\n
"
,
probe
->
index
,
status
.
ch0_min
);
}
else
{
fprintf
(
meta
,
" period%d = %d
\n
"
,
probe
->
index
,
status
.
ch1_period
);
fprintf
(
meta
,
" pcnt%d = %d
\n
"
,
probe
->
index
,
status
.
ch1_pcnt
);
fprintf
(
meta
,
" max%d = %d
\n
"
,
probe
->
index
,
status
.
ch1_max
);
fprintf
(
meta
,
" min%d = %d
\n
"
,
probe
->
index
,
status
.
ch1_min
);
}
}
}
probecnt
++
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment