1import * as std from 'std'
2import * as NETWORK from 'NETWORK';
3
4var WIFI_TYPE = 0;
5var CELLULAR_TYPE = 1;
6var ETHNET_TYPE = 2;
7
8class ADVANCED_LOCATION {
9  constructor() {
10    this.devType = NETWORK.getType();
11    if (this.devType === WIFI_TYPE) {
12      std.eval('import * as NETMGR from \'NETMGR\'; globalThis.NETMGR = NETMGR');
13    }
14    else if (this.devType === CELLULAR_TYPE) {
15      std.eval('import * as CELLULAR from \'CELLULAR\'; globalThis.CELLULAR = CELLULAR');
16    }
17  }
18
19
20  getAccessApInfo() {
21    var info = { mac: null, ip: null, rssi: null };
22    var dev_handler = NETMGR.getDev('/dev/wifi0');
23    if (this.devType === WIFI_TYPE) {
24      if (NETMGR.getState(dev_handler) === 5) {
25        var { mac, ip_addr, rssi } = NETMGR.getIfConfig(dev_handler);
26        info.mac = mac;
27        info.ip = ip_addr;
28        info.rssi = rssi;
29      } else {
30        console.log('ERROR: wifi is not connected');
31      }
32    } else {
33      console.log('ERROR: board does not support wifi');
34    }
35    return info;
36  }
37
38  getAccessedLbsInfo() {
39    var info = {
40      cellid: null,
41      lac: null,
42      mcc: null,
43      mnc: null,
44      signal: null
45    };
46    if (this.devType === CELLULAR_TYPE) {
47      if (CELLULAR.getStatus() === 1) {
48        var { cellid, lac, mcc, mnc, signal } = CELLULAR.getLocatorInfo();
49        info.cellid = cellid;
50        info.lac = lac;
51        info.mcc = mcc;
52        info.mnc = mnc;
53        info.signal = signal;
54      } else {
55        console.log('ERROR: cellular is not connected')
56      }
57    } else {
58      console.log('ERROR: board does not support cellular')
59    }
60    return info;
61  }
62}
63
64export function init() {
65  return new ADVANCED_LOCATION();
66}
67