Skip to content

Commit

Permalink
Load device configuration from server
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed Feb 21, 2023
1 parent f37fb99 commit 1c669c1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/app/components/testrunner/testrunner.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class TestrunnerComponent implements OnInit {
ngOnInit(): void {
this.deviceId = this.route.snapshot.paramMap.get("deviceId")!;
console.log("deviceId: ", this.deviceId);
this.deviceConfiguration = this.deviceConfigurationService.getDeviceConfigurationById(this.deviceId)!;
this.deviceConfigurationService.getDeviceConfigurationById(this.deviceId).then(configuration => {
this.deviceConfiguration = configuration!;
})
this.espPortService.portStateStream.subscribe(isConnected => {
console.log("isConnected: ", isConnected);
this.connected = isConnected;
Expand Down
11 changes: 9 additions & 2 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ export class HomeComponent implements OnInit {
constructor(public deviceConfigurationService: DeviceConfigurationService) {

}

ngOnInit(): void {
this.deviceConfigurations = this.deviceConfigurationService.getDeviceConfigurations();
this.loadConfiguration();
this.deviceConfigurationService.deviceConfigurationStream.subscribe((id) => {
this.deviceConfigurations = this.deviceConfigurationService.getDeviceConfigurations();
this.loadConfiguration();
});
}

loadConfiguration() {
this.deviceConfigurationService.getDeviceConfigurations().then((configuration) => {
this.deviceConfigurations = configuration;
})
}

deleteDevice(id: string) {
this.deviceConfigurationService.deleteLocalDeviceById(id);
}
Expand Down
43 changes: 16 additions & 27 deletions src/app/shared/device-configuration.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { firstValueFrom, Observable, Subject } from 'rxjs';
import { DeviceConfiguration } from '../model/device-configuration';

@Injectable({
Expand All @@ -13,40 +14,28 @@ export class DeviceConfigurationService {

localDeviceConfigurations: DeviceConfiguration[];

deviceConfigurations: DeviceConfiguration[] = [{
id: "epulse-feather",
name: "ePulse Feather",
imageSource: "assets/feather/epulsefeather.jpg",
partitions: [{
name: 'Firmware',
data: new Uint8Array,
offset: 0x00,
url: './assets/feather/app-firmware.bin'
}]
},
{
id: "espgateway",
name: "ESPGateway",
imageSource: "assets/espgateway/espgateway.jpg",
partitions: [{
name: 'Firmware',
data: new Uint8Array,
offset: 0x00,
url: './assets/espgateway/app-firmware.bin'
}]
}];
deviceConfigurations: DeviceConfiguration[] = [];


constructor() { }
constructor(public httpClient: HttpClient) {

getDeviceConfigurations(): DeviceConfiguration[] {
}


loadDefaultDeviceConfiguration(): Observable<DeviceConfiguration[]> {
return this.httpClient.get<DeviceConfiguration[]>("/assets/defaultDeviceConfiguration.json");
}

async getDeviceConfigurations(): Promise<DeviceConfiguration[]> {
this.deviceConfigurations = await firstValueFrom(this.loadDefaultDeviceConfiguration());
this.loadLocalDeviceConfigurations();
var combinedDeviceConfigurations = this.deviceConfigurations.concat(this.localDeviceConfigurations);
return combinedDeviceConfigurations;
}

getDeviceConfigurationById(id: string) {
return this.getDeviceConfigurations().find(x => x.id == id);
async getDeviceConfigurationById(id: string) {
const combinedConfiguration = await this.getDeviceConfigurations();
return combinedConfiguration.find(x => x.id == id);
}

addOrUpdateLocalStorageConfiguration(deviceConfiguration: DeviceConfiguration) {
Expand Down
24 changes: 24 additions & 0 deletions src/assets/defaultDeviceConfiguration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"id": "epulse-feather",
"name": "ePulse Feather",
"imageSource": "assets/feather/epulsefeather.jpg",
"partitions": [{
"name": "Firmware",
"data": [],
"offset": 0,
"url": "./assets/feather/app-firmware.bin"
}]
},
{
"id": "espgateway",
"name": "ESPGateway",
"imageSource": "assets/espgateway/espgateway.jpg",
"partitions": [{
"name": "Firmware",
"data": [],
"offset": 0,
"url": "./assets/espgateway/app-firmware.bin"
}]
}
]

0 comments on commit 1c669c1

Please sign in to comment.