public function actionrestoredefault() { //发送指令 $message = '<br>'; FLEA::loadClass('Util_socketclient'); $dev_bak = FLEA::getSingleton('Model_devinitialinfo'); $dev = $dev_bak->findAll(); //如果备份表里为空,将退出; if (!$dev) { $this->_G->customshow('您当前没有备份的默认值,请先备份', "edit", "Index", 3, 0); exit; } foreach ($dev as $devinfo) { $socket = new Util_socketclient(); $socket->socketconn($devinfo['ipaddr'], $devinfo['ipport']); foreach ($devinfo['chninfo'] as $chninfo) { $sendcommand = $socket->messagetype($chninfo['chn'], $chninfo['apid'], $chninfo['agcstat'], $chninfo['gain'], $chninfo['mutestat'], $chninfo['passstat']); switch ($socket->sendmessage($sendcommand)) { case $socket->returntrue: $this->log->writelog($devinfo['devname'], $sendcommand, $socket->returntrue); $message .= "设备{$devinfo['devname']}通道号:{$devinfo['chn']}指令发送: [<font color=red><b>{$sendcommand}</b></font>]成功"; $type = '1'; case $socket->returnfalse: $this->log->writelog($devinfo['devname'], $sendcommand, $socket->returnfalse); $message .= "<font color=red>设备{$devinfo['devname']}通道号:{$devinfo['chn']}指令发送: [<b>{$sendcommand}</b>]失败</b>"; $type = '0'; } } unset($socket); } $message .= "<br>备份恢复完成"; $this->_G->customshow($message, 'edit', 'Index', 3, $type); }
/** * 恢复设备默认设置 * */ public function actionResumeDefault() { $devinfo = $this->M_devinfo->find($_GET['serial']); $socket = FLEA::getSingleton('Util_socketclient'); $socket->socketconn($devinfo['ipaddr'], $devinfo['ipport']); $this->log->ip = $devinfo['ipaddr']; switch ($socket->sendmessage('SINITZ')) { case $socket->returntrue: $this->log->writelog($devinfo['devname'], 'SINITZ', $socket->returntrue); $serial = (int) $_GET['serial']; try { $db = FLEA::getDBO(); $db->startTrans(); sleep(1); for ($i = 1; $i < 9; $i++) { $return_socketinfo = $socket->sendmessage("SI{$i}Z"); if (strlen($return_socketinfo) == 13) { $chninfo = $socket->analysisinfo($return_socketinfo); if ($chninfo === FALSE) { exit($this->_G->customshow('获取设备信息出现乱码,请重试', $_GET['socket_C'], 'index', 3, 0)); } //如果有乱码将直接退出 #检测APID是否有相同 $this->M_chninfo->updateByConditions("dev_no='{$serial}' and chn='{$chninfo['chn']}'", $chninfo); $chninfo['prgname'] = " "; $chninfo['chnshort'] = " "; $this->M_chninfo->updateByConditions("dev_no='{$serial}' and chn='{$chninfo['chn']}'", $chninfo); sleep(1); } } fclose($socket->socket); $db->completeTrans(); $this->_G->customshow("该设备已恢复成默认值", 'socket', 'index', 3, 1); } catch (Exception $e) { $db->completeTrans(FALSE); $this->_G->customshow("恢复设备默认值失败,请重试", 'socket', 'index', 3, 0); } break; case $socket->returnfalse: $this->log->writelog($devinfo['devname'], 'SINITZ', $socket->returnfalse); $this->_G->customshow("恢复出错,请重新恢复", 'socket', 'index', 0); break; } }
define('SocketFalse', 'SFAILZ'); //返回失败值 define('SocketTrue', 'SOKZ'); //调整整时返回的值 define('REFURBISH', 5000); //定时刷新时间 //echo "<meta http-equiv=\"refresh\" content=\"5;URL=".$_SERVER['REQUEST_URI']."\" />"; //搜出定时所有的记录 $sql = "select * from socket_dev_schedule"; $result = mysql_query($sql); $list = array(); while ($filed_list = mysql_fetch_assoc($result)) { $list[] = $filed_list; } //初始化需要的变量 $log = new Util_log(); $message = ''; $nowdate = date('Ymd'); $nowtime = date('H:i'); $nowweek = date('w'); $socket = new Util_socketclient(); foreach ($list as $filed) { //每天设置 if ($filed['week'] == '0') { $drivertype = '每天'; if ($filed['run_type'] == '1') { $drivername = '设备'; } else { $drivername = '频道'; } if ($filed['schedule'] <= $nowtime) {