Example #1
0
  noble.on('discover', function(peripheral)
  {
    const ad = peripheral.advertisement;
    const eventType = typeof ad.localName === 'undefined'
      ? btHci.AdvertisingReportEventType.AdvInd
      : btHci.AdvertisingReportEventType.ScanRsp;
    const addressType = peripheral.addressType === 'public'
      ? btHci.AdvertisingReportAddressType.Public
      : btHci.AdvertisingReportAddressType.Random;
    const report = {
      eventType: eventType,
      eventTypeLabel: btHci.AdvertisingReportEventType[eventType],
      addressType: addressType,
      addressTypeLabel: btHci.AdvertisingReportAddressType[addressType],
      address: peripheral.address.toUpperCase(),
      length: -1,
      data: [],
      rssi: peripheral.rssi
    };

    if (typeof ad.localName === 'string')
    {
      report.data.push({
        type: btHci.EirDataType.LocalNameShort,
        typeLabel: btHci.EirDataType[btHci.EirDataType.LocalNameShort],
        value: ad.localName
      });
    }

    if (typeof ad.txPowerLevel === 'number')
    {
      report.data.push({
        type: btHci.EirDataType.TxPowerLevel,
        typeLabel: btHci.EirDataType[btHci.EirDataType.TxPowerLevel],
        value: ad.txPowerLevel
      });
    }

    try
    {
      report.data.push(iNodeHci.decodeMsd(ad.manufacturerData));
    }
    catch (err) {} // eslint-disable-line no-empty

    if (report.data.length)
    {
      app.gateway.handleAdvertisingReport(report);
    }
  });
Example #2
0
  /**
   * @private
   * @param {string} id
   * @param {IncomingMessage} req
   * @param {ServerResponse} res
   * @param {Buffer} body
   */
  function handleGsmUploadRequest(id, req, res, body)
  {
    if (req.method !== 'POST')
    {
      res.writeHead(405);
      res.end();

      return;
    }

    res.writeHead(200);
    res.end();

    const gsmTime = url.parse(req.url, true).query.time || -1;
    const reports = iNodeHci.decodeGsmData(gsmTime, body);

    dumpGsmReports(reports);

    reports.forEach(report => app.gateway.handleAdvertisingReport(report));
  }