/** * Stop flash light */ public function actionStopFind() { if (SYS_INFO === 'SF3301_D_V1') { SocketModel::request('{"command":"led","parameter":0}'); } else { // find gpio thread $command = SUDO_COMMAND . 'ps' . (SUDO_COMMAND === '' ? '' : ' -x') . '|grep gpio_0'; exec($command, $output); $pids = array(); foreach ($output as $r) { preg_match('/\\s*(\\d+)\\s*.*/', $r, $match); if (!empty($match[1])) { $pids[] = $match[1]; } } exec(SUDO_COMMAND . 'kill -9 ' . implode(' ', $pids)); echo '200'; exit; } }
/** * USB获得检测结果 */ public function getUsbCheckResult($_strRunMode = '', $_strCheckTar = '') { if (empty($_strRunMode)) { return array(); } // parse target param if (!empty($_strCheckTar)) { $aryTars = explode('-', $_strCheckTar); if (count($aryTars) > 1) { $_strCheckTar = $aryTars[0]; } } // is contain GD miner $boolHasGD = false; if ($_strCheckTar === 'sf') { @exec(SUDO_COMMAND . 'ls /dev/tty* |grep -E "ACM|USB"', $output); $aryUsbCache = array(); $aryUsbCache['usb'] = $output; $aryUsbCache['time'] = time(); $aryUsbCache['hasgd'] = 0; } else { if (in_array($_strRunMode, array('B', 'LB')) && empty($_strCheckTar) || $_strCheckTar === 'lsusb') { $redis = $this->getRedis(); $aryUsbCache = json_decode($redis->readByKey('usb.check.result'), 1); $restartData = json_decode($redis->readByKey('restart.status'), 1); $blank_time = $restartData['status'] === 1 ? 5 : 30; if (empty($aryUsbCache)) { $aryUsbCache = array('usb' => array(), 'time' => 0, 'iswrite' => 0); } $now = time(); // if usb state time out if (empty($aryUsbCache['time']) || $now - $aryUsbCache['time'] > $blank_time || $now - $aryUsbCache['time'] < 0) { $aryUsbCache['iswrite'] = 1; $redis->writeByKey('usb.check.result', json_encode($aryUsbCache, 1)); @exec(SUDO_COMMAND . 'lsusb', $output); $aryUsb = array(); foreach ($output as $usb) { preg_match('/.*Bus\\s(\\d+)\\sDevice\\s(\\d+).*CP210x.*/', $usb, $match_usb); if (!empty($match_usb[1]) && !empty($match_usb[2])) { $boolHasGD = true; $strId = intval($match_usb[1]) . ':' . intval($match_usb[2]); $aryUsb[] = $strId; } else { preg_match('/.*Bus\\s(\\d+)\\sDevice\\s(\\d+).*(SGS\\sThomson\\sMicroelectronics|Future\\sTechnology\\sDevices\\sInternational).*/', $usb, $match_usb); if (!empty($match_usb[1]) && !empty($match_usb[2])) { $strId = intval($match_usb[1]) . ':' . intval($match_usb[2]); $aryUsb[] = $strId; } } } // store usb state $aryUsbCache['usb'] = $aryUsb; $aryUsbCache['time'] = time(); $aryUsbCache['iswrite'] = 0; $aryUsbCache['hasgd'] = $boolHasGD === true ? 1 : 0; $redis->writeByKey('usb.check.result', json_encode($aryUsbCache, 1)); } } else { if (empty($_strCheckTar) || $_strCheckTar === 'tty') { @exec(SUDO_COMMAND . 'ls /dev/tty* |grep -E "ACM|USB"', $output); $aryUsbCache = array(); $aryUsbCache['usb'] = $output; $aryUsbCache['time'] = time(); $aryUsbCache['hasgd'] = 0; } else { if ($_strCheckTar === 'spi') { $aryApiData = SocketModel::request('devs'); // list usb $aryUsb = array(); foreach ($aryApiData as $data) { if (!isset($data['ASC'])) { if (!is_array($data) && strpos($data, 'spidev') === 0) { $aryUsb[] = $data; } continue; } $aryUsb[] = 'ASC' . $data['ASC']; } $aryUsbCache = array(); $aryUsbCache['usb'] = $aryUsb; $aryUsbCache['time'] = time(); } } } } return $aryUsbCache; }
/** * 获得速度数据 * * @return array */ public static function getSpeedDataBySfApi() { $aryApiData = SocketModel::request('{"command":"devs"}'); $aryUsbData = array(); foreach ($aryApiData['DEVS'] as $key => $data) { $aryUsb = $data['Name']; $aryUsbData[$aryUsb] = array('A' => $data['Accepted'], 'R' => $data['Rejected'], 'S' => $data['MHS av'], 'RUN' => $data['Device Elapsed'], 'LAST' => $data['Last Valid Work']); } return $aryUsbData; }