Skip to content

Commit a9718fd

Browse files
Move connections into kernel
1 parent 6bc5b13 commit a9718fd

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

kernel/src/kernel.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { BaseKernel } from '@jupyterlite/kernel';
22
import { KernelMessage } from '@jupyterlab/services';
33
import { ServiceContainer } from './services/ServiceContainer';
44

5+
const reconnectString: string = "%connect%"
6+
57
export class EmbeddedKernel extends BaseKernel {
68

79
constructor(options: any, private serviceContainer: ServiceContainer) {
@@ -58,6 +60,17 @@ export class EmbeddedKernel extends BaseKernel {
5860
console.log("GOT CODE AT KERNEL LEVEL: ", code);
5961
console.log("Type of CODE AT KERNEL LEVEL: ", typeof code);
6062

63+
console.log('Before reconnect check');
64+
if (code.includes(reconnectString)) {
65+
// Reconnect the device or connect for the first time
66+
console.log('Reconnect command detected, reconnecting device...');
67+
await this.serviceContainer.deviceService.disconnect();
68+
console.log('Device disconnected');
69+
await this.serviceContainer.deviceService.connect();
70+
console.log('Device connected');
71+
}
72+
console.log('After reconnect check');
73+
6174
try {
6275
console.log("[Kernel] executeRequest - Checking transport");
6376
const transport = this.serviceContainer.deviceService.getTransport();

kernel/src/services/DeviceService.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Transport } from 'esptool-js';
22

3-
const reconnectString: string = "%connect%"
4-
53
export class DeviceService {
64
private port: SerialPort | null = null;
75
private transport: Transport | null = null;
@@ -124,17 +122,6 @@ export class DeviceService {
124122
}
125123

126124
async sendCommand(code: string): Promise<boolean> {
127-
console.log('Before reconnect check');
128-
if (code.includes(reconnectString)) {
129-
// Reconnect the device or connect for the first time
130-
console.log('Reconnect command detected, reconnecting device...');
131-
await this.disconnect();
132-
console.log('Device disconnected');
133-
await this.connect();
134-
console.log('Device connected');
135-
}
136-
console.log('After reconnect check');
137-
138125
if (!this.transport || !this.transport.device.writable) {
139126
return false;
140127
}

0 commit comments

Comments
 (0)