Skip to content

Commit 0e19890

Browse files
committed
mapping template (yaml)
1 parent 11fd8d4 commit 0e19890

File tree

4 files changed

+371
-107
lines changed

4 files changed

+371
-107
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ what works in general (on RevE-Rebooted & RevG):
1212
- implementation of crc16 / BCC
1313
- display RSSI
1414
- integration of mfkey32v2 (RevE-Rebooted - workaround with binary)
15+
- diff/edit Dump-/Slot-Data
1516

1617
what is missing:
1718
- logmode=live (RevG)

config/map.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package config
2+
3+
import (
4+
"gopkg.in/yaml.v2"
5+
"log"
6+
"io/ioutil"
7+
"path/filepath"
8+
"runtime"
9+
)
10+
11+
const MYFAIRE_CLASSIC_1K_4Byte_UID = 0x0400
12+
13+
type TagMap struct {
14+
Name string `yaml:"name"`
15+
Tagtype string `yaml:"tagtype"`
16+
Mappings []ByteMap `yaml:"mappings"`
17+
}
18+
type ByteMap struct {
19+
Start int `yaml:"start"`
20+
End int `yaml:"end"`
21+
MapBytes []MapByte `yaml:"mapbytes"`
22+
MapFuncs []MapFunc `yaml:"mapfuncs"`
23+
}
24+
type MapByte struct {
25+
Pos int `yaml:"pos"`
26+
Color string `yaml:"color"`
27+
Tooltip string `yaml:"tooltip"`
28+
}
29+
type MapFunc struct{
30+
Name string `yaml:"name"`
31+
ExpectResult bool `yaml:"expectresult"`
32+
Result []string `yaml:"result"`
33+
}
34+
35+
var DefaultMap = TagMap{
36+
Name: "Mifare Classic 1K 4Byte UID",
37+
Tagtype: "0400",
38+
Mappings: []ByteMap{
39+
{
40+
Start: 0,
41+
End:3,
42+
MapBytes: []MapByte{
43+
{
44+
Pos: 0,
45+
Color: "yellow",
46+
Tooltip: "UID0",
47+
},
48+
{
49+
Pos: 1,
50+
Color: "yellow",
51+
Tooltip: "UID1",
52+
},
53+
{
54+
Pos: 2,
55+
Color: "yellow",
56+
Tooltip: "UID2",
57+
},
58+
{
59+
Pos: 3,
60+
Color: "yellow",
61+
Tooltip: "UID3",
62+
},
63+
},
64+
},
65+
{
66+
Start: 4,
67+
End:4,
68+
MapBytes: []MapByte{
69+
{
70+
Pos: 0,
71+
Color: "yellow",
72+
Tooltip: "BCC (UID0..UID3)",
73+
},
74+
},
75+
MapFuncs: []MapFunc{
76+
{
77+
Name: "bcc",
78+
ExpectResult: true,
79+
Result: []string{"fc"},
80+
},
81+
},
82+
},
83+
},
84+
}
85+
86+
func (m *TagMap) Save(f string) {
87+
tagmap := Apppath()+string(filepath.Separator)+runtime.GOOS+string(filepath.Separator)+"maps"+string(filepath.Separator)+f
88+
if len(m.Mappings) > 0 {
89+
if data, err := yaml.Marshal(m); err != nil {
90+
log.Printf("error Marshall yaml (%s)\n", err)
91+
} else {
92+
err := ioutil.WriteFile(tagmap, data, 0644)
93+
if err != nil {
94+
log.Print(err)
95+
}
96+
}
97+
}
98+
}
99+
100+
func (c *TagMap) Load(f string) {
101+
tagmap := Apppath()+string(filepath.Separator)+runtime.GOOS+string(filepath.Separator)+"maps"+string(filepath.Separator)+f
102+
//log.Printf("Using configFile: %s\n", configfile)
103+
if len(tagmap) > 0 {
104+
yamlFile, err := ioutil.ReadFile(tagmap)
105+
if err != nil {
106+
log.Printf("error reading config (%s) err #%v ", tagmap, err)
107+
return
108+
}
109+
log.Println("loaded TagMap: ", c.Name)
110+
111+
err = yaml.Unmarshal(yamlFile, c)
112+
if err != nil {
113+
log.Print("Unmarshal: %v", err)
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)