Skip to content

Commit 81f633b

Browse files
lego-yawBright-yaw
and
Bright-yaw
authored
Lego yaw patch 1 (#10)
* removing some packages * update to ReadDBC.jl --------- Co-authored-by: Bright-yaw <[email protected]>
1 parent b0b9309 commit 81f633b

6 files changed

+28
-62
lines changed

Project.toml

+4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ authors = ["Bright-yaw <[email protected]> and contributors"]
44
version = "1.0.0"
55

66
[deps]
7+
DBCtoDBF_jll = "404e8f35-d372-56c3-89ac-e648a26fddda"
78
DBFTables = "75c7ada1-017a-5fb6-b8c7-2125ff2d6c93"
89
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
910
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
11+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
12+
1013

1114
[compat]
1215
DBFTables = "1.2.6"
1316
DataFrames = "1.6.1"
1417
Documenter = "1.6.0"
1518
julia = "1.10.4"
19+
DBCtoDBF_jll = "v1.0.0"
1620

1721
[extras]
1822
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/ReadDBC.jl

+8-28
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,21 @@ export dbcTable, dbctodbf
66
# Importing packages
77
using DBFTables
88
using DataFrames
9-
using Base.Libc.Libdl
10-
using Base.Filesystem
9+
using DBCtoDBF_jll
1110

1211

13-
# Defining function dbctodbf
14-
function dbctodbf(input_file::String, output_file::String)
15-
# Set path for .dll files
16-
lib_path = "src/libdbc2dbf.dll"
17-
# Change permissions on the file before loading (optional and platform-dependent)
18-
chmod(lib_path, 0o755)
1912

20-
# Load the shared library
21-
lib = dlopen(lib_path)
22-
23-
# Ensure the library is properly loaded
24-
if lib === C_NULL
25-
error("Failed to load the library.")
26-
end
2713

28-
# Create a pointer to the C function in the library
29-
func = dlsym(lib, :dbc2dbf)
30-
31-
# Ensure the function pointer is valid
32-
if func === C_NULL
33-
dlclose(lib)
34-
error("Failed to find the function dbc2dbf in the library.")
35-
end
3614

37-
# Call the C function directly with string parameters
38-
result = ccall(func, Cvoid, (Cstring, Cstring), input_file, output_file)
15+
# Defining function dbctodbf
16+
function dbctodbf(input_file::String, output_file::String)
17+
# The DBCtoDBF_jll package provides the dbc2dbf executable directly
18+
exe_path = dbc2dbf() # This gives the path to the dbc2dbf executable
3919

40-
# Close the library after the function call
41-
dlclose(lib)
20+
# Run the executable with the input and output file arguments
21+
run(`$exe_path $input_file $output_file`)
4222

43-
return result
23+
return output_file # Optionally return the output file name
4424
end
4525

4626
# Defining function readdbc

src/ccall_dbftodbc.jl

+12-31
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
#using Libdl
2-
using Base.Filesystem
3-
using Base.Libc.Libdl
1+
using DBCtoDBF_jll # Load the DBCtoDBF_jll wrapper
42

5-
function dbctodbf(input_file::String, output_file::String)
6-
7-
# Set path for .dll files
8-
lib_path = "src/libdbc2dbf.dll"
9-
# Change permissions on the file before loading (optional and platform-dependent)
10-
chmod(lib_path, 0o755)
113

12-
# Load the shared library
13-
lib = dlopen(lib_path)
14-
15-
# Ensure the library is properly loaded
16-
if lib === C_NULL
17-
error("Failed to load the library.")
18-
end
4+
function dbctodbf(input_file::String, output_file::String)
5+
# The DBCtoDBF_jll package provides the dbc2dbf executable directly
6+
exe_path = dbc2dbf() # This gives the path to the dbc2dbf executable
197

20-
# Create a pointer to the C function in the library
21-
func = dlsym(lib, :dbc2dbf)
8+
# Run the executable with the input and output file arguments
9+
run(`$exe_path $input_file $output_file`)
2210

23-
# Ensure the function pointer is valid
24-
if func === C_NULL
25-
dlclose(lib)
26-
error("Failed to find the function dbc2dbf in the library.")
27-
end
11+
return output_file # Optionally return the output file name
12+
end
2813

29-
# Call the C function directly with string parameters
30-
result = ccall(func, Cvoid, (Cstring, Cstring), input_file, output_file)
31-
32-
# Close the library after the function call
33-
dlclose(lib)
34-
35-
return result
36-
end
14+
# Example usage
15+
input_file = "src/ABOAC1909.dbc"
16+
output_file = "src/ABOAC1909.dbf"
17+
dbctodbf(input_file, output_file)

src/how_to_use.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
using ReadDBC
1+
using .ReadDBC
22

33
df = dbcTable("src/ABOAC1909.dbc")

src/libdbc2dbf.dll

-75 KB
Binary file not shown.

test/runtests.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using Test
2-
using ReadDBC
2+
using .ReadDBC
33
using DataFrames
44

5+
56
# Test the dbctodbf function
67
@testset "ReadDBC Tests" begin
78
# Set up file paths
89
input_file = "src/ABOAC1909.dbc"
9-
output_file = "src/ABOAC1909.dbf"
10+
output_file = "src/ABOAC1909.dbf"
1011

1112
# Call the dbctodbf function
1213
result = dbctodbf(input_file, output_file)

0 commit comments

Comments
 (0)