Skip to content

Commit 80100fd

Browse files
authored
Merge pull request #7 from 1138-4EB/decode-array
Added 'jsonGetIntegerArray'.
2 parents b2bbeeb + 00609d2 commit 80100fd

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

Data/Boards0.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
["test",[true,false,18,null,"hello"],3324.34,832432,"world"]
2-
1+
["test",[true,false,18,null,"hello"],[9,8],3324.34,832432,"world"]

Examples/Boards_VUnit.vhdl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ end entity;
1616
architecture tb of tb_boards is
1717
constant JSONContent : T_JSON := jsonLoad(tb_cfg);
1818
constant JSONFileContent : T_JSON := jsonLoad(tb_cfg_file);
19+
constant tb_imga : integer_vector := jsonGetIntegerArray(JSONContent, "2");
1920
begin
2021
main: process
2122
begin
2223
test_runner_setup(runner, runner_cfg);
2324
while test_suite loop
2425
if run("test") then
26+
info("tb_path & tb_cfg_file: " & tb_path & tb_cfg_file);
27+
info("JSONFileContent: " & lf & JSONFileContent.Content);
28+
info("ML505/FPGA: " & jsonGetString(JSONFileContent, "ML505/FPGA"));
29+
info("ML505/Eth/0/PHY-Int: " & jsonGetString(JSONFileContent, "ML505/Eth/0/PHY-Int"));
30+
info("KC705/FPGA: " & jsonGetString(JSONFileContent, "KC705/FPGA"));
31+
info("KC705/IIC/0/Devices/0/Name: " & jsonGetString(JSONFileContent, "KC705/IIC/0/Devices/0/Name"));
32+
2533
info("tb_cfg: " & tb_cfg);
2634
info("JSONContent: " & lf & JSONContent.Content);
27-
info("ML505/FPGA: " & jsonGetString(JSONContent, "ML505/FPGA"));
28-
info("ML505/Eth/0/PHY-Int: " & jsonGetString(JSONContent, "ML505/Eth/0/PHY-Int"));
29-
info("KC705/FPGA: " & jsonGetString(JSONContent, "KC705/FPGA"));
30-
info("KC705/IIC/0/Devices/0/Name: " & jsonGetString(JSONContent, "KC705/IIC/0/Devices/0/Name"));
3135

32-
info("tb_path & tb_cfg_file: " & tb_path & tb_cfg_file);
33-
info("JSONFileContent: " & lf & JSONFileContent.Content);
34-
info("ML505/FPGADevice: " & jsonGetString(JSONFileContent, "ML505/FPGADevice"));
35-
info("ML505/Ethernet/0/PHY_Device: " & jsonGetString(JSONFileContent, "ML505/Ethernet/0/PHY_Device"));
36-
info("KC705/FPGADevice: " & jsonGetString(JSONFileContent, "KC705/FPGADevice"));
37-
info("KC705/IIC/0/Devices/0/Type: " & jsonGetString(JSONFileContent, "KC705/IIC/0/Devices/0/Type"));
36+
info("Integer array length: " & jsonGetString(JSONContent, "2/1"));
37+
for i in 0 to tb_imga'length-1 loop
38+
info("Integer array [" & integer'image(i) & "]: " & integer'image(tb_imga(i)));
39+
end loop;
3840
end if;
3941
end loop;
4042
test_runner_cleanup(runner);

VUnit/run.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
lib = vu.add_library("lib")
1111
lib.add_source_files(join(root, "..", "Examples", "Boards_VUnit.vhdl"))
1212

13-
vu.set_generic('tb_cfg_file', '../Data/Boards2.json')
13+
vu.set_generic('tb_cfg_file', '../Data/Boards1.json')
1414

1515
import json
16-
file = open('../Data/Boards1.json', 'r')
17-
generics = json.loads(file.read())
16+
generics = json.loads(open('../Data/Boards0.json', 'r').read())
1817
vu.set_generic("tb_cfg", json.dumps(generics, separators=(',', ':')))
1918

2019
vu.main()

vhdl/JSON.ctx.vhdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ context json_ctx is
4242
use JSON.json.jsonNoParserError;
4343
use JSON.json.jsonGetErrorMessage;
4444
use JSON.json.jsonGetContent;
45-
use JSON.json.jsonGetString;
4645
use JSON.json.jsonGetBoolean;
46+
use JSON.json.jsonGetString;
47+
use JSON.json.jsonGetIntegerArray;
4748
use JSON.json.jsonIsBoolean;
4849
use JSON.json.jsonIsNull;
4950
use JSON.json.jsonIsString;
5051
use JSON.json.jsonIsNumber;
51-
-- use JSON.json.jsonGetIntArray;
5252
end context;

vhdl/JSON.pkg.vhdl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ package JSON is
103103

104104
function jsonGetBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
105105
function jsonGetString(JSONContext : T_JSON; Path : STRING) return STRING;
106+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector;
107+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string; Len : positive) return integer_vector;
108+
-- function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector;
106109

107110
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
108111
function jsonIsNull(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
@@ -1485,7 +1488,7 @@ package body JSON is
14851488
end if; -- Index = 0
14861489
for j in 1 to Index loop
14871490
if (IndexElement.NextIndex = 0) then
1488-
report "jsonGetElementIndex: Reached last element in chain." severity FAILURE;
1491+
report "jsonGetElementIndex: Reached last element in chain." severity NOTE; --FAILURE
14891492
return 0;
14901493
end if;
14911494
IndexElement := JSONContext.Index(IndexElement.NextIndex);
@@ -1619,6 +1622,26 @@ package body JSON is
16191622
return (Element.ElementType = ELEM_TRUE);
16201623
end function;
16211624

1625+
-- function to get a integer_vector from the compressed content extracted from a JSON input
1626+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector is
1627+
variable len: natural:=0;
1628+
begin
1629+
while jsonIsNumber(JSONContext, Path & "/" & to_string(len)) loop
1630+
len := len+1;
1631+
end loop;
1632+
return jsonGetIntegerArray(JSONContext, Path, len);
1633+
end;
1634+
1635+
-- function to get a integer_vector of a fixed length from the compressed content extracted from a JSON input
1636+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string; Len : positive) return integer_vector is
1637+
variable return_value : integer_vector(Len-1 downto 0);
1638+
begin
1639+
for i in 0 to Len-1 loop
1640+
return_value(i) := to_natural_dec(jsonGetString(JSONContext, Path & "/" & to_string(i)));
1641+
end loop;
1642+
return return_value;
1643+
end function;
1644+
16221645
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN is
16231646
constant ElementIndex : T_UINT16 := jsonGetElementIndex(JSONContext, Path);
16241647
constant Element : T_JSON_INDEX_ELEMENT := JSONContext.Index(ElementIndex);

0 commit comments

Comments
 (0)