walangkaji / ztef

ZTE F Series API - F609 F670
10 stars 4 forks source link

Add Feature: ```userInterface()->wlan()``` and ```wlan()->associatedDevices()``` #2

Closed kura1420 closed 1 year ago

kura1420 commented 1 year ago

mas izin bantu review misal sempet,

add const di Request

public const STATUS_WLAN          = self::PARAM . 'status_wlanm_info1_t.gch';
public const ACCESS_CONTROL_LIST  = self::PARAM . 'net_wlanm_assoc1_t.gch';

add method findTransferMeaning di file Utils.php

public static function findTransferMeaning(string $content, string $findWord, string $start, string $end)
    {
        $explode = explode('Transfer_meaning', $content);

        $return = NULL;
        foreach ($explode as $key => $value) {
            if (str_contains($value, $findWord)) {
                // $content = trim($value);
                // $start = strlen($start);
                // $end = strlen($end);

                // $return = substr($content, $start, -$end);
                return explode("'", trim($value))[3];
            }
        }

        return $return;
    }

get list devices on method associatedDevices

public function associatedDevices()
    {
        $session = Utils::getSession($this->request(self::ACCESS_CONTROL_LIST)->getRawResponse());
        $request = $this->request(self::ACCESS_CONTROL_LIST)
            ->addPosts([
                // 'WLAN_SSID0' => 'IGD.LD1.WLAN1',
                // 'WLAN_SSID1' => 'IGD.LD1.WLAN2',
                // 'WLAN_SSID2' => 'IGD.LD1.WLAN3',
                // 'WLAN_SSID3' => 'IGD.LD1.WLAN4',
                'IF_VIEWID' => 'IGD.LD1.WLAN1', // di hardcode, harusnya pake combobox
                '_SESSION_TOKEN' => $session,
            ])
            ->getRawResponse();

        $context   = (new Document($request))->text();

        $devices = [];
        for ($i=0; $i <= 32; $i++) { 
            $deviceAvaliable = Utils::findTransferMeaning($context, 'ADMACAddress'. $i, "('ADMACAddress". $i ."','", "');");
            if ($deviceAvaliable) {

                $devices[] = [
                    'ADMACAddress' . $i => $deviceAvaliable,
                    'DeviceName' . $i => Utils::findTransferMeaning($context, 'DeviceName'. $i, "('DeviceName". $i ."','", "');"),
                    'ADIPAddress' . $i => Utils::findTransferMeaning($context, 'ADIPAddress'. $i, "('ADIPAddress". $i ."','", "');"),
                    'MCS' . $i => Utils::findTransferMeaning($context, 'MCS'. $i, "('MCS". $i ."','", "');"),
                    'RSSI' . $i => Utils::findTransferMeaning($context, 'RSSI'. $i, "('RSSI". $i ."','", "');"),
                    'TXRate' . $i => Utils::findTransferMeaning($context, 'TXRate'. $i, "('TXRate". $i ."','", "');"),
                    'RXRate' . $i => Utils::findTransferMeaning($context, 'RXRate'. $i, "('RXRate". $i ."','", "');"),
                    'CurrentMode' . $i => Utils::findTransferMeaning($context, 'CurrentMode'. $i, "('CurrentMode". $i ."','", "');"),
                ];
            }
        }

        return $devices;
    }

add method wlans di UserInterface

public function wlans(): array
    {
        $request = $this->request(Request::STATUS_WLAN)->getRawResponse();
        $context   = (new Document($request))->text();

        $wlans = [];
        for ($i=0; $i < 4; $i++) { 
            $wlans[]['wlan_'.$i] = [
                'Enable' . $i => Utils::findTransferMeaning($context, 'Enable'. $i, "('Enable". $i ."','", "');"),
                'ChannelInUsed' . $i => Utils::findTransferMeaning($context, 'ChannelInUsed'. $i, "('ChannelInUsed". $i ."','", "');"),
                'ESSID' . $i => Utils::findTransferMeaning($context, 'ESSID'. $i, "('ESSID". $i ."','", "');"),
                'TotalBytesReceived' . $i => Utils::findTransferMeaning($context, 'TotalBytesReceived'. $i, "('TotalBytesReceived". $i ."','", "');"),
                'TotalBytesSent' . $i => Utils::findTransferMeaning($context, 'TotalBytesSent'. $i, "('TotalBytesSent". $i ."','", "');"),
                'ErrorsReceived' . $i => Utils::findTransferMeaning($context, 'ErrorsReceived'. $i, "('ErrorsReceived". $i ."','", "');"),
                'ErrorsSent' . $i => Utils::findTransferMeaning($context, 'ErrorsSent'. $i, "('ErrorsSent". $i ."','", "');"),
                'DiscardPacketsSent' . $i => Utils::findTransferMeaning($context, 'DiscardPacketsSent'. $i, "('DiscardPacketsSent". $i ."','", "');"),
                'DiscardPacketsReceived' . $i => Utils::findTransferMeaning($context, 'DiscardPacketsReceived'. $i, "('DiscardPacketsReceived". $i ."','", "');"),
                'RealRF' . $i => Utils::findTransferMeaning($context, 'RealRF'. $i, "('RealRF". $i ."','", "');"),
            ];
        }

        return $wlans;
    }
walangkaji commented 1 year ago

ini model modem apa mas? f609 kah? dan ini untuk mendapatkan Associated Devices ?

kura1420 commented 1 year ago

Iya betul mas zte-f609 mas, kebetulan dirumah pake itu. Klo yg lain blum tau

walangkaji commented 1 year ago

baik mas, nanti coba tak cek'e ya, fitur diatas untuk cek status ssid & dan cek Associated Devices yak?

kura1420 commented 1 year ago

Ya betul mas, fitur yg lain blum sempet

walangkaji commented 1 year ago

silahkan dicoba mas, sudah saya tambahkan, jangan lupa composer update

kura1420 commented 1 year ago

okeh mas, hatur nuhun