Exemplo n.º 1
0
 function errorToSSO($level, $msg, $file, $line, $context)
 {
     $message = NULL;
     // do nothing when level is 0 or with @ (we don't care about error)
     if (0 == ($level & error_reporting())) {
         return;
     }
     //TODO move this log function to printerlog helper
     $json_context = @json_encode($context);
     $message = strip_tags($msg . " in " . $file . " at " . $line . " with " . $json_context);
     $this->load->helper('printerlog');
     PrinterLog_logDebug('ErrorHandler ' . $level . ': ' . $message);
     // just display error for simulator (develop staff), and return 503 for ajax call
     if ($this->config->item('simulator')) {
         $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
         header($protocol . ' 503');
         var_dump(array('level' => $level, 'message' => $message));
         die("error");
     } else {
         PrinterLog_logSSO($level, 500, $message);
     }
     header('Location: /error');
     exit;
 }
Exemplo n.º 2
0
function PrinterState_filterOutput(&$output, $command = '', $trim_ok = TRUE)
{
    global $PRINTER;
    if (!is_array($output)) {
        return FALSE;
    } else {
        if (empty($output)) {
            $PRINTER['last_command'] = $command;
            return TRUE;
        } else {
            $retry = 0;
            do {
                if ($retry != 0) {
                    $output = array();
                    exec($command, $output);
                }
                // assign output to temp and empty output array
                $array_tmp = $output;
                $output = array();
                $retry_flag = FALSE;
                // filter empty line
                // 			$array_tmp = array_filter($array_tmp, "PrinterState__checkLine");
                // filter the output not necessary
                foreach ($array_tmp as $line) {
                    // jump the empty line
                    $line = trim($line, " \t\n\r\v");
                    if ($line == '') {
                        continue;
                    }
                    // check it start with [<-] or [->], then filter it
                    //filter the input
                    if (strpos($line, '[->]') === 0) {
                        continue;
                    }
                    // 				$line = preg_replace('[\[->\]]', '', $line, 1);
                    $line = preg_replace('[\\[<-\\]]', '', $line, 1);
                    $line = trim($line, " \t\n\r\v");
                    if ($line == '') {
                        continue;
                    }
                    $output[] = $line;
                    if ($line == 'END_INITIALISATION') {
                        $sso_message = 'Marlin reset; current: ' . $command . ', last: ' . (is_array($PRINTER) && array_key_exists('last_command', $PRINTER) ? $PRINTER['last_command'] : 'N/A');
                        PrinterLog_logSSO(3, 503, $sso_message);
                        $PRINTER['last_command'] = $command;
                        PrinterLog_logArduino($command, json_encode($output));
                        ++$retry;
                        $retry_flag = TRUE;
                        break;
                    }
                }
                if ($retry_flag == FALSE) {
                    break;
                    // it's ok if we reach here, so breakout the loop
                }
            } while ($retry < 2);
            if (empty($output)) {
                $PRINTER['last_command'] = $command;
                PrinterLog_logMessage('no return from arduino', __FILE__, __LINE__);
                return TRUE;
            }
            // filter the ok message in the end of array
            if ($trim_ok == TRUE && strtolower($output[count($output) - 1]) == 'ok') {
                unset($output[count($output) - 1]);
            }
        }
    }
    $PRINTER['last_command'] = $command;
    return TRUE;
}