Exemplo n.º 1
0
 public function test_curl()
 {
     $this->load->helper('printerlog');
     PrinterLog_logDebug('category: ' . $this->input->post('category') . ', action: ' . $this->input->post('action') . ', printersn: ' . $this->input->post('printersn') . ', label: ' . $this->input->post('label') . ', value: ' . $this->input->post('value'));
     $this->load->library('parser');
     $this->parser->parse('plaintxt', array('display' => 'ok'));
     return;
 }
Exemplo n.º 2
0
 public function index()
 {
     $this->load->helper('printerlog');
     if ($this->input->server('REQUEST_METHOD') == 'POST') {
         $token_post = $this->input->post('token');
         $token_json = json_decode($token_post, TRUE);
         PrinterLog_logDebug('remote token: ' . $token_post);
         if (is_array($token_json) && isset($token_json['token'])) {
             // new token system
             $this->input->set_cookie('auth', $token_json['token'], 0);
             $this->input->set_cookie('token_system', 'new', 1800);
             // 30 mins
             if (isset($token_json['redirect']) && is_array($token_json['redirect']) && isset($token_json['redirect']['url'])) {
                 $redirect_url = $token_json['redirect']['url'] . '?from=remote';
                 // treat get parameter
                 if (isset($token_json['redirect']['prm']) && is_array($token_json['redirect']['prm'])) {
                     foreach ($token_json['redirect']['prm'] as $prm_key => $prm_val) {
                         $redirect_url .= '&' . $prm_key . '=' . $prm_val;
                     }
                 }
                 // treat cookie parameter
                 if (isset($token_json['redirect']['cookie']) && is_array($token_json['redirect']['cookie'])) {
                     $array_cookie = array();
                     foreach ($token_json['redirect']['cookie'] as $cookie_key => $cookie_value) {
                         $array_cookie[$cookie_key] = $cookie_value;
                     }
                     $this->input->set_cookie('redirectData', json_encode($array_cookie), 60);
                     // 1 min
                 }
                 // filter outside redirection
                 if ($redirect_url[0] != '/') {
                     $redirect_url = '/' . $redirect_url;
                 }
                 $this->output->set_header('Location: ' . $redirect_url);
             }
         } else {
             // old token system
             $this->input->set_cookie('auth', $token_post, 0);
             $this->input->set_cookie('token_system', 'old', 1800);
             // 30 mins
             $this->output->set_header('Location: /');
         }
     } else {
         PrinterLog_logError("SetCookie: method != POST");
         echo '<script>alert("denied")</script>';
     }
 }
Exemplo n.º 3
0
 public function stlupload()
 {
     $redirect_cookie = $this->input->cookie('redirectData');
     $this->load->helper('printerlog');
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $name_post = $this->input->post('name');
         $url_post = $this->input->post('url');
         $this->_stlupload_main($name_post, $url_post);
     } else {
         if ($redirect_cookie !== FALSE) {
             $array_cookie = json_decode($redirect_cookie, TRUE);
             if (is_array($array_cookie) && isset($array_cookie['name']) && isset($array_cookie['url'])) {
                 $this->_stlupload_main($array_cookie['name'], $array_cookie['url']);
             } else {
                 $this->_exitWithError500('remote model redirection data invalid');
             }
         } else {
             $this->output->set_header('Location: /');
             PrinterLog_logDebug('remote model import entry API failed');
         }
     }
     return;
 }
Exemplo n.º 4
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.º 5
0
function ZimAPI_sendMandrillEmail($array_senddata)
{
    $send_context = NULL;
    $result = NULL;
    $json_data = array();
    $send_status = FALSE;
    // 	$array_senddata = json_encode($array_senddata);
    $send_context = stream_context_create(array('http' => array('header' => "Content-type: application/x-www-form-urlencoded", 'method' => 'POST', 'content' => http_build_query($array_senddata), 'ignore_errors' => TRUE)));
    $result = @file_get_contents(ZIMAPI_VALUE_TL_MANDRILL_API, FALSE, $send_context);
    // check response
    if ($result === FALSE || is_null($http_response_header)) {
        return ERROR_NO_PRINT;
        // act as no internet access
    }
    $json_data = json_decode($result, TRUE);
    foreach ($json_data as $json_element) {
        if (is_array($json_element)) {
            if (array_key_exists('status', $json_element) && in_array($json_element['status'], array('sent', 'queued'))) {
                $send_status = TRUE;
            } else {
                $send_status = FALSE;
                break;
            }
        } else {
            if (array_key_exists('status', $json_data) && $json_data['status'] != 'error') {
                $send_status = TRUE;
                break;
            } else {
                break;
            }
        }
    }
    if ($send_status == FALSE) {
        $matches = array();
        $CI =& get_instance();
        $CI->load->helper('printerlog');
        PrinterLog_logError('decode json data return error, return: ' . $result, __FILE__, __LINE__);
        if (count($http_response_header)) {
            preg_match('#HTTP/\\d+\\.\\d+ (\\d+)#', $http_response_header[0], $matches);
            PrinterLog_logDebug('send email mandrill status code: ' . $matches[1], __FILE__, __LINE__);
        }
        return ERROR_INTERNAL;
    } else {
        $CI =& get_instance();
        $CI->load->helper('printerlog');
        PrinterLog_logDebug('send email json: ' . $result, __FILE__, __LINE__);
        // 		PrinterLog_logDebug('send to mandrill json: ' . json_encode($array_senddata));
    }
    return ERROR_OK;
}
Exemplo n.º 6
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);
         }
     }
 }
Exemplo n.º 7
0
 public function connect_facebook($in_upload = NULL)
 {
     if (isset($_POST['fb_title']) && isset($_POST['fb_desc'])) {
         $fb_title = $_POST['fb_title'];
         $fb_desc = $_POST['fb_desc'];
         $_SESSION['fb_title'] = $fb_title;
         $_SESSION['fb_desc'] = $fb_desc;
     } else {
         $fb_title = $_SESSION['fb_title'];
         $fb_desc = $_SESSION['fb_desc'];
     }
     FacebookSession::setDefaultApplication('406642542819370', 'da80c93b500711ba60c79cf943e776e5');
     $helper = new FacebookRedirectLoginHelper("https://sso.zeepro.com/redirectfb.ashx?sn=" . ZimAPI_getSerial());
     $this->load->helper(array('zimapi', 'corestatus', 'printerlog'));
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         // create new session from the existing PHP sesson
         $session = new FacebookSession($_SESSION['fb_token']);
         try {
             // validate the access_token to make sure it's still valid
             if (!$session->validate()) {
                 // try to pick session from redirection if session is invalid or expired, it returns null if it's not a valid redirect
                 // that avoid when we have set session value, but we need re-authenticate from redirection - Peng
                 // 					$session = null;
                 $session = $helper->getSessionFromRedirect();
             }
         } catch (Exception $e) {
             // catch any exceptions and set the sesson null
             $session = null;
             echo 'No session: ' . $e->getMessage();
         }
     } else {
         // the session is empty, we create a new one
         try {
             // the visitor is redirected from the login, let's pickup the session
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $e) {
             // Facebook has returned an error
             echo 'Facebook (session) request error: ' . $e->getMessage();
         } catch (Exception $e) {
             // Any other error
             echo 'Other (session) request error: ' . $e->getMessage();
         }
     }
     if (isset($session)) {
         PrinterLog_logDebug('Facebook upload with session');
         // store the session token into a PHP session
         $_SESSION['fb_token'] = $session->getToken();
         // 			// and create a new Facebook session using the cururent token
         // 			// or from the new token we got after login
         // 			$session = new FacebookSession($session->getToken());
         // connect succeeded, check if we are in uploading call or not (redirection doesn't have in_upload variable in extra path) - Peng
         if ($in_upload == NULL) {
             PrinterLog_logDebug('Facebook connect by getting session from redirection');
             $this->facebook_upload();
             return;
         } else {
             try {
                 $this->lang->load('share/facebook_form', $this->config->item('language'));
                 $this->upload_facebookVideo($fb_title == "" ? t('fb_title') : $fb_title, $fb_desc == "" ? t('fb_desc') : $fb_desc);
             } catch (FacebookRequestException $e) {
                 // show any error for this facebook request
                 echo 'Facebook (post) request error: ' . $e->getMessage();
                 PrinterLog_logDebug('Facebook (post) request error: ' . $e->getMessage());
             }
         }
     } else {
         $loginUrl = $helper->getLoginUrl(array('publish_actions'));
         $prefix = CoreStatus_checkTromboning() ? 'https://' : 'http://';
         $data = array('printersn' => ZimAPI_getSerial(), 'URL' => $prefix . $_SERVER['HTTP_HOST'] . '/share/connect_facebook');
         $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
         $context = stream_context_create($options);
         @file_get_contents('https://sso.zeepro.com/url.ashx', false, $context);
         $result = substr($http_response_header[0], 9, 3);
         echo "{$loginUrl}";
         PrinterLog_logDebug('Facebook login url: ' . $loginUrl);
         $this->output->set_status_header(202);
     }
 }
Exemplo n.º 8
0
function Slicer_exportAll(&$path_model, &$path_config)
{
    $cr = 0;
    $ret_val = 0;
    $response = NULL;
    $path_model = NULL;
    $path_config = NULL;
    $ret_val = Slicer__requestSlicer(SLICER_URL_EXPORT_ALL, FALSE, $response);
    switch ($ret_val) {
        case SLICER_RESPONSE_OK:
            // 		case SLICER_RESPONSE_WRONG_PRM:
            $cr = $ret_val;
            break;
        case SLICER_RESPONSE_NO_MODEL:
            $cr = ERROR_EMPTY_PLATFORM;
            break;
        default:
            $cr = ERROR_INTERNAL;
            break;
    }
    if ($cr == ERROR_OK) {
        $explode_array = explode("\n", $response);
        if (isset($explode_array[1]) && isset($explode_array[2])) {
            $path_config = $explode_array[1];
            $path_model = $explode_array[2];
            foreach (array($path_config, $path_model) as $path_check) {
                if (!file_exists($path_check)) {
                    $CI =& get_instance();
                    $CI->load->helper('printerlog');
                    PrinterLog_logDebug('export all not found: ' . $path_check, __FILE__, __LINE__);
                    $cr = ERROR_INTERNAL;
                }
            }
        } else {
            $cr = ERROR_INTERNAL;
        }
    }
    return $cr;
}
Exemplo n.º 9
0
 function restart_ajax()
 {
     $ret_val = 0;
     $display = NULL;
     $action = $this->input->get('action');
     $this->load->helper('slicer');
     if (Slicer_checkOnline(FALSE)) {
         $this->output->set_status_header(202, 'Opened');
         return;
     } else {
         if ($action) {
             $this->load->helper('printerlog');
             PrinterLog_logDebug('restarting slicer', __FILE__, __LINE__);
             Slicer_restart();
         }
     }
     $display = 200 . " " . t(MyERRMSG(200));
     $this->output->set_status_header(200, $display);
     return;
 }
Exemplo n.º 10
0
function PrinterStoring_printStl($id)
{
    global $CFG;
    $CI =& get_instance();
    $CI->load->helper('slicer');
    $info_file = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_INFO_JSON;
    try {
        $name_stl1 = NULL;
        //		$str = file_get_contents($info_file);
        if (($str = @file_get_contents($info_file)) === false || ($info = json_decode($str, true)) != TRUE || !array_key_exists('name', $info)) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('stl model id not found', __FILE__, __LINE__);
            return ERROR_UNKNOWN_MODEL;
        }
        Slicer_checkOnline(TRUE);
        // extract, copy model file(s) to tmp and addModel to slicer
        $model_file1 = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_STL1_BZ2;
        $name_stl1 = PrinterStoring__generateFilename($info['name'] . PRINTERSTORING_FILE_STL1_EXT);
        if (($file_path = PrinterStoring__extractFile($model_file1, $name_stl1)) !== null) {
            //stats info
            $CI->load->helper('printerlog');
            if ($info[PRINTERSTORING_TITLE_MULTI_STL] === true) {
                $name_stl2 = NULL;
                $model_file2 = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_STL2_BZ2;
                $name_stl2 = PrinterStoring__generateFilename($info['name'] . PRINTERSTORING_FILE_STL2_EXT);
                if (($file2_path = PrinterStoring__extractFile($model_file2, $name_stl2)) !== null) {
                    //stats info
                    PrinterLog_statsLibrarySTL(PRINTERLOG_STATS_LABEL_PRINT, 2);
                    return Slicer_addModel(array($file_path, $file2_path), FALSE);
                } else {
                    $CI->load->helper('printerlog');
                    PrinterLog_logError('could not extract the stl model', __FILE__, __LINE__);
                    return ERROR_INTERNAL;
                }
            } else {
                //stats info
                PrinterLog_statsLibrarySTL(PRINTERLOG_STATS_LABEL_PRINT, 1);
                return Slicer_addModel(array($file_path), FALSE);
            }
        } else {
            $CI->load->helper('printerlog');
            PrinterLog_logDebug('after name: ' . $name_stl1);
            PrinterLog_logError('could not extract the stl model', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
    } catch (Exception $e) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('stl model print error', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    return ERROR_OK;
}
Exemplo n.º 11
0
function Printer__changeGcode(&$gcode_path, $array_filament = array(), $exchange_extruder = FALSE, &$array_temper = array(), $temper_material = FALSE)
{
    $temp_r = 0;
    // right normal temper
    $temp_rs = 0;
    // right start temper
    $temp_l = 0;
    // left normal temper
    $temp_ls = 0;
    // left start temper
    $temp_b = isset($array_temper['b']) && $array_temper['b'] > 0 ? $array_temper['b'] : 0;
    // bed temper
    $cr = 0;
    $command = NULL;
    $output = array();
    $json_cartridge = array();
    $CI =& get_instance();
    $CI->load->helper('printerstate');
    if ($exchange_extruder) {
        $command = $CI->config->item('gcdaemon') . PRINTER_PRM_EXCHANGE_E . PRINTER_PRM_FILE . $gcode_path . ' > ' . $gcode_path . '.new';
        // debug message for test
        $CI->load->helper('printerlog');
        PrinterLog_logDebug('change extruder: ' . $command, __FILE__, __LINE__);
        @unlink($gcode_path . '.new');
        // delete old file
        exec($command, $output, $cr);
        if ($cr != ERROR_NORMAL_RC_OK) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('change extruder error', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
        $gcode_path = $gcode_path . '.new';
    }
    // temporary change - make it possible to change temperature not according to cartridge
    //TODO remove me when it is necessary
    if (array_key_exists('r', $array_temper) && $array_temper['r'] > 0) {
        $temp_r = $array_temper['r'];
        $temp_rs = $temp_r + 10;
        // 		if ($temp_r > $temp_rs) {
        // 			$temp_rs = $temp_r;
        // 		}
    } else {
        if (!array_key_exists('r', $array_filament) || $array_filament['r'] <= 0) {
            // ignore the cartridge which we do not need
            $CI->load->helper('slicer');
            $temp_r = SLICER_VALUE_DEFAULT_TEMPER;
            $temp_rs = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
        } else {
            $cr = PrinterState_getCartridgeAsArray($json_cartridge, 'r');
            if ($cr == ERROR_OK) {
                if ($temper_material) {
                    //TODO need to reunion all getting temperature functions
                    switch ($json_cartridge[PRINTERSTATE_TITLE_MATERIAL]) {
                        case PRINTERSTATE_DESP_MATERIAL_PLA:
                            $temp_rs = PRINTERSTATE_VALUE_FILAMENT_PLA_LOAD_TEMPER;
                            break;
                        case PRINTERSTATE_DESP_MATERIAL_ABS:
                            $temp_rs = PRINTERSTATE_VALUE_FILAMENT_ABS_LOAD_TEMPER;
                            break;
                        case PRINTERSTATE_DESP_MATERIAL_PVA:
                            $temp_rs = PRINTERSTATE_VALUE_FILAMENT_PVA_LOAD_TEMPER;
                            break;
                        default:
                            PrinterLog_logError('unknown filament type in priming', __FILE__, __LINE__);
                            // 						return ERROR_INTERNAL;
                            $temp_rs = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
                            break;
                    }
                    $temp_r = $temp_rs;
                } else {
                    $temp_r = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER];
                    $temp_rs = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1];
                }
            } else {
                if ($cr == ERROR_MISS_RIGT_CART) {
                    $CI->load->helper('slicer');
                    $temp_r = SLICER_VALUE_DEFAULT_TEMPER;
                    $temp_rs = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
                    // 			$temp_r = $temp_rs = PRINTER_VALUE_DEFAULT_TEMPER;
                }
            }
        }
    }
    if ($temp_r * $temp_rs == 0) {
        // we have at least one value not initialised to call change temper program
        return $cr == ERROR_OK ? ERROR_INTERNAL : $cr;
    } else {
        $array_temper['r'] = $temp_r;
    }
    if ($CI->config->item('nb_extruder') >= 2) {
        // make it possible to change temperature not according to cartridge
        if (array_key_exists('l', $array_temper) && $array_temper['l'] > 0) {
            $temp_l = $array_temper['l'];
            $temp_ls = $temp_l + 10;
        } else {
            if (!array_key_exists('l', $array_filament) || $array_filament['l'] <= 0) {
                // ignore the cartridge which we do not need
                $CI->load->helper('slicer');
                $temp_l = SLICER_VALUE_DEFAULT_TEMPER;
                $temp_ls = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
            } else {
                $cr = PrinterState_getCartridgeAsArray($json_cartridge, 'l');
                if ($cr == ERROR_OK) {
                    if ($temper_material) {
                        //TODO need to reunion all getting temperature functions
                        switch ($json_cartridge[PRINTERSTATE_TITLE_MATERIAL]) {
                            case PRINTERSTATE_DESP_MATERIAL_PLA:
                                $temp_ls = PRINTERSTATE_VALUE_FILAMENT_PLA_LOAD_TEMPER;
                                break;
                            case PRINTERSTATE_DESP_MATERIAL_ABS:
                                $temp_ls = PRINTERSTATE_VALUE_FILAMENT_ABS_LOAD_TEMPER;
                                break;
                            case PRINTERSTATE_DESP_MATERIAL_PVA:
                                $temp_ls = PRINTERSTATE_VALUE_FILAMENT_PVA_LOAD_TEMPER;
                                break;
                            default:
                                PrinterLog_logError('unknown filament type in priming', __FILE__, __LINE__);
                                // 							return ERROR_INTERNAL;
                                $temp_ls = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
                                break;
                        }
                        $temp_l = $temp_ls;
                    } else {
                        $temp_l = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER];
                        $temp_ls = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1];
                    }
                } else {
                    if ($cr == ERROR_MISS_LEFT_CART) {
                        $CI->load->helper('slicer');
                        $temp_l = SLICER_VALUE_DEFAULT_TEMPER;
                        $temp_ls = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
                    }
                }
            }
        }
        if ($temp_l * $temp_ls == 0) {
            // we have at least one value not initialised to call change temper program
            return $cr == ERROR_OK ? ERROR_INTERNAL : $cr;
        } else {
            $array_temper['l'] = $temp_l;
        }
    }
    $command = $CI->config->item('gcdaemon') . PRINTER_PRM_TEMPER_R_F . $temp_rs . PRINTER_PRM_TEMPER_R_N . $temp_r . PRINTER_PRM_TEMPER_L_F . $temp_ls . PRINTER_PRM_TEMPER_L_N . $temp_l . PRINTER_PRM_TEMPER_BED . $temp_b . PRINTER_PRM_FILE . $gcode_path . ' > ' . $gcode_path . '.new';
    // debug message for test
    $CI->load->helper('printerlog');
    PrinterLog_logDebug('change temperature: ' . $command, __FILE__, __LINE__);
    @unlink($gcode_path . '.new');
    // delete old file
    exec($command, $output, $cr);
    if ($cr != ERROR_NORMAL_RC_OK) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('change temperature error', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    $gcode_path = $gcode_path . '.new';
    return ERROR_OK;
}
Exemplo n.º 12
0
function PrinterState__updateCartridge(&$code_cartridge, $abb_cartridge)
{
    $CI =& get_instance();
    $file_path = $CI->config->item('base_data') . PRINTERSTATE_FILE_UPDATE_RFID;
    if (file_exists($file_path)) {
        $data_json = array();
        $temp_code = NULL;
        try {
            $CI->load->helper('json');
            $tmp_array = @json_read($file_path, TRUE);
            if ($tmp_array['error']) {
                throw new Exception('read json error');
            } else {
                $data_json = $tmp_array['json'];
            }
        } catch (Exception $e) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('read cartridge update data error', __FILE__, __LINE__);
            return;
            // log error and return
        }
        $temp_code = substr($code_cartridge, 0, 26);
        if (array_key_exists($temp_code, $data_json)) {
            $temp_hex = 0;
            $ret_val = 0;
            $CI->load->helper('printerlog');
            PrinterLog_logDebug('detected a cartridge to update', __FILE__, __LINE__);
            // add date in the end
            $temp_code = $data_json[$temp_code] . substr($code_cartridge, 26, 4);
            // calculate checksum
            for ($i = 0; $i <= 14; $i++) {
                $string_tmp = substr($temp_code, $i * 2, 2);
                $hex_tmp = hexdec($string_tmp);
                $temp_hex = $temp_hex ^ $hex_tmp;
            }
            $temp_hex = dechex($temp_hex);
            if (strlen($temp_hex) == 1) {
                $temp_hex = '0' . $temp_hex;
            }
            $temp_code .= strtoupper($temp_hex);
            $code_cartridge = $temp_code;
            $ret_val = PrinterState_setCartridgeCode($temp_code, $abb_cartridge);
            if ($ret_val != ERROR_OK) {
                // log error and return
                $CI->load->helper('printerlog');
                PrinterLog_logError('write cartridge error when in updating cartridge from database', __FILE__, __LINE__);
            }
        }
    }
    return;
}