Ejemplo n.º 1
0
 public function changecartridge_action($mode = '')
 {
     $abb_cartridge = $this->input->get('v');
     if (!$abb_cartridge && !in_array($abb_cartridge, array('l', 'r'))) {
         $this->output->set_status_header(403);
         // invalid request
         return;
     }
     if ($mode == 'unload_r') {
         $mode = 'unload';
     } else {
         if ($mode == 'load_r') {
             $mode = 'load';
         } else {
             if ($mode != 'cancel_unload') {
                 //block request when not in idle
                 $this->load->helper('corestatus');
                 if (CoreStatus_checkInIdle() == FALSE) {
                     $this->output->set_status_header(403);
                     // bad request
                     return;
                 }
             }
         }
     }
     switch ($mode) {
         case 'unload':
             $ret_val = PrinterState_unloadFilament($abb_cartridge);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header($ret_val, MyERRMSG($ret_val));
             }
             break;
         case 'cancel_unload':
             $ret_val = 0;
             @unlink(PRINTERSTATE_FILE_UNLOAD_HEAT);
             $ret_val = CoreStatus_setInIdle();
             if ($ret_val == FALSE) {
                 $this->load->helper('printerlog');
                 PrinterLog_logError('can not set idle after cancelling unloading', __FILE__, __LINE__);
                 $this->output->set_status_header(ERROR_INTERNAL);
             }
             break;
         case 'load':
             $ret_val = PrinterState_loadFilament($abb_cartridge);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header($ret_val);
             }
             break;
         case 'detail':
             $id_model = $this->input->get('id');
             $this->_display_changecartridge_cartridge_detail($abb_cartridge, $id_model);
             break;
         case 'write':
             $ret_val = 0;
             $array_data = array();
             $array_old = array();
             $color = $this->input->get('c');
             $temper = (int) $this->input->get('t');
             $material = (int) $this->input->get('m');
             $length = (int) $this->input->get('l') * 1000;
             $abb_cartridge = $this->input->get('v');
             // get cartridge type from old RFID
             $ret_val = PrinterState_getCartridgeAsArray($array_old, $abb_cartridge, FALSE);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header(403);
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('read rfid error: ' . $ret_val, __FILE__, __LINE__);
                 break;
             }
             // change color from name to hex code
             $this->load->helper('printlist');
             $ret_val = ModelList__changeColorName($color);
             if ($ret_val == ERROR_WRONG_PRM) {
                 $this->output->set_status_header(404);
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('unknown color name: ' . $color, __FILE__, __LINE__);
                 break;
             }
             $color = str_replace('#', '', $color);
             // write RFID card
             $array_data = array(PRINTERSTATE_TITLE_COLOR => $color, PRINTERSTATE_TITLE_EXT_TEMPER => $temper, PRINTERSTATE_TITLE_INITIAL => $length, PRINTERSTATE_TITLE_MATERIAL => $material, PRINTERSTATE_TITLE_CARTRIDGE => $array_old[PRINTERSTATE_TITLE_CARTRIDGE]);
             $ret_val = PrinterState_setCartridgeAsArray($abb_cartridge, $array_data);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header(403);
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('write rfid error: ' . $ret_val, __FILE__, __LINE__);
                 break;
             }
             break;
         default:
             $this->output->set_status_header(403);
             // unknown request
             break;
     }
     return;
 }
Ejemplo n.º 2
0
 public function unload()
 {
     $cr = 0;
     $abb_cartridge = $this->input->get('v');
     $this->load->helper('printerstate');
     if ($abb_cartridge) {
         switch ($abb_cartridge) {
             case 'l':
             case 'r':
                 // 					$temper = 0;
                 // 					$cr = PrinterState_getTemperature($temper, 'e', $abb_cartridge);
                 // 					if ($cr == ERROR_OK && $temper > PRINTERSTATE_VALUE_MAXTEMPER_BEFORE_UNLOAD) {
                 $cr = PrinterState_unloadFilament($abb_cartridge);
                 // 					}
                 // 					else if ($cr == ERROR_OK) {
                 // 						$cr = ERROR_BUSY_PRINTER;
                 // 					}
                 break;
             default:
                 $cr = ERROR_WRONG_PRM;
                 break;
         }
     } else {
         $cr = ERROR_MISS_PRM;
     }
     $this->_return_cr($cr);
     return;
 }