src.dualinventive.com/dinet/libdi-php/examples/can_raw_reqrep_device_uid.php

34 lines
774 B
PHP

<?php
$fd = di_can_open("can1");
di_can_set_nodeid($fd, "00000000000000000000000000000001");
function send_device_uid($fd)
{
$msg = [];
$msg['msgtype'] = DI_CAN_MSGTYPE_RAW;
$msg['ttype'] = DI_CAN_TRANSFERTYPE_REPLY;
$msg['dtype'] = DI_CAN_RAW_DTYPE_DEVICE_UID;
$msg['ptype'] = DI_CAN_PTYPE_STRING;
$msg['dst_id'] = DI_CAN_NODEID_BROADCAST;
$msg['msg'] = "9900deadbeefdeadbeefcafebabe1337";
di_can_send($fd, $msg);
unset($msg);
}
while (true) {
$x = di_can_recv($fd);
if ($x) {
if ($x['msgtype'] == DI_CAN_MSGTYPE_RAW &&
$x['ttype'] == DI_CAN_TRANSFERTYPE_REQUEST &&
$x['dtype'] == DI_CAN_RAW_DTYPE_DEVICE_UID) {
send_device_uid($fd);
print "reply device:uid" . PHP_EOL;
}
unset($x);
}
}
di_can_close($fd);
unset($fd);