function ZimAPI_codePresetHash($raw_name) { $CI =& get_instance(); $CI->load->helper(array('detectos')); if (DectectOS_checkWindows()) { return md5(utf8_encode($raw_name)); } else { return md5($raw_name); } }
function Slicer_sliceHalt($force_remote = FALSE) { $cr = 0; $ret_val = 0; $action_remote = FALSE; $url_remote = NULL; $CI =& get_instance(); $CI->load->helper('printerlog'); if (file_exists(SLICER_FILE_REMOTE_STATUS) || ($force_remote = TRUE)) { // remote slicing $output = array(); $json_status = array(); $command = $CI->config->item('siteutil') . SLICER_CMD_PRM_REMOTE_STOP; $CI->load->helper('json'); $json_status = json_read(SLICER_FILE_REMOTE_STATUS, TRUE); if (!isset($json_status['error']) && isset($json_status['json'][SLICER_TITLE_REMOTE_URL])) { $url_remote = $json_status['json'][SLICER_TITLE_REMOTE_URL]; } else { $url_remote = PRINTERLOG_STATS_VALUE_REMOTE; } if (!DectectOS_checkWindows()) { $command = 'sudo ' . $command; } $action_remote = TRUE; exec($command, $output, $ret_val); if ($ret_val != ERROR_NORMAL_RC_OK) { $CI->load->helper('remote slicing cancel utils command error', __FILE__, __LINE__); $ret_val = SLICER_RESPONSE_ERROR; } else { $ret_val = SLICER_RESPONSE_OK; } } else { // local slicing $ret_val = Slicer__requestSlicer(SLICER_URL_SLICE_HALT); $url_remote = PRINTERLOG_STATS_VALUE_LOCAL; } if ($ret_val == SLICER_RESPONSE_OK) { $CI->load->helper('corestatus'); CoreStatus_setInIdle(); // stats info PrinterLog_statsSlice(PRINTERLOG_STATS_ACTION_CANCEL, array(PRINTERLOG_STATS_SLICE_SERVER => $url_remote)); $cr = ERROR_OK; if ($action_remote == FALSE) { Slicer_restart(); //FIXME remove me as soon as possible } } else { $cr = ERROR_NO_SLICING; } return $cr; }
function Printer_printFromFile($gcode_path, $model_id, $time_estimation, $need_prime = TRUE, $exchange_extruder = FALSE, $array_filament = array(), $array_temper = array()) { global $CFG; $command = ''; $output = array(); $temper_json = array(); $ret_val = 0; $stats_info = array(); $CI =& get_instance(); $CI->load->helper(array('printerstate', 'errorcode', 'corestatus', 'printerlog', 'detectos')); // check if we have no file if (!file_exists($gcode_path)) { return ERROR_INTERNAL; } // only check if we are in printing when we are not called stopping printing // if ($stop_printing == FALSE) { // check if in printing $ret_val = PrinterState_checkInPrint(); if ($ret_val == TRUE) { // return ERROR_IN_PRINT; PrinterLog_logMessage('already in printing', __FILE__, __LINE__); return ERROR_BUSY_PRINTER; } // } // check extruder number if ($CI->config->item('nb_extruder') < 2) { $tmp_array = array(); $command = $CFG->config['gcanalyser'] . $gcode_path; exec($command, $output, $ret_val); if ($ret_val != ERROR_NORMAL_RC_OK) { PrinterLog_logError('gcanalyser error', __FILE__, __LINE__); return ERROR_INTERNAL; } $tmp_array = json_decode($output[0], TRUE); if ($tmp_array['N'] > $CI->config->item('nb_extruder')) { PrinterLog_logMessage('no enough extruder', __FILE__, __LINE__); return ERROR_INTERNAL; } } // check if having enough filament $ret_val = PrinterState_checkFilaments($array_filament); if ($ret_val != ERROR_OK) { return $ret_val; } if ($time_estimation == 0) { $ret_val = Printer__getEstimation($array_filament, $time_estimation); if ($ret_val != TRUE) { PrinterLog_logError('system can not get estimation time'); return ERROR_INTERNAL; } } // prepare subprinting gcode files and scripts $ret_val = Printer_preparePrint($model_id, $need_prime); if ($ret_val != ERROR_OK) { return $ret_val; } // if ($stop_printing == FALSE) { if ($CFG->config['simulator']) { // just set temperature for simulation PrinterState_setExtruder('r'); PrinterState_setTemperature(210); PrinterState_setExtruder('l'); PrinterState_setTemperature(200); PrinterState_setExtruder('r'); } // change status json file foreach ($array_temper as $abb_filament => $tmp_temper) { if ($abb_filament != 'b' && (!array_key_exists($abb_filament, $array_filament) || $array_filament[$abb_filament] <= 0)) { $temper_json[$abb_filament] = NULL; } else { $temper_json[$abb_filament] = $array_temper[$abb_filament]; } } $ret_val = CoreStatus_setInPrinting($model_id, $time_estimation, $exchange_extruder, $temper_json); // } // else { // $ret_val = CoreStatus_setInCanceling(); // } if ($ret_val == FALSE) { return ERROR_INTERNAL; } // stats info $stats_info[PRINTERLOG_STATS_MODEL] = $model_id; foreach ($temper_json as $abb_filament => $tmp_temper) { if (isset($tmp_temper)) { $json_cartridge = array(); $arrkey_type = PRINTERLOG_STATS_FILA_TYPE_R; $arrkey_color = PRINTERLOG_STATS_FILA_COLOR_R; if ($abb_filament == 'l') { $arrkey_type = PRINTERLOG_STATS_FILA_TYPE_L; $arrkey_color = PRINTERLOG_STATS_FILA_COLOR_L; } if (ERROR_OK == PrinterState_getCartridgeAsArray($json_cartridge, $abb_filament)) { $stats_info[$arrkey_type] = $json_cartridge[PRINTERSTATE_TITLE_MATERIAL]; $stats_info[$arrkey_color] = $json_cartridge[PRINTERSTATE_TITLE_COLOR]; } } } PrinterLog_statsPrint(PRINTERLOG_STATS_ACTION_START, $stats_info); // pass gcode to printer // if (!PrinterState_beforeFileCommand()) { // return ERROR_INTERNAL; // } // use different command for priming if ($need_prime == FALSE) { $command = PrinterState_getPrintCommand($array_filament, TRUE, TRUE) . $gcode_path; } else { $command = PrinterState_getPrintCommand($array_filament) . $gcode_path; } // exec($command, $output, $ret_val); // if ($ret_val != ERROR_NORMAL_RC_OK) { // return ERROR_INTERNAL; // } if ($CFG->config['simulator'] && DectectOS_checkWindows()) { pclose(popen($command, 'r')); // only for windows arcontrol client PrinterLog_logArduino($command); } else { // exec($command, $output, $ret_val); pclose(popen($command . ' > ' . PRINTERSTATE_FILE_PRINTLOG . ' &', 'r')); // if (!PrinterState_filterOutput($output)) { // PrinterLog_logError('filter arduino output error', __FILE__, __LINE__); // return ERROR_INTERNAL; // } // if ($ret_val != ERROR_NORMAL_RC_OK) { // return $ret_val; // } // PrinterLog_logArduino($command, $output); PrinterLog_logArduino($command); } // if (!PrinterState_afterFileCommand()) { // return ERROR_INTERNAL; // } return ERROR_OK; }
function ModelList__codeModelName($raw_name) { $CI =& get_instance(); $CI->load->helper(array('detectos')); if (DectectOS_checkWindows()) { return utf8_decode($raw_name); } else { return $raw_name; } }
function PrinterState_powerOff() { $CI =& get_instance(); $arcontrol_fullpath = $CI->config->item('arcontrol_c'); $output = array(); $command = $arcontrol_fullpath . PRINTERSTATE_POWER_OFF; $ret_val = 0; $CI->load->helper('detectos'); if ($CI->config->item('simulator') == FALSE && !DectectOS_checkWindows()) { $command .= ' &'; } else { $command = 'start /B ' . $command; } // stats info $CI->load->helper('printerlog'); PrinterLog_statsPowerOff(); exec($command, $output, $ret_val); PrinterLog_logArduino($command, $output); if ($ret_val != ERROR_NORMAL_RC_OK) { PrinterLog_logError('power off command error', __FILE__, __LINE__); return ERROR_INTERNAL; } return ERROR_OK; }
define('PRINTERLOG_STATS_LABEL_PRINT', 'print'); define('PRINTERLOG_STATS_LABEL_SUPPORT', 'support'); define('PRINTERLOG_STATS_LABEL_UPGRADE', 'upgrade'); define('PRINTERLOG_STATS_LABEL_SHOP', 'shop'); define('PRINTERLOG_STATS_LABEL_3DSLASH', '3dslash'); define('PRINTERLOG_STATS_VALUE_ON', 'on'); define('PRINTERLOG_STATS_VALUE_OFF', 'off'); define('PRINTERLOG_STATS_VALUE_LOCAL', 'local'); define('PRINTERLOG_STATS_VALUE_REMOTE', 'remote'); define('PRINTERLOG_STATS_TEMPFILE_FOLDER', 'php_stats'); define('PRINTERLOG_STATS_TEMPFILE_PREFIX', 'st_'); define('PRINTERLOG_STATS_SITEUTILS_CMD', ' stats '); define('PRINTERLOG_STATS_TMPFILE_SLICE_UPLOAD_END', $CI->config->item('temp') . '/remote_slice/upload_end'); define('PRINTERLOG_STATS_TMPFILE_SLICE_DOWNLOAD_START', $CI->config->item('temp') . '/remote_slice/download_start'); define('PRINTERLOG_STATS_SESSION_GUID_FILE', $CI->config->item('temp') . '/stats_session_guid.txt'); if (DectectOS_checkWindows()) { define('PRINTERLOG_STATS_FILEPATH_OFF', $CI->config->item('conf') . 'stats_off'); define('PRINTERLOG_STATS_FILEPATH_LOG', $CI->config->item('temp') . 'stats.log'); } else { define('PRINTERLOG_STATS_FILEPATH_OFF', '/config/conf/stats_off'); define('PRINTERLOG_STATS_FILEPATH_LOG', '/var/www/tmp/stats.log'); } } // call error list if we want // $CI = &get_instance(); // $CI->load->helper(array ( // 'errorcode', // )); // log for arduino part function PrinterLog_logArduino($command, $output = '') {