/** * Execute the command. * * @return void */ public function handle() { $ftp = Storage::disk('ftp'); $list = $ftp->files('commands_response'); $count = 0; //$file = $list[0]; foreach ($list as $file) { $filename = basename($file); $this->info(Carbon::now()->toDateTimeString() . " - Processando arquivo {$file}"); if ($content = $ftp->read($file)) { $xml = simplexml_load_string($content); $ftp->delete($file); } $command = CommandXML::where('id_command', xmlGetVal($xml, 'ID_COMMAND'))->first(); $response = new CommandsResponse(); //['command_id', 'fragment_number', '', '', '', '', 'timestamp'] $response->fragment_number = xmlGetVal($xml, 'FRAGMENT_NUMBER', 'int'); $response->fragment_count = xmlGetVal($xml, 'FRAGMENT_COUNT', 'int'); $response->attempt = xmlGetVal($xml, 'ATTEMPT', 'int'); $response->sts_id = xmlGetVal($xml, 'STS_ID', 'int'); $response->timestamp = xmlGetVal($xml, 'STS_TIMESTAMP', 'str'); $response->desc = xmlGetVal($xml, 'DESC', 'str'); $command->Responses()->save($response); $count++; } if ($count > 0) { $this->info("{$count} Respostas de Comandos processadas!"); } else { $this->error("Nenhuma Resposta de Comando encontrada!"); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $ftp = Storage::disk('ftp'); $local = Storage::disk('xml'); $list = $ftp->files('data'); $count = 0; //$file = $list[0]; foreach ($list as $file) { $filename = basename($file); $this->info(Carbon::now()->toDateTimeString() . " - Processando arquivo {$file}"); if ($content = $ftp->read($file)) { $xml = simplexml_load_string($content); $local->put($filename, $content); $ftp->delete($file); } foreach ($xml->xpath('POSITION') as $pos) { $device = Device::where('serial', xmlGetVal($pos, 'FIRMWARE/SERIAL'))->where('model', xmlGetVal($pos, 'FIRMWARE/PROTOCOL'))->first(); $now = Carbon::now(); $date = new Carbon(xmlGetVal($pos, 'GPS/DATE', 'str')); if ($now->timestamp >= $date->timestamp) { // $this->info(xmlGetVal($pos,'FIRMWARE/SERIAL').": usando date"); $prefix = $date->timestamp * 100000; } else { // $this->info(xmlGetVal($pos,'FIRMWARE/SERIAL').":usando now"); $prefix = $now->timestamp * 100000; } $memory_index = xmlGetVal($pos, 'FIRMWARE/MEMORY_INDEX', 'int') + $prefix; $position = array('serial' => xmlGetVal($pos, 'FIRMWARE/SERIAL'), 'model' => xmlGetVal($pos, 'FIRMWARE/PROTOCOL'), 'memory_index' => $memory_index, 'transmission_reason' => xmlGetVal($pos, 'FIRMWARE/TRANSMISSION_REASON', 'int'), 'date' => xmlGetVal($pos, 'GPS/DATE', 'str'), 'power_supply' => xmlGetVal($pos, 'HARDWARE_MONITOR/POWER_SUPPLY', 'float'), 'temperature' => xmlGetVal($pos, 'HARDWARE_MONITOR/TEMPERATURE', 'int'), 'ignition' => xmlGetVal($pos, 'HARDWARE_MONITOR/INPUTS/IGNITION', 'int'), 'panic' => xmlGetVal($pos, 'HARDWARE_MONITOR/INPUTS/PANIC', 'int'), 'battery_charging' => xmlGetVal($pos, 'HARDWARE_MONITOR/FLAG_STATE/BATTERY_CHARGING', 'int'), 'battery_failure' => xmlGetVal($pos, 'HARDWARE_MONITOR/FLAG_STATE/BATTERY_FAILURE', 'int'), 'latitude' => xmlGetVal($pos, 'GPS/LATITUDE', 'float'), 'longitude' => xmlGetVal($pos, 'GPS/LONGITUDE', 'float'), 'speed' => xmlGetVal($pos, 'GPS/SPEED', 'float'), 'hodometer' => xmlGetVal($pos, 'GPS/HODOMETER', 'int'), 'lifetime' => xmlGetVal($pos, 'FIRMWARE/LIFE_TIME', 'int'), 'gps_signal' => xmlGetVal($pos, 'GPS/FLAG_STATE/GPS_SIGNAL', 'int'), 'gps_antenna_failure' => xmlGetVal($pos, 'GPS/FLAG_STATE/GPS_ANTENNA_FAILURE', 'int')); $new = new Position($position); $new->save(); if ($device) { $new->Device()->associate($device); $new->save(); if ($device->has('Vehicle')) { $vehicle = $device->Vehicle; $new->Vehicle()->associate($vehicle); $new->save(); } } //$this->info("Nova posição: ". $new->id); $count++; } } if ($count > 0) { $this->info("{$count} Posicoes encontradas!"); } else { $this->error("Nenhuma Posicao encontrada!"); } }