Skip to content

Commit 9c4f151

Browse files
author
Bartosz Grabias
committed
Added support for mat file compression
1 parent 0148a29 commit 9c4f151

17 files changed

+820
-260
lines changed

.clang-format

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: false
7+
AlignConsecutiveAssignments: false
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: Right
10+
AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllArgumentsOnNextLine: true
13+
AllowAllConstructorInitializersOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: true
15+
AllowShortBlocksOnASingleLine: Never
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: All
18+
AllowShortLambdasOnASingleLine: All
19+
AllowShortIfStatementsOnASingleLine: Never
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterDefinitionReturnType: None
22+
AlwaysBreakAfterReturnType: None
23+
AlwaysBreakBeforeMultilineStrings: false
24+
AlwaysBreakTemplateDeclarations: MultiLine
25+
BinPackArguments: true
26+
BinPackParameters: true
27+
BraceWrapping:
28+
AfterCaseLabel: false
29+
AfterClass: true
30+
AfterControlStatement: true
31+
AfterEnum: true
32+
AfterFunction: true
33+
AfterNamespace: true
34+
AfterObjCDeclaration: false
35+
AfterStruct: true
36+
AfterUnion: true
37+
AfterExternBlock: true
38+
BeforeCatch: true
39+
BeforeElse: true
40+
IndentBraces: false
41+
SplitEmptyFunction: true
42+
SplitEmptyRecord: true
43+
SplitEmptyNamespace: true
44+
BreakBeforeBinaryOperators: None
45+
BreakBeforeBraces: Custom
46+
BreakBeforeInheritanceComma: false
47+
BreakInheritanceList: BeforeColon
48+
BreakBeforeTernaryOperators: true
49+
BreakConstructorInitializersBeforeComma: false
50+
BreakConstructorInitializers: BeforeColon
51+
BreakAfterJavaFieldAnnotations: false
52+
BreakStringLiterals: true
53+
ColumnLimit: 120
54+
CommentPragmas: '^ IWYU pragma:'
55+
CompactNamespaces: false
56+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
57+
ConstructorInitializerIndentWidth: 4
58+
ContinuationIndentWidth: 4
59+
Cpp11BracedListStyle: true
60+
DeriveLineEnding: true
61+
DerivePointerAlignment: false
62+
DisableFormat: false
63+
ExperimentalAutoDetectBinPacking: false
64+
FixNamespaceComments: true
65+
ForEachMacros:
66+
- foreach
67+
- Q_FOREACH
68+
- BOOST_FOREACH
69+
IncludeBlocks: Preserve
70+
IncludeCategories:
71+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
72+
Priority: 2
73+
SortPriority: 0
74+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
75+
Priority: 3
76+
SortPriority: 0
77+
- Regex: '.*'
78+
Priority: 1
79+
SortPriority: 0
80+
IncludeIsMainRegex: '(Test)?$'
81+
IncludeIsMainSourceRegex: ''
82+
IndentCaseLabels: false
83+
IndentGotoLabels: true
84+
IndentPPDirectives: None
85+
IndentWidth: 4
86+
IndentWrappedFunctionNames: false
87+
JavaScriptQuotes: Leave
88+
JavaScriptWrapImports: true
89+
KeepEmptyLinesAtTheStartOfBlocks: true
90+
MacroBlockBegin: ''
91+
MacroBlockEnd: ''
92+
MaxEmptyLinesToKeep: 1
93+
NamespaceIndentation: All
94+
ObjCBinPackProtocolList: Auto
95+
ObjCBlockIndentWidth: 2
96+
ObjCSpaceAfterProperty: false
97+
ObjCSpaceBeforeProtocolList: true
98+
PenaltyBreakAssignment: 2
99+
PenaltyBreakBeforeFirstCallParameter: 19
100+
PenaltyBreakComment: 300
101+
PenaltyBreakFirstLessLess: 120
102+
PenaltyBreakString: 1000
103+
PenaltyBreakTemplateDeclaration: 10
104+
PenaltyExcessCharacter: 1000000
105+
PenaltyReturnTypeOnItsOwnLine: 60
106+
PointerAlignment: Right
107+
ReflowComments: true
108+
SortIncludes: true
109+
SortUsingDeclarations: true
110+
SpaceAfterCStyleCast: false
111+
SpaceAfterLogicalNot: false
112+
SpaceAfterTemplateKeyword: true
113+
SpaceBeforeAssignmentOperators: true
114+
SpaceBeforeCpp11BracedList: false
115+
SpaceBeforeCtorInitializerColon: true
116+
SpaceBeforeInheritanceColon: true
117+
SpaceBeforeParens: ControlStatements
118+
SpaceBeforeRangeBasedForLoopColon: true
119+
SpaceInEmptyBlock: false
120+
SpaceInEmptyParentheses: false
121+
SpacesBeforeTrailingComments: 1
122+
SpacesInAngles: false
123+
SpacesInConditionalStatement: false
124+
SpacesInContainerLiterals: true
125+
SpacesInCStyleCastParentheses: false
126+
SpacesInParentheses: false
127+
SpacesInSquareBrackets: false
128+
SpaceBeforeSquareBrackets: false
129+
Standard: Latest
130+
StatementMacros:
131+
- Q_UNUSED
132+
- QT_REQUIRE_VERSION
133+
TabWidth: 8
134+
UseCRLF: false
135+
UseTab: Never
136+
...
137+

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
cmake_minimum_required(VERSION 3.1)
2+
23
project (scope_receiver)
34

5+
find_package(ZLIB REQUIRED)
6+
7+
set(CXXOPTS_BUILD_EXAMPLES no)
8+
set(SPDLOG_BUILD_EXAMPLE no)
49
set(CMAKE_CXX_STANDARD 17)
510

611
add_subdirectory(spdlog)
@@ -10,6 +15,9 @@ add_subdirectory(cxxopts)
1015
add_executable(scope_receiver
1116
src/main.cpp
1217
src/mat_writer.cpp
18+
src/mat_writer_compressed.cpp
1319
)
1420

15-
target_link_libraries(scope_receiver librigol spdlog cxxopts)
21+
set_target_properties(scope_receiver PROPERTIES CXX_STANDARD 17)
22+
target_include_directories(scope_receiver PRIVATE ${ZLIB_INCLUDE_DIRS})
23+
target_link_libraries(scope_receiver librigol spdlog cxxopts ${ZLIB_LIBRARIES})

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ Run: `./scope_receiver`
2525

2626
TODO...
2727
For now please run `scope_receiver -h`
28+
29+
# Others
30+
31+
Mat file format documentation: https://pub.ist.ac.at/~schloegl/matlab/matfile_format.pdf

librigol/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_library(librigol
77
src/scpi_command.cpp
88
)
99

10+
set_target_properties(librigol PROPERTIES CXX_STANDARD 17)
1011
target_include_directories(librigol PUBLIC include/)
1112
target_link_libraries(librigol spdlog)
1213

librigol/include/connection.h

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <cstdint>
43
#include <cstddef>
4+
#include <cstdint>
55
#include <string>
66

77
#ifdef __WIN32__
@@ -12,21 +12,22 @@ namespace rigol
1212
{
1313
class connection
1414
{
15-
private:
16-
connection(const connection&) = delete;
17-
connection& operator=(const connection&) = delete;
15+
private:
16+
connection(const connection &) = delete;
17+
connection &operator=(const connection &) = delete;
1818

19-
protected:
20-
connection() {};
19+
protected:
20+
connection(){};
2121

22-
virtual std::size_t read(std::uint8_t* buffer, std::size_t max_len) = 0;
23-
virtual std::size_t write(const std::uint8_t* buffer, std::size_t max_len) = 0;
24-
public:
25-
virtual ~connection() {};
22+
virtual std::size_t read(std::uint8_t *buffer, std::size_t max_len) = 0;
23+
virtual std::size_t write(const std::uint8_t *buffer, std::size_t max_len) = 0;
2624

27-
void write(const std::string& s);
28-
void read_line(std::string& out);
29-
void read(std::string& out, size_t count);
25+
public:
26+
virtual ~connection(){};
27+
28+
void write(const std::string &s);
29+
void read_line(std::string &out);
30+
void read(std::string &out, size_t count);
3031
std::string read_line();
3132
};
3233

@@ -37,12 +38,12 @@ namespace rigol
3738
#else
3839
int m_fd;
3940
#endif
40-
public:
41-
tcp_connection(const std::string& address, std::uint16_t port);
41+
public:
42+
tcp_connection(const std::string &address, std::uint16_t port);
4243
~tcp_connection();
43-
44-
protected:
45-
std::size_t read(std::uint8_t* buffer, std::size_t max_len) override;
46-
std::size_t write(const std::uint8_t* buffer, std::size_t max_len) override;
44+
45+
protected:
46+
std::size_t read(std::uint8_t *buffer, std::size_t max_len) override;
47+
std::size_t write(const std::uint8_t *buffer, std::size_t max_len) override;
4748
};
48-
}
49+
} // namespace rigol

librigol/include/scope.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3+
#include "connection.h"
34
#include <memory>
4-
#include <vector>
55
#include <ostream>
6-
#include "connection.h"
6+
#include <vector>
77

88
namespace rigol
99
{
@@ -24,14 +24,22 @@ namespace rigol
2424
CHANNEL_4,
2525
};
2626

27-
inline std::ostream& operator<<(std::ostream& str, channel ch)
27+
inline std::ostream &operator<<(std::ostream &str, channel ch)
2828
{
2929
switch (ch)
3030
{
31-
case channel::CHANNEL_1: str << "CHANNEL_1"; return str;
32-
case channel::CHANNEL_2: str << "CHANNEL_2"; return str;
33-
case channel::CHANNEL_3: str << "CHANNEL_3"; return str;
34-
case channel::CHANNEL_4: str << "CHANNEL_4"; return str;
31+
case channel::CHANNEL_1:
32+
str << "CHANNEL_1";
33+
return str;
34+
case channel::CHANNEL_2:
35+
str << "CHANNEL_2";
36+
return str;
37+
case channel::CHANNEL_3:
38+
str << "CHANNEL_3";
39+
return str;
40+
case channel::CHANNEL_4:
41+
str << "CHANNEL_4";
42+
return str;
3543
}
3644
str << "Unknown channel";
3745
return str;
@@ -40,9 +48,10 @@ namespace rigol
4048
class scope
4149
{
4250
std::unique_ptr<connection> m_connection;
43-
public:
44-
scope(std::unique_ptr<connection>&& connection);
45-
51+
52+
public:
53+
scope(std::unique_ptr<connection> &&connection);
54+
4655
void run();
4756
void stop();
4857
void single();
@@ -51,8 +60,8 @@ namespace rigol
5160

5261
void select_channel(channel ch);
5362

54-
void read_buffer(std::vector<float>& buffer);
55-
void read_buffer(std::vector<uint8_t>& buffer);
63+
void read_buffer(std::vector<float> &buffer);
64+
void read_buffer(std::vector<uint8_t> &buffer);
5665

5766
double x_origin();
5867
double x_increment();
@@ -61,4 +70,4 @@ namespace rigol
6170
double y_increment();
6271
double y_reference();
6372
};
64-
}
73+
} // namespace rigol

librigol/include/scpi_command.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
#pragma once
22

3-
#include <string>
43
#include <initializer_list>
4+
#include <string>
55

66
namespace rigol
77
{
88
class connection;
99

1010
class scpi_command
1111
{
12-
protected:
13-
scpi_command() {};
12+
protected:
13+
scpi_command(){};
1414

15-
public:
16-
virtual ~scpi_command() {};
15+
public:
16+
virtual ~scpi_command(){};
1717

18-
virtual void run_on(connection& connection) = 0;
18+
virtual void run_on(connection &connection) = 0;
1919
};
2020

2121
class no_response_scpi_command : public scpi_command
2222
{
2323
std::string m_command;
24-
public:
25-
no_response_scpi_command(const std::string& command);
26-
no_response_scpi_command(const std::initializer_list<std::string>& parts, const std::string& args = {});
2724

28-
void run_on(connection& connection) override;
25+
public:
26+
no_response_scpi_command(const std::string &command);
27+
no_response_scpi_command(const std::initializer_list<std::string> &parts, const std::string &args = {});
28+
29+
void run_on(connection &connection) override;
2930
};
3031

3132
class text_query_scpi_command : public scpi_command
3233
{
3334
std::string m_command;
3435
std::string m_last_response;
35-
public:
36-
text_query_scpi_command(const std::string& command);
37-
text_query_scpi_command(const std::initializer_list<std::string>& parts);
3836

39-
void run_on(connection& connection) override;
40-
const std::string& last_response() const { return m_last_response; };
37+
public:
38+
text_query_scpi_command(const std::string &command);
39+
text_query_scpi_command(const std::initializer_list<std::string> &parts);
40+
41+
void run_on(connection &connection) override;
42+
const std::string &last_response() const { return m_last_response; };
4143
};
42-
}
44+
} // namespace rigol

0 commit comments

Comments
 (0)