This repository was archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.js
172 lines (153 loc) · 4.94 KB
/
simulator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const { spawn } = require('child_process');
const chalk = require('chalk');
const builder = require('xmlbuilder');
const fs = require('fs');
const Store = require('electron-store');
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {}
var store = null;
module.exports = {
child: {},
log: new MyEmitter(),
running: false,
path: '',
setStore: function(s) {
store = s;
},
start: function() {
if (!this.running) {
if (this.path !== '') {
if (process.platform === "win32") {
child = spawn('wvp', [], {
'cwd': this.path + '/bin/'
})
} else {
child = spawn('./wvp_run', [], {
'cwd': this.path + '/wvp_sim/Frameworks/'
})
}
child.stdout.on('data', (data) => {
this.log.emit('new', Utf8ArrayToStr(data));
});
if (child.pid !== null) {
this.running = true
this.log.emit('new', "Simulator sucessfully started");
console.log(chalk.blue('Simulator Started: ') + child.pid)
}
} else {
this.log.emit('new', "No path to simulator currently set! Please set a path.");
}
} else {
console.log(chalk.magenta("Can't run two simulators at once!"))
this.log.emit('new', "Can't run two simulators yet!");
}
},
stop: function() {
child.kill(); // does not terminate the node process in the shell
if (child.killed) {
console.log(chalk.red('Simulator Killed'));
this.running = false
}
},
setPath: function(path) {
this.path = path;
console.log(chalk.magenta('Path Set: ') + this.path)
this.log.emit('new', "New Simulator Path Set: " + this.path);
store.set('path', this.path);
},
saveCurrentAsXML: function(e) {
this.saveJsonToXMLFileAtPath(e, this.path + "/wvp_sim/wvp_9876/sim/simhw.xml")
},
saveJsonToXMLFileAtPath: function(e, path) {
var xml = this.jsonToXML(e);
fs.writeFile(path, xml, function(err) {
if(err) {
return console.log(err);
}
console.log('File written')
});
},
jsonToXML: function(e) {
var xml = builder.create('simhw', {}, {}, {'headless':true})
.ele('frametype', {'type':e.frames[0].frameType}, '').root()
for (var card in e.frames[0].cards) {
if (e.frames[0].cards[card] !== 'x') {
var item = xml.ele('card')
item.att('id', "slot-" + card);
item.att('type', e.frames[0].cards[card]);
item.att('slot', card)
item.txt(cards[e.frames[0].cards[card]])
}
}
for (var l = 0; l < 4; l++) {
var link = e.frames[0].links[l];
if (typeof link == "object") {
if (link.connection.frameType !== null) {
var item = xml.ele('linkinfo')
item.att('selfslot', link.cardId)
item.att('selfconn', link.connectorId)
item.att('detectframetype', link.connection.frameType)
item.att('detectslot', link.connection.frameSlot)
item.att('detectsconn', link.connection.frameConnector)
item.att('detectunitid', link.connection.unitId)
item.att('detectip', link.connection.ipAddress)
if (typeof link.connection.macAddress == "string") {
link.connection.macAddress = link.connection.macAddress.toLowerCase()
}
item.att('detectmac', link.connection.macAddress)
}
}
}
xml = xml.end({ pretty: true, allowEmpty: true});
return xml;
}
}
const cards = {
0: "CardType_Input_2_DVI",
1: "CardType_Input_4_SDI",
2: "CardType_Input_4_HDMI_DP",
3: "CardType_Input_6_TRI_COMBO",
4: "CardType_Input_4_HDMI20",
5: "CardType_Input_4_DP",
20: "CardType_Output_2_DVI",
21: "CardType_Output_4_SDI",
22: "CardType_Output_4_HDMI",
23: "CardType_Output_DP",
25: "CardType_Output_6_TRI_COMBO",
26: "CardType_Output_4_HDMI20",
40: "CardType_Output_Multiviewer",
50: "CardType_VPU",
52: "CardType_VPU",
70: "CardType_Exp"
}
function Utf8ArrayToStr(array) {
var out, i, len, c;
var char2, char3;
out = "";
len = array.length;
i = 0;
while(i < len) {
c = array[i++];
switch(c >> 4)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12: case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}
return out;
}