src.dualinventive.com/dinet/libdi-php/tests/can_rpc_config_reset.php

57 lines
1.4 KiB
PHP

<?php
/* Send rpc config:set request messages to set device token and activation state */
$fd = di_can_open("vcan0");
$fd2 = di_can_open("vcan0");
// Send config:reset request
$msg = [];
$msg['msgtype'] = DI_CAN_MSGTYPE_RPC;
$msg['ptype'] = DI_CAN_PTYPE_MSGPACK;
$msg['ttype'] = DI_CAN_TRANSFERTYPE_REQUEST;
$msg['dtype'] = DI_RPC_TYPE_CONFIG_RESET;
$msg['msg'] = msgpack_pack(['uid' => DI_RPC_UID_CONFIG_DEVICE_ACTIVATION]);
di_can_send($fd, $msg);
$have_req = false;
$have_rep = false;
while (true) {
$m = di_can_recv($fd2);
if ($m == NULL)
continue;
if ($m['msgtype'] == DI_CAN_MSGTYPE_RPC &&
$m['ptype'] == DI_CAN_PTYPE_MSGPACK &&
$m['ttype'] == DI_CAN_TRANSFERTYPE_REQUEST &&
$m['dtype'] == DI_RPC_TYPE_CONFIG_RESET) {
$have_req = true;
debug_zval_dump($m);
// Send config:reset reply
$msg = [];
$msg['msgtype'] = DI_CAN_MSGTYPE_RPC;
$msg['ptype'] = DI_CAN_PTYPE_MSGPACK;
$msg['ttype'] = DI_CAN_TRANSFERTYPE_REPLY;
$msg['dtype'] = DI_RPC_TYPE_CONFIG_RESET;
di_can_send($fd, $msg);
} else {
print("INVALID REQUEST");
debug_zval_dump($m);
}
if ($m['msgtype'] == DI_CAN_MSGTYPE_RPC &&
$m['ttype'] == DI_CAN_TRANSFERTYPE_REPLY &&
$m['dtype'] == DI_RPC_TYPE_CONFIG_RESET) {
$have_rep = true;
debug_zval_dump($m);
}
if ($have_req && $have_rep)
break;
}
di_can_close($fd);
di_can_close($fd2);