Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RISE
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-RISE
Commits
a99c6e9f
Commit
a99c6e9f
authored
May 22, 2022
by
lfq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove logs
parent
27f7d059
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
src/utils/hex_string_convert.cpp
src/utils/hex_string_convert.cpp
+10
-10
No files found.
src/utils/hex_string_convert.cpp
View file @
a99c6e9f
...
@@ -14,10 +14,10 @@ void convert_string_2_hex(std::string& input_str, std::string& output_str)
...
@@ -14,10 +14,10 @@ void convert_string_2_hex(std::string& input_str, std::string& output_str)
memset
(
data
,
0
,
input_str
.
length
()
+
1
);
memset
(
data
,
0
,
input_str
.
length
()
+
1
);
memcpy
((
void
*
)
data
,
(
void
*
)
input_str
.
c_str
(),
input_str
.
length
());
memcpy
((
void
*
)
data
,
(
void
*
)
input_str
.
c_str
(),
input_str
.
length
());
for
(
int
i
=
0
;
i
<
input_str
.
length
();
i
++
)
{
//
for (int i = 0; i < input_str.length(); i++) {
printf
(
"%02x "
,
data
[
i
]);
//
printf("%02x ", data[i]);
}
//
}
printf
(
"
\n
"
);
//
printf("\n");
char
*
datahex
=
(
char
*
)
malloc
(
input_str
.
length
()
*
2
+
1
);
char
*
datahex
=
(
char
*
)
malloc
(
input_str
.
length
()
*
2
+
1
);
memset
(
datahex
,
0
,
input_str
.
length
()
*
2
+
1
);
memset
(
datahex
,
0
,
input_str
.
length
()
*
2
+
1
);
...
@@ -37,9 +37,9 @@ unsigned char * format_string_as_hex(std::string str){
...
@@ -37,9 +37,9 @@ unsigned char * format_string_as_hex(std::string str){
memcpy
((
void
*
)
data
,
(
void
*
)
str
.
c_str
(),
str_len
);
memcpy
((
void
*
)
data
,
(
void
*
)
str
.
c_str
(),
str_len
);
std
::
cout
<<
"Data: "
<<
data
<<
" ("
<<
str_len
<<
" bytes)"
<<
std
::
endl
;
//
std::cout << "Data: " << data << " (" << str_len <<" bytes)" <<std::endl;
std
::
cout
<<
"Data (formatted):
\n
"
;
//
std::cout <<"Data (formatted): \n";
for
(
int
i
=
0
;
i
<
str_len
;
i
++
)
for
(
int
i
=
0
;
i
<
str_len
;
i
++
)
{
{
char
datatmp
[
3
]
=
{
0
};
char
datatmp
[
3
]
=
{
0
};
...
@@ -57,14 +57,14 @@ unsigned char * format_string_as_hex(std::string str){
...
@@ -57,14 +57,14 @@ unsigned char * format_string_as_hex(std::string str){
// Convert two hexadecimal characters into one character
// Convert two hexadecimal characters into one character
unsigned
int
nAsciiCharacter
;
unsigned
int
nAsciiCharacter
;
sscanf
(
datatmp
,
"%x"
,
&
nAsciiCharacter
);
sscanf
(
datatmp
,
"%x"
,
&
nAsciiCharacter
);
printf
(
"%x "
,
nAsciiCharacter
);
//
printf("%x ",nAsciiCharacter);
// Concatenate this character onto the output
// Concatenate this character onto the output
datavalue
[
i
/
2
]
=
(
unsigned
char
)
nAsciiCharacter
;
datavalue
[
i
/
2
]
=
(
unsigned
char
)
nAsciiCharacter
;
// Skip the next character
// Skip the next character
i
++
;
i
++
;
}
}
printf
(
"
\n
"
);
//
printf("\n");
free_wrapper
((
void
**
)
&
data
);
free_wrapper
((
void
**
)
&
data
);
return
datavalue
;
return
datavalue
;
...
@@ -83,12 +83,12 @@ char* bstring2charString(bstring b){
...
@@ -83,12 +83,12 @@ char* bstring2charString(bstring b){
void
msg_str_2_msg_hex
(
std
::
string
msg
,
bstring
&
b
){
void
msg_str_2_msg_hex
(
std
::
string
msg
,
bstring
&
b
){
std
::
string
msg_hex_str
;
std
::
string
msg_hex_str
;
convert_string_2_hex
(
msg
,
msg_hex_str
);
convert_string_2_hex
(
msg
,
msg_hex_str
);
printf
(
"tmp string: %s
\n
"
,
msg_hex_str
.
c_str
());
//
printf("tmp string: %s\n", msg_hex_str.c_str());
unsigned
int
msg_len
=
msg_hex_str
.
length
();
unsigned
int
msg_len
=
msg_hex_str
.
length
();
char
*
data
=
(
char
*
)
malloc
(
msg_len
+
1
);
char
*
data
=
(
char
*
)
malloc
(
msg_len
+
1
);
memset
(
data
,
0
,
msg_len
+
1
);
memset
(
data
,
0
,
msg_len
+
1
);
memcpy
((
void
*
)
data
,
(
void
*
)
msg_hex_str
.
c_str
(),
msg_len
);
memcpy
((
void
*
)
data
,
(
void
*
)
msg_hex_str
.
c_str
(),
msg_len
);
printf
(
"data: %s
\n
"
,
data
);
//
printf("data: %s\n", data);
uint8_t
*
msg_hex
=
(
uint8_t
*
)
malloc
(
msg_len
/
2
+
1
);
uint8_t
*
msg_hex
=
(
uint8_t
*
)
malloc
(
msg_len
/
2
+
1
);
conv
::
ascii_to_hex
(
msg_hex
,
(
const
char
*
)
data
);
conv
::
ascii_to_hex
(
msg_hex
,
(
const
char
*
)
data
);
b
=
blk2bstr
(
msg_hex
,
(
msg_len
/
2
));
b
=
blk2bstr
(
msg_hex
,
(
msg_len
/
2
));
...
...
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