Beispiel #1
0
 function slice_status_ajax()
 {
     $ret_val = 0;
     $cr = 0;
     $array_data = array();
     $status_current = NULL;
     $display = NULL;
     $this->load->helper(array('printerstate', 'slicer'));
     $this->load->library('parser');
     $ret_val = CoreStatus_checkInIdle($status_current);
     if ($ret_val == TRUE) {
         $cr = 403;
         $this->output->set_status_header($cr);
         return;
     }
     $ret_val = PrinterState_checkBusyStatus($status_current, $array_data);
     if ($ret_val == TRUE && $status_current == CORESTATUS_VALUE_IDLE) {
         if (isset($array_data[PRINTERSTATE_TITLE_LASTERROR])) {
             $cr = $array_data[PRINTERSTATE_TITLE_LASTERROR];
         } else {
             $cr = ERROR_OK;
         }
     } else {
         if ($ret_val == FALSE && $status_current == CORESTATUS_VALUE_SLICE) {
             if (!isset($array_data[PRINTERSTATE_TITLE_PERCENT])) {
                 $this->load->helper('printerlog');
                 PrinterLog_logError('can not find percentage in slicing', __FILE__, __LINE__);
                 $cr = ERROR_INTERNAL;
             } else {
                 $this->lang->load('sliceupload/slice_status_ajax', $this->config->item('language'));
                 $array_display = array('percent' => $array_data[PRINTERSTATE_TITLE_PERCENT], 'message' => isset($array_data[PRINTERSTATE_TITLE_DETAILMSG]) ? t($array_data[PRINTERSTATE_TITLE_DETAILMSG]) : NULL);
                 $cr = ERROR_OK;
                 $this->output->set_status_header($cr);
                 $this->output->set_content_type('jsonu');
                 $this->parser->parse('plaintxt', array('display' => json_encode($array_display)));
                 return;
             }
         } else {
             $this->load->helper('printerlog');
             PrinterLog_logError('unknown status in slicing', __FILE__, __LINE__);
             $cr = ERROR_INTERNAL;
             CoreStatus_setInIdle();
         }
     }
     if (!in_array($cr, array(ERROR_OK, ERROR_INTERNAL, ERROR_LOW_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_CART, ERROR_MISS_LEFT_CART))) {
         $this->load->helper('printerlog');
         PrinterLog_logError('unknown return after slicing: ' . $cr, __FILE__, __LINE__);
         $cr = ERROR_INTERNAL;
     }
     if ($cr == ERROR_INTERNAL) {
         $this->output->set_status_header($cr);
     } else {
         $this->output->set_status_header(202);
     }
     $display = $cr . " " . t(MyERRMSG($cr));
     $this->output->set_content_type('txt_u');
     $this->parser->parse('plaintxt', array('display' => $display));
     //optional
     return;
 }
Beispiel #2
0
 function __construct()
 {
     parent::__construct();
     $this->load->helper(array('form', 'url', 'json', 'errorcode', 'corestatus'));
     $status_current = '';
     if (CoreStatus_checkInInitialization() || CoreStatus_checkInConnection() || CoreStatus_checkInUSB()) {
         // let no block REST web service go for setting network
         if (CoreStatus_checkCallNoBlockRESTInConnection()) {
             return;
         }
         // we haven't finished initialization or connection yet
         $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER);
     } else {
         if (!CoreStatus_checkInIdle($status_current)) {
             // check if the status is changed
             $ret_val = 0;
             $this->load->helper('printerstate');
             switch ($status_current) {
                 case CORESTATUS_VALUE_SLICE:
                     if (CoreStatus_checkCallNoBlockRESTInSlice()) {
                         // do not block some special REST for action in slicing
                         return;
                     }
                     $ret_val = PrinterState_checkBusyStatus($status_current);
                     if ($ret_val == FALSE) {
                         // still in slicing
                         break;
                     } else {
                         if ($status_current == CORESTATUS_VALUE_IDLE) {
                             // encounted some errors
                             break;
                         } else {
                             // CORESTATUS_VALUE_PRINT
                             $this->load->helper('printerlog');
                             PrinterLog_logMessage('call rest when we are in slicing, but finished really', __FILE__, __LINE__);
                         }
                     }
                     // we treat canceling as printing
                 // we treat canceling as printing
                 case CORESTATUS_VALUE_PRINT:
                     // do not block some special REST for action in printing
                     if (CoreStatus_checkCallNoBlockRESTInPrint()) {
                         return;
                     }
                 case CORESTATUS_VALUE_CANCEL:
                     //TODO test here for canceling
                     $ret_val = PrinterState_checkInPrint();
                     if ($ret_val == FALSE) {
                         $ret_val = CoreStatus_setInIdle();
                         if ($ret_val == TRUE) {
                             $this->load->helper('printerlog');
                             PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__);
                             return;
                             // continue to generate if we are now in idle
                         }
                         $this->load->helper('printerlog');
                         PrinterLog_logError('can not set status in idle', __FILE__, __LINE__);
                     }
                     break;
                 default:
                     $ret_val = PrinterState_checkBusyStatus($status_current);
                     if ($ret_val == TRUE) {
                         $this->load->helper('printerlog');
                         PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__);
                         return;
                         // status has changed to idle
                     }
                     break;
             }
             // do not block some special REST
             if (CoreStatus_checkCallNoBlockREST()) {
                 return;
             }
             // return that printer is busy
             $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER);
         }
     }
 }
Beispiel #3
0
function PrinterState_checkStatusAsArray($extra_info = TRUE)
{
    $command = '';
    $output = array();
    $ret_val = 0;
    $data_json = array();
    $temp_data[PRINTERSTATE_TITLE_LASTERROR] = array();
    $time_start = NULL;
    $status_current = '';
    // if we need duration, the function that get duration by id is necessary
    // and we must stock print list id somewhere in json file
    $CI =& get_instance();
    $CI->load->helper('corestatus');
    if (CoreStatus_checkInUSB()) {
        $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_USB;
        return $data_json;
    } else {
        if (CoreStatus_checkInConnection()) {
            $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_WAIT_CONNECT;
            return $data_json;
        }
    }
    $ret_val = CoreStatus_checkInIdle($status_current, $status_json);
    if ($ret_val == TRUE) {
        $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_IDLE;
        //TODO think about if we need to display last error as 200 (error_ok) or not
        if (array_key_exists(CORESTATUS_TITLE_LASTERROR, $status_json) && !is_null($status_json[CORESTATUS_TITLE_LASTERROR]) && $status_json[CORESTATUS_TITLE_LASTERROR] != ERROR_OK) {
            // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_LASTERROR] = $status_json[CORESTATUS_TITLE_LASTERROR];
            // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_DETAILMSG] = $status_json[CORESTATUS_TITLE_MESSAGE];
            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_SLICE_ERR] = $status_json[CORESTATUS_TITLE_LASTERROR] . ' ' . $status_json[CORESTATUS_TITLE_MESSAGE];
        }
    } else {
        if ($ret_val == FALSE) {
            $temp_data = array();
            $status_old = $status_current;
            PrinterState_checkBusyStatus($status_current, $temp_data);
            if (in_array($status_current, array(CORESTATUS_VALUE_SLICE, CORESTATUS_VALUE_PRINT))) {
                $data_json[PRINTERSTATE_TITLE_PERCENT] = $temp_data[PRINTERSTATE_TITLE_PERCENT];
            }
            $data_json[PRINTERSTATE_TITLE_STATUS] = $status_current;
            // return error code in the first time when we have error from slicing=>idle
            if ($status_old == CORESTATUS_VALUE_SLICE && $status_current == CORESTATUS_VALUE_IDLE && array_key_exists(PRINTERSTATE_TITLE_LASTERROR, $temp_data)) {
                // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_LASTERROR] = $temp_data[PRINTERSTATE_TITLE_LASTERROR];
                // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_DETAILMSG] = $temp_data[PRINTERSTATE_TITLE_DETAILMSG];
                $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_SLICE_ERR] = $temp_data[PRINTERSTATE_TITLE_LASTERROR] . ' ' . $temp_data[PRINTERSTATE_TITLE_DETAILMSG];
            } else {
                if ($status_current == CORESTATUS_VALUE_PRINT) {
                    $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_PRINT;
                    $array_status = array();
                    // add temperature
                    if ($extra_info == TRUE && $data_json[PRINTERSTATE_TITLE_PERCENT] != 100) {
                        $data_temperature = PrinterState_getExtruderTemperaturesAsArray();
                        if (!is_array($data_temperature)) {
                            // log internal error
                            $CI->load->helper('printerlog');
                            PrinterLog_logError('API error when getting temperatures in printing', __FILE__, __LINE__);
                        } else {
                            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_L] = array_key_exists(PRINTERSTATE_LEFT_EXTRUD, $data_temperature) ? $data_temperature[PRINTERSTATE_LEFT_EXTRUD] : 0;
                            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_R] = array_key_exists(PRINTERSTATE_RIGHT_EXTRUD, $data_temperature) ? $data_temperature[PRINTERSTATE_RIGHT_EXTRUD] : 0;
                            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_B] = array_key_exists(PRINTERSTATE_HEAT_BED, $data_temperature) ? $data_temperature[PRINTERSTATE_HEAT_BED] : 0;
                        }
                    }
                    // try to calculate time remained when percentage is passed offset
                    $ret_val = CoreStatus_getStatusArray($array_status);
                    if ($ret_val == TRUE && isset($array_status[CORESTATUS_TITLE_STARTTIME]) && isset($array_status[CORESTATUS_TITLE_ESTIMATE_T])) {
                        $time_pass = time() - $array_status[CORESTATUS_TITLE_STARTTIME];
                        $data_json[PRINTERSTATE_TITLE_PASSTIME] = $time_pass;
                        if (isset($data_json[PRINTERSTATE_TITLE_PERCENT]) && ($time_pass >= PRINTERSTATE_VALUE_OFST_TO_CAL_TIME || $data_json[PRINTERSTATE_TITLE_PERCENT] >= PRINTERSTATE_VALUE_OFST_TO_CAL_PCT)) {
                            // rest time = total time - passed time
                            // total time = estimate time (by filament) * (1 - percentage ^ 0.5) + estimate time (by time) * percentage ^ 0.5
                            // estimate time (by time) = passed time / percentage
                            // 					$percentage_finish = $data_json[PRINTERSTATE_TITLE_PERCENT] / 100;
                            $calculate_factor = sqrt($data_json[PRINTERSTATE_TITLE_PERCENT] / 100);
                            $time_estimation = $array_status[CORESTATUS_TITLE_ESTIMATE_T];
                            $data_json[PRINTERSTATE_TITLE_DURATION] = (int) ($time_estimation * (1 - $calculate_factor) + $time_pass * (1 / $calculate_factor - 1));
                        }
                    }
                    // check operation
                    if (file_exists(PRINTERSTATE_FILE_PRINT_HEAT)) {
                        $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_HEAT;
                    } else {
                        if ($data_json[PRINTERSTATE_TITLE_PERCENT] == 100) {
                            $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_END;
                        }
                    }
                    $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_OPER] = $print_operation;
                }
            }
        }
    }
    if ($extra_info == TRUE && $status_current == CORESTATUS_VALUE_IDLE) {
        // check if we need to change idle into sliced or not
        PrinterState_checkSlicedCondition($data_json);
        //TODO add timelapse checking
        PrinterState_checkTimelapseCondition($data_json);
    }
    return $data_json;
}