pxt-ev3/libs/core/serialnumber.cpp
Michał Moskal c5cec3a6ba update to pxt 5 and pxt-common-packages 6 (#934)
* bump pxt

* fix build issues

* Auto-gen of projects/summary

* removing feild editors moved to pxt

* various typing fixes

* more typing fixes

* fixing various typing issues

* Start on integration of new pxt

* serial number fixes

* gc-ify MMap object

* Re-build generated files

* fix console listeners

* clear lf() warnings

* More generated files

* also auto-generated

* Compilation fixes

* fix merge

* mostly fixing blocks

* fix sim

* fix field motors

* enable a few features

* moving to tsx

* try to fix edtiro compilation

* more defs

* removing commands

* removing extra $

* fix blockly warning

* hiding images

* enabling more pxt features

* hide images

* setup autorun

* add lock on target_reset

* update deps

* return trylock result

* updated pxt

* rename video section

* add alpha channel

* upgraded pxt

* bump pxt/version

* removed alpha ref

* var ceanup

* don't do major bump
2019-10-08 21:57:55 -07:00

71 lines
1.3 KiB
C++

#include "pxt.h"
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <unistd.h>
#define BTPROTO_HCI 1
#define HCIGETDEVLIST _IOR('H', 210, int)
#define HCIGETDEVINFO _IOR('H', 211, int)
struct hci_dev_info {
uint16_t dev_id;
char name[8];
uint8_t bdaddr[6];
uint32_t padding[32];
};
struct hci_dev_req {
uint16_t dev_id;
uint32_t dev_opt;
};
struct hci_dev_list_req {
uint16_t dev_num;
hci_dev_req dev_req[2];
};
static uint64_t bt_addr() {
uint64_t res = -1;
int fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (fd < 0) {
DMESG("BT_ADDR: can't open HCI socket");
return res;
}
hci_dev_list_req dl;
dl.dev_num = 1;
if (ioctl(fd, HCIGETDEVLIST, (void *)&dl) < 0) {
DMESG("BT_ADDR: can't get HCI device list");
goto done;
}
hci_dev_info di;
di.dev_id = dl.dev_req[0].dev_id;
if (ioctl(fd, HCIGETDEVINFO, (void *)&di) < 0) {
DMESG("BT_ADDR: can't get HCI device info");
goto done;
}
res = 0;
memcpy(&res, di.bdaddr, 6);
done:
close(fd);
return res;
}
namespace pxt {
uint64_t getLongSerialNumber() {
static uint64_t serial;
if (serial == 0)
serial = bt_addr();
return serial;
}
} // namespace pxt