prepareMeter(options, meterData) {
    // First we create meter for Kamstup Multical 21 with meter configuration
    // settings.
    let meter = KamstrupMultical21Meter.getInstance();
    meter.applySettings({
      meterData: meterData,
    });

    let statistics = Statistics.getInstance();
    statistics.prepareStats(meterData);

    // Create data buffer. All raw data will be buffered before processing
    let buffer = new DataBuffer();
    let reader = false;

    if (options.hasOwnProperty('csvFile'))
      this._csvFile = options.csvFile;

    if (options.readerType == 'log') {
      // Load test data log file(s) containing list of keyed values
      reader = new LogReader({ source: options.logReaderSource, buffer: buffer });
    } else {
      // Register log writer as listener. This allows us to write all
      // raw data to log file to be used later if needed.
      let filepath = path.join(__dirname, options.logWriterPath);
      let logWriter = new LogWriter({ logFile: filepath});

      buffer.registerListener('logWriter', {
        onPush: (arg) => { logWriter.writeRawTelegram(arg) }
      });

      console.log("Start Wireless M-Bus reader...");

      reader = new AmberWirelessReader({
        buffer: buffer,
        serialPortPath: options.serialPortPath
      });
    }

    // Enabled data source, now all data will be sent to out data buffer.
    reader.enableSource();

    // Process buffer data.
    let interval = setInterval(() => {
      if (!buffer.hasData())
        return;
      let telegram = new WirelessMBusTelegram(buffer.fetch());
      meter.processTelegramData(telegram);
      // Just write data to console
      let stats = statistics.getMeterStats(meter, telegram);
      console.log(`${stats.description} ${stats.deviceType}, ${stats.initTargetValue} -> ${stats.currentValue} = ${stats.monthUsage}, delta: ${stats.deltaTargetValue} -> ${stats.deltaValue}`);

      // Write composed data to csv file, one row for one meter per day
      this.writeCSV(stats);

    }, options.bufferInterval);

    if (options.previewInterval) {
      let previewInterval = setInterval(() => {
        let stats = statistics.getStats()
        Object.keys(stats).forEach(key => {
          if (stats[key])
            console.log(`Meter: ${stats[key].description} Count telegrams: ${stats[key].counter}`);
          else
            console.log(`No meter data for: ${meter.describeMeterData(meterData.get(key))}`);
        });
      }, options.previewInterval);
    }
  }
/**
  * Prepare example meters and collect data.
  *
  * @param options
  *   Options
  * @param meterData
  *   Meter configuration data
  */
Prepare example meters and collect data.
@param options
Options
@param meterData
Meter configuration data
Prepare example meters and collect data . @param options Options @param meterData Meter configuration data
prepareMeter(options, meterData) {
    let meter = KamstrupMultical21Meter.getInstance();
    meter.applySettings({
      meterData: meterData,
    });
    let statistics = Statistics.getInstance();
    statistics.prepareStats(meterData);
    let buffer = new DataBuffer();
    let reader = false;
    if (options.hasOwnProperty('csvFile'))
      this._csvFile = options.csvFile;
    if (options.readerType == 'log') {
      reader = new LogReader({ source: options.logReaderSource, buffer: buffer });
    } else {
      let filepath = path.join(__dirname, options.logWriterPath);
      let logWriter = new LogWriter({ logFile: filepath});
      buffer.registerListener('logWriter', {
        onPush: (arg) => { logWriter.writeRawTelegram(arg) }
      });
      console.log("Start Wireless M-Bus reader...");
      reader = new AmberWirelessReader({
        buffer: buffer,
        serialPortPath: options.serialPortPath
      });
    }
    reader.enableSource();
    let interval = setInterval(() => {
      if (!buffer.hasData())
        return;
      let telegram = new WirelessMBusTelegram(buffer.fetch());
      meter.processTelegramData(telegram);
      let stats = statistics.getMeterStats(meter, telegram);
      console.log(`${stats.description} ${stats.deviceType}, ${stats.initTargetValue} -> ${stats.currentValue} = ${stats.monthUsage}, delta: ${stats.deltaTargetValue} -> ${stats.deltaValue}`);
      this.writeCSV(stats);
    }, options.bufferInterval);
    if (options.previewInterval) {
      let previewInterval = setInterval(() => {
        let stats = statistics.getStats()
        Object.keys(stats).forEach(key => {
          if (stats[key])
            console.log(`Meter: ${stats[key].description} Count telegrams: ${stats[key].counter}`);
          else
            console.log(`No meter data for: ${meter.describeMeterData(meterData.get(key))}`);
        });
      }, options.previewInterval);
    }
  }
prepareMeter ( options , meterData ) { let meter = KamstrupMultical21Meter . getInstance ( ) ; meter . applySettings ( { meterData : meterData , } ) ; let statistics = Statistics . getInstance ( ) ; statistics . prepareStats ( meterData ) ; let buffer = new DataBuffer ( ) ; let reader = false ; if ( options . hasOwnProperty ( 'csvFile' ) ) this . _csvFile = options . csvFile ; if ( options . readerType == 'log' ) { reader = new LogReader ( { source : options . logReaderSource , buffer : buffer } ) ; } else { let filepath = path . join ( __dirname , options . logWriterPath ) ; let logWriter = new LogWriter ( { logFile : filepath } ) ; buffer . registerListener ( 'logWriter' , { onPush : ( arg ) => { logWriter . writeRawTelegram ( arg ) } } ) ; console . log ( "Start Wireless M-Bus reader..." ) ; reader = new AmberWirelessReader ( { buffer : buffer , serialPortPath : options . serialPortPath } ) ; } reader . enableSource ( ) ; let interval = setInterval ( ( ) => { if ( ! buffer . hasData ( ) ) return ; let telegram = new WirelessMBusTelegram ( buffer . fetch ( ) ) ; meter . processTelegramData ( telegram ) ; let stats = statistics . getMeterStats ( meter , telegram ) ; console . log ( ` ${ stats . description } ${ stats . deviceType } ${ stats . initTargetValue } ${ stats . currentValue } ${ stats . monthUsage } ${ stats . deltaTargetValue } ${ stats . deltaValue } ` ) ; this . writeCSV ( stats ) ; } , options . bufferInterval ) ; if ( options . previewInterval ) { let previewInterval = setInterval ( ( ) => { let stats = statistics . getStats ( ) Object . keys ( stats ) . forEach ( key => { if ( stats [ key ] ) console . log ( ` ${ stats [ key ] . description } {s tats[ k ey] . c ounter} ` ) ; else console . log ( ` ${ meter . describeMeterData ( meterData . get ( key ) ) } ` ) ; } ) ; } , options . previewInterval ) ; } }
Prepare example meters and collect data.
Prepare example meters and collect data .
// First we create meter for Kamstup Multical 21 with meter configuration // settings. // Create data buffer. All raw data will be buffered before processing // Load test data log file(s) containing list of keyed values // Register log writer as listener. This allows us to write all // raw data to log file to be used later if needed. // Enabled data source, now all data will be sent to out data buffer. // Process buffer data. // Just write data to console // Write composed data to csv file, one row for one meter per day