@@ -12,13 +12,16 @@ import { IoTDevice } from "@entities/iot-device.entity";
1212import configuration from "@config/configuration" ;
1313import { OpenDataDkSharingController } from "@admin-controller/open-data-dk-sharing.controller" ;
1414import { ErrorCodes } from "@enum/error-codes.enum" ;
15+ import { IoTDeviceType } from "@enum/device-type.enum" ;
16+ import { ChirpstackDeviceService } from "@services/chirpstack/chirpstack-device.service" ;
1517
1618@Injectable ( )
1719export class OpenDataDkSharingService {
1820 constructor (
1921 @InjectRepository ( OpenDataDkDataset )
2022 private repository : Repository < OpenDataDkDataset > ,
21- private payloadDecoderExecutorService : PayloadDecoderExecutorService
23+ private payloadDecoderExecutorService : PayloadDecoderExecutorService ,
24+ private chirpstackDeviceService : ChirpstackDeviceService
2225 ) { }
2326
2427 private readonly BACKEND_BASE_URL = configuration ( ) [ "backend" ] [ "baseurl" ] ;
@@ -40,18 +43,17 @@ export class OpenDataDkSharingService {
4043 return { error : ErrorCodes . NoData } ;
4144 }
4245
43- return this . decodeData ( rawData ) ;
46+ return await this . decodeData ( rawData ) ;
4447 }
4548
46- private decodeData ( rawData : OpenDataDkDataset ) {
47- // TODO: Do this in parallel
49+ private async decodeData ( rawData : OpenDataDkDataset ) {
4850 const results : any [ ] = [ ] ;
49- rawData . dataTarget . connections . forEach ( connection => {
51+ for ( const connection of rawData . dataTarget . connections ) {
5052 this . logger . debug ( `Got connection(${ connection . id } )` ) ;
51- connection . iotDevices . forEach ( async device => {
53+ for ( const device of connection . iotDevices ) {
5254 await this . decodeDevice ( device , connection , results ) ;
53- } ) ;
54- } ) ;
55+ }
56+ }
5557 return results ;
5658 }
5759
@@ -67,6 +69,14 @@ export class OpenDataDkSharingService {
6769 }
6870 try {
6971 if ( connection . payloadDecoder != null ) {
72+ // Enrich lorawan devices with chirpstack data
73+ if (
74+ device . type === IoTDeviceType . LoRaWAN &&
75+ connection . payloadDecoder . decodingFunction . includes ( "lorawanSettings" )
76+ ) {
77+ device = await this . chirpstackDeviceService . enrichLoRaWANDevice ( device ) ;
78+ }
79+
7080 const decoded = await this . payloadDecoderExecutorService . callUntrustedCode (
7181 connection . payloadDecoder . decodingFunction ,
7282 device ,
0 commit comments