()
| 413 | } |
| 414 | |
| 415 | public tclStartSocket(): Promise<void> { |
| 416 | if (this.tclSocket) { |
| 417 | return Promise.resolve(); |
| 418 | } |
| 419 | return new Promise<void>(async (resolve, reject) => { |
| 420 | if (this.tclSocket === undefined) { |
| 421 | const tclPortName = createPortName(0, 'tclPort'); |
| 422 | const tclPortNum = this.ports[tclPortName]; |
| 423 | const obj = { |
| 424 | host: 'localhost', |
| 425 | port: tclPortNum |
| 426 | }; |
| 427 | this.tclSocket = net.createConnection(obj, () => { |
| 428 | resolve(); |
| 429 | }); |
| 430 | this.tclSocket.on('data', this.tclRecvTclData.bind(this)); |
| 431 | this.tclSocket.on('end', () => { |
| 432 | this.tclSocket = null; |
| 433 | }); |
| 434 | this.tclSocket.on('close', () => { |
| 435 | this.tclSocket = null; |
| 436 | }); |
| 437 | this.tclSocket.on('error', (e) => { |
| 438 | if (this.tclSocket) { |
| 439 | this.tclSocket = null; |
| 440 | reject(e); |
| 441 | } |
| 442 | }); |
| 443 | } else { |
| 444 | reject(new Error('OpenOCD tcl socket already closed')); |
| 445 | } |
| 446 | }); |
| 447 | } |
| 448 | |
| 449 | private tclRecvTclData(buffer: Buffer) { |
| 450 | const str = this.tclSocketBuf + buffer.toString('utf8'); |
no test coverage detected