Skip to content

Commit

Permalink
-unsignedHex switch added
Browse files Browse the repository at this point in the history
  • Loading branch information
rokath committed Feb 19, 2021
1 parent b66d6a5 commit db8e9a4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/args/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Works not perfect with windows, because of cmd and powershell color issues and m
Example: "trice l -port COM38 -displayserver -autostart" opens a separate display window automatically on the same PC.
`+boolInfo)

fsScLog.BoolVar(&decoder.UnsignedHex, "unsignedHex", false, "Hex and Bin values are printed as unsigned values.")
fsScLog.BoolVar(&decoder.UnsignedHex, "u", false, "Short for '-unsignedHex'.")
fsScLog.BoolVar(&emitter.Autostart, "a", false, "Short for '-autostart'.")
fsScLog.BoolVar(&receiver.ShowInputBytes, "showInputBytes", false, `Show incoming bytes, what can be helpful during setup.
`+boolInfo)
Expand Down
8 changes: 8 additions & 0 deletions internal/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const (
// patNextFormatSpezifier is a regex to find next format u specifier in a string
// It does also match %%u positions! so an additional check must follow.
patNextFormatUSpezifier = `(?:%[0-9]*u)`

// patNextFormatSpezifier is a regex to find next format u specifier in a string
// It does also match %%u positions! so an additional check must follow.
patNextFormatXSpezifier = `(?:%[0-9]*(x|X|b))`
)

var (
Expand All @@ -49,8 +53,12 @@ var (
// TestTableMode is a special option for easy decoder test table generation.
TestTableMode bool

// UnsignedHex if true, forces hex and in values printed as unsigned values.
UnsignedHex bool

matchNextFormatSpezifier = regexp.MustCompile(patNextFormatSpezifier)
matchNextFormatUSpezifier = regexp.MustCompile(patNextFormatUSpezifier)
matchNextFormatXSpezifier = regexp.MustCompile(patNextFormatXSpezifier)
)

// newDecoder abstracts the function type for a new decoder.
Expand Down
5 changes: 4 additions & 1 deletion internal/decoder/pack2Decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func uReplaceN(i string) (o string, u []bool) {
offset += loc[1] // track position
fm := s[loc[0]:loc[1]]
locU := matchNextFormatUSpezifier.FindStringIndex(fm)
locX := matchNextFormatXSpezifier.FindStringIndex(fm)
if nil != locU { // a %nu found
//if 0 < loc[0] { // not at string start, so check for %%
// x := s[loc[0]-1 : loc[0]]
Expand All @@ -551,7 +552,9 @@ func uReplaceN(i string) (o string, u []bool) {
//}
o = o[:offset-1] + "d" + o[offset:] // replace %nu -> %nd
u = append(u, true)
} else {
} else if nil != locX && UnsignedHex { // a %nx or %nX or %nb found
u = append(u, true) // no negative values
} else { // keep sign
u = append(u, false)
}
s = i[offset:] // remove processed part
Expand Down
5 changes: 4 additions & 1 deletion srcTrice.C/triceCheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ void triceCheckSetTime(int index) {
break;
case 20:
#if TRICE_ENCODING == TRICE_PACK2_ENCODING
TRICE8_1(Id(52174), "tst:TRICE8_1 %02x\n", 0xe0);
TRICE8_8(Id( 579), "tst:TRICE8_1 %%d=%d, %%u=%u, 0x%%x=0x%x, 0x%%2x=0x%2x, 0x%%02x=0x%02x, 0x%%3x=0x%3x, 0x%%03x=0x%03x, %%b=%b\n", 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81);
TRICE16_1(Id(21394), "tst:TRICE16_1 0x%04x\n", 0xa0);
TRICE8_1(Id(21201), "tst:TRICE8_1 0x%02x\n", 0xa0);
TRICE8_1(Id(21201), "tst:TRICE8_1 0x%02x\n", 0xa0);
TRICE8_1(Id(32742), "tst:TRICE8_1 %u\n", 201);
TRICE8_2(Id( 7473), "tst:TRICE8_2 %u %u\n", 201, 202);
TRICE8_3(Id(14014), "tst:TRICE8_3 %u %u %u\n", 201, 202, 203);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<TargetName>MDK-ARM_LL_UART_RTT0_PACK_STM32F030R8-NUCLEO-64</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060960::V5.06 update 7 (build 960)::ARMCC</pCCUsed>
<pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
Expand Down
12 changes: 12 additions & 0 deletions til.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
"Type": "TRICE0",
"Strg": "s: \\ns: ARM-MDK_LL_UART_BARE_TO_ESC_NUCLEO-F070RB \\ns: \\n\\n"
},
"21201": {
"Type": "TRICE8_1",
"Strg": "tst:TRICE8_1 0x%02x\\n"
},
"21394": {
"Type": "TRICE16_1",
"Strg": "tst:TRICE16_1 0x%04x\\n"
},
"22722": {
"Type": "TRICE0",
"Strg": "s: \\ns: ARM-MDK_BARE_STM32F03051R8Tx-DISCOVERY \\ns: \\n\\n"
Expand Down Expand Up @@ -303,6 +311,10 @@
"Type": "TRICE8_7",
"Strg": "tst:TRICE8_7 %u %u %u %u %u %u %u\\n"
},
"579": {
"Type": "TRICE8_8",
"Strg": "tst:TRICE8_1 %%d=%d, %%u=%u, 0x%%x=0x%x, 0x%%2x=0x%2x, 0x%%02x=0x%02x, 0x%%3x=0x%3x, 0x%%03x=0x%03x, %%b=%b\\n"
},
"59229": {
"Type": "TRICE32_3",
"Strg": "tst:TRICE32_3 %u %u %u\\n"
Expand Down

0 comments on commit db8e9a4

Please sign in to comment.