package b4a.example;

import java.net.NetworkInterface;
import java.util.Collections;
import java.util.List;
import java.net.InetAddress;
import java.net.Inet6Address;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;

import anywheresoftware.b4a.B4AMenuItem;
import android.app.Activity;
import android.os.Bundle;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.B4AActivity;
import anywheresoftware.b4a.ObjectWrapper;
import anywheresoftware.b4a.objects.ActivityWrapper;
import java.lang.reflect.InvocationTargetException;
import anywheresoftware.b4a.B4AUncaughtException;
import anywheresoftware.b4a.debug.*;
import java.lang.ref.WeakReference;

public class main extends Activity implements B4AActivity{
	public static main mostCurrent;
	static boolean afterFirstLayout;
	static boolean isFirst = true;
    private static boolean processGlobalsRun = false;
	BALayout layout;
	public static BA processBA;
	BA activityBA;
    ActivityWrapper _activity;
    java.util.ArrayList<B4AMenuItem> menuItems;
	public static final boolean fullScreen = false;
	public static final boolean includeTitle = true;
    public static WeakReference<Activity> previousOne;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        mostCurrent = this;
		if (processBA == null) {
			processBA = new anywheresoftware.b4a.ShellBA(this.getApplicationContext(), null, null, "b4a.example", "b4a.example.main");
			processBA.loadHtSubs(this.getClass());
	        float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
	        BALayout.setDeviceScale(deviceScale);
            
		}
		else if (previousOne != null) {
			Activity p = previousOne.get();
			if (p != null && p != this) {
                BA.LogInfo("Killing previous instance (main).");
				p.finish();
			}
		}
        processBA.setActivityPaused(true);
        processBA.runHook("oncreate", this, null);
		if (!includeTitle) {
        	this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
        	getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
        			android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
		
        processBA.sharedProcessBA.activityBA = null;
		layout = new BALayout(this);
		setContentView(layout);
		afterFirstLayout = false;
        WaitForLayout wl = new WaitForLayout();
        if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(this, processBA, wl, false))
		    BA.handler.postDelayed(wl, 5);

	}
	static class WaitForLayout implements Runnable {
		public void run() {
			if (afterFirstLayout)
				return;
			if (mostCurrent == null)
				return;
            
			if (mostCurrent.layout.getWidth() == 0) {
				BA.handler.postDelayed(this, 5);
				return;
			}
			mostCurrent.layout.getLayoutParams().height = mostCurrent.layout.getHeight();
			mostCurrent.layout.getLayoutParams().width = mostCurrent.layout.getWidth();
			afterFirstLayout = true;
			mostCurrent.afterFirstLayout();
		}
	}
	private void afterFirstLayout() {
        if (this != mostCurrent)
			return;
		activityBA = new BA(this, layout, processBA, "b4a.example", "b4a.example.main");
        
        processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
        anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
        _activity = new ActivityWrapper(activityBA, "activity");
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (BA.isShellModeRuntimeCheck(processBA)) {
			if (isFirst)
				processBA.raiseEvent2(null, true, "SHELL", false);
			processBA.raiseEvent2(null, true, "CREATE", true, "b4a.example.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
			_activity.reinitializeForShell(activityBA, "activity");
		}
        initializeProcessGlobals();		
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create, isFirst = " + isFirst + " **");
        processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
		isFirst = false;
		if (this != mostCurrent)
			return;
        processBA.setActivityPaused(false);
        BA.LogInfo("** Activity (main) Resume **");
        processBA.raiseEvent(null, "activity_resume");
        if (android.os.Build.VERSION.SDK_INT >= 11) {
			try {
				android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	public void addMenuItem(B4AMenuItem item) {
		if (menuItems == null)
			menuItems = new java.util.ArrayList<B4AMenuItem>();
		menuItems.add(item);
	}
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		super.onCreateOptionsMenu(menu);
        try {
            if (processBA.subExists("activity_actionbarhomeclick")) {
                Class.forName("android.app.ActionBar").getMethod("setHomeButtonEnabled", boolean.class).invoke(
                    getClass().getMethod("getActionBar").invoke(this), true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (processBA.runHook("oncreateoptionsmenu", this, new Object[] {menu}))
            return true;
		if (menuItems == null)
			return false;
		for (B4AMenuItem bmi : menuItems) {
			android.view.MenuItem mi = menu.add(bmi.title);
			if (bmi.drawable != null)
				mi.setIcon(bmi.drawable);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
				try {
                    if (bmi.addToBar) {
				        android.view.MenuItem.class.getMethod("setShowAsAction", int.class).invoke(mi, 1);
                    }
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			mi.setOnMenuItemClickListener(new B4AMenuItemsClickListener(bmi.eventName.toLowerCase(BA.cul)));
		}
        
		return true;
	}   
 @Override
 public boolean onOptionsItemSelected(android.view.MenuItem item) {
    if (item.getItemId() == 16908332) {
        processBA.raiseEvent(null, "activity_actionbarhomeclick");
        return true;
    }
    else
        return super.onOptionsItemSelected(item); 
}
@Override
 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
    super.onPrepareOptionsMenu(menu);
    processBA.runHook("onprepareoptionsmenu", this, new Object[] {menu});
    return true;
    
 }
 protected void onStart() {
    super.onStart();
    processBA.runHook("onstart", this, null);
}
 protected void onStop() {
    super.onStop();
    processBA.runHook("onstop", this, null);
}
    public void onWindowFocusChanged(boolean hasFocus) {
       super.onWindowFocusChanged(hasFocus);
       if (processBA.subExists("activity_windowfocuschanged"))
           processBA.raiseEvent2(null, true, "activity_windowfocuschanged", false, hasFocus);
    }
	private class B4AMenuItemsClickListener implements android.view.MenuItem.OnMenuItemClickListener {
		private final String eventName;
		public B4AMenuItemsClickListener(String eventName) {
			this.eventName = eventName;
		}
		public boolean onMenuItemClick(android.view.MenuItem item) {
			processBA.raiseEventFromUI(item.getTitle(), eventName + "_click");
			return true;
		}
	}
    public static Class<?> getObject() {
		return main.class;
	}
    private Boolean onKeySubExist = null;
    private Boolean onKeyUpSubExist = null;
	@Override
	public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeydown", this, new Object[] {keyCode, event}))
            return true;
		if (onKeySubExist == null)
			onKeySubExist = processBA.subExists("activity_keypress");
		if (onKeySubExist) {
			if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK &&
					android.os.Build.VERSION.SDK_INT >= 18) {
				HandleKeyDelayed hk = new HandleKeyDelayed();
				hk.kc = keyCode;
				BA.handler.post(hk);
				return true;
			}
			else {
				boolean res = new HandleKeyDelayed().runDirectly(keyCode);
				if (res)
					return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	private class HandleKeyDelayed implements Runnable {
		int kc;
		public void run() {
			runDirectly(kc);
		}
		public boolean runDirectly(int keyCode) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keypress", false, keyCode);
			if (res == null || res == true) {
                return true;
            }
            else if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK) {
				finish();
				return true;
			}
            return false;
		}
		
	}
    @Override
	public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeyup", this, new Object[] {keyCode, event}))
            return true;
		if (onKeyUpSubExist == null)
			onKeyUpSubExist = processBA.subExists("activity_keyup");
		if (onKeyUpSubExist) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keyup", false, keyCode);
			if (res == null || res == true)
				return true;
		}
		return super.onKeyUp(keyCode, event);
	}
	@Override
	public void onNewIntent(android.content.Intent intent) {
        super.onNewIntent(intent);
		this.setIntent(intent);
        processBA.runHook("onnewintent", this, new Object[] {intent});
	}
    @Override 
	public void onPause() {
		super.onPause();
        if (_activity == null)
            return;
        if (this != mostCurrent)
			return;
		anywheresoftware.b4a.Msgbox.dismiss(true);
        BA.LogInfo("** Activity (main) Pause, UserClosed = " + activityBA.activity.isFinishing() + " **");
        if (mostCurrent != null)
            processBA.raiseEvent2(_activity, true, "activity_pause", false, activityBA.activity.isFinishing());		
        processBA.setActivityPaused(true);
        mostCurrent = null;
        if (!activityBA.activity.isFinishing())
			previousOne = new WeakReference<Activity>(this);
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        processBA.runHook("onpause", this, null);
	}

	@Override
	public void onDestroy() {
        super.onDestroy();
		previousOne = null;
        processBA.runHook("ondestroy", this, null);
	}
    @Override 
	public void onResume() {
		super.onResume();
        mostCurrent = this;
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (activityBA != null) { //will be null during activity create (which waits for AfterLayout).
        	ResumeMessage rm = new ResumeMessage(mostCurrent);
        	BA.handler.post(rm);
        }
        processBA.runHook("onresume", this, null);
	}
    private static class ResumeMessage implements Runnable {
    	private final WeakReference<Activity> activity;
    	public ResumeMessage(Activity activity) {
    		this.activity = new WeakReference<Activity>(activity);
    	}
		public void run() {
            main mc = mostCurrent;
			if (mc == null || mc != activity.get())
				return;
			processBA.setActivityPaused(false);
            BA.LogInfo("** Activity (main) Resume **");
            if (mc != mostCurrent)
                return;
		    processBA.raiseEvent(mc._activity, "activity_resume", (Object[])null);
		}
    }
	@Override
	protected void onActivityResult(int requestCode, int resultCode,
	      android.content.Intent data) {
		processBA.onActivityResult(requestCode, resultCode, data);
        processBA.runHook("onactivityresult", this, new Object[] {requestCode, resultCode});
	}
	private static void initializeGlobals() {
		processBA.raiseEvent2(null, true, "globals", false, (Object[])null);
	}
    public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
        for (int i = 0;i < permissions.length;i++) {
            Object[] o = new Object[] {permissions[i], grantResults[i] == 0};
            processBA.raiseEventFromDifferentThread(null,null, 0, "activity_permissionresult", true, o);
        }
            
    }



public static void initializeProcessGlobals() {
    
    if (main.processGlobalsRun == false) {
	    main.processGlobalsRun = true;
		try {
		        		
        } catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
}
public static boolean isAnyActivityVisible() {
    boolean vis = false;
vis = vis | (main.mostCurrent != null);
return vis;}

private static BA killProgramHelper(BA ba) {
    if (ba == null)
        return null;
    anywheresoftware.b4a.BA.SharedProcessBA sharedProcessBA = ba.sharedProcessBA;
    if (sharedProcessBA == null || sharedProcessBA.activityBA == null)
        return null;
    return sharedProcessBA.activityBA.get();
}
public static void killProgram() {
     {
            Activity __a = null;
            if (main.previousOne != null) {
				__a = main.previousOne.get();
			}
            else {
                BA ba = killProgramHelper(main.mostCurrent == null ? null : main.mostCurrent.processBA);
                if (ba != null) __a = ba.activity;
            }
            if (__a != null)
				__a.finish();}

BA.applicationContext.stopService(new android.content.Intent(BA.applicationContext, starter.class));
BA.applicationContext.stopService(new android.content.Intent(BA.applicationContext, get_data.class));
}
public static class _mymessage{
public boolean IsInitialized;
public String Name;
public int Age;
public byte[] Image;
public void Initialize() {
IsInitialized = true;
Name = "";
Age = 0;
Image = new byte[0];
;
}
@Override
		public String toString() {
			return BA.TypeToString(this, false);
		}}
public anywheresoftware.b4a.keywords.Common __c = null;
public static anywheresoftware.b4a.randomaccessfile.B4XSerializator _ser = null;
public static anywheresoftware.b4a.objects.RuntimePermissions _rp = null;
public anywheresoftware.b4a.objects.FloatLabeledEditTextWrapper _edtip = null;
public anywheresoftware.b4a.objects.LabelWrapper _lblmyip = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnconnect = null;
public anywheresoftware.b4a.objects.LabelWrapper _lblstatus = null;
public anywheresoftware.b4a.objects.FloatLabeledEditTextWrapper _edtage = null;
public anywheresoftware.b4a.objects.FloatLabeledEditTextWrapper _edtname = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnsend = null;
public anywheresoftware.b4a.objects.drawable.CanvasWrapper _cvs = null;
public anywheresoftware.b4a.objects.PanelWrapper _pnldrawing = null;
public anywheresoftware.b4a.agraham.byteconverter.ByteConverter _bconv = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btn_ping = null;
public wifi.MLwifi _conf_wifi = null;
public anywheresoftware.b4a.objects.ListViewWrapper _listview1 = null;
public b4a.example.b4xbytesbuilder _bb = null;
public anywheresoftware.b4a.objects.FloatLabeledEditTextWrapper _edtpass = null;
public anywheresoftware.b4a.objects.FloatLabeledEditTextWrapper _edttlog = null;
public static String _password = "";
public static String _login = "";
public adr.stringfunctions.stringfunctions _strutil = null;
public b4a.example.starter _starter = null;
public b4a.example.get_data _get_data = null;
public b4a.example.b4xcollections _b4xcollections = null;
public static String  _activity_create(boolean _firsttime) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "activity_create", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "activity_create", new Object[] {_firsttime}));}
RDebugUtils.currentLine=131072;
 //BA.debugLineNum = 131072;BA.debugLine="Sub Activity_Create(FirstTime As Boolean)";
RDebugUtils.currentLine=131075;
 //BA.debugLineNum = 131075;BA.debugLine="Activity.LoadLayout(\"1\")";
mostCurrent._activity.LoadLayout("1",mostCurrent.activityBA);
RDebugUtils.currentLine=131076;
 //BA.debugLineNum = 131076;BA.debugLine="cvs.Initialize(pnlDrawing)";
mostCurrent._cvs.Initialize((android.view.View)(mostCurrent._pnldrawing.getObject()));
RDebugUtils.currentLine=131080;
 //BA.debugLineNum = 131080;BA.debugLine="edtIp.Text=\"192.168.0.21\"";
mostCurrent._edtip.setText((Object)("192.168.0.21"));
RDebugUtils.currentLine=131082;
 //BA.debugLineNum = 131082;BA.debugLine="StartService(Get_data)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._get_data.getObject()));
RDebugUtils.currentLine=131094;
 //BA.debugLineNum = 131094;BA.debugLine="End Sub";
return "";
}
public static String  _activity_pause(boolean _userclosed) throws Exception{
RDebugUtils.currentModule="main";
RDebugUtils.currentLine=262144;
 //BA.debugLineNum = 262144;BA.debugLine="Sub Activity_Pause (UserClosed As Boolean)";
RDebugUtils.currentLine=262146;
 //BA.debugLineNum = 262146;BA.debugLine="End Sub";
return "";
}
public static String  _activity_resume() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "activity_resume", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "activity_resume", null));}
RDebugUtils.currentLine=196608;
 //BA.debugLineNum = 196608;BA.debugLine="Sub Activity_Resume";
RDebugUtils.currentLine=196609;
 //BA.debugLineNum = 196609;BA.debugLine="SetState";
_setstate();
RDebugUtils.currentLine=196610;
 //BA.debugLineNum = 196610;BA.debugLine="End Sub";
return "";
}
public static String  _setstate() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "setstate", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "setstate", null));}
RDebugUtils.currentLine=720896;
 //BA.debugLineNum = 720896;BA.debugLine="Public Sub SetState";
RDebugUtils.currentLine=720897;
 //BA.debugLineNum = 720897;BA.debugLine="btnSend.Enabled = Starter.connected";
mostCurrent._btnsend.setEnabled(mostCurrent._starter._connected /*boolean*/ );
RDebugUtils.currentLine=720899;
 //BA.debugLineNum = 720899;BA.debugLine="If Starter.connected Then";
if (mostCurrent._starter._connected /*boolean*/ ) { 
RDebugUtils.currentLine=720900;
 //BA.debugLineNum = 720900;BA.debugLine="btnConnect.Text = \"Disconnect\"";
mostCurrent._btnconnect.setText(BA.ObjectToCharSequence("Disconnect"));
RDebugUtils.currentLine=720901;
 //BA.debugLineNum = 720901;BA.debugLine="lblStatus.Text = \"Connected\"";
mostCurrent._lblstatus.setText(BA.ObjectToCharSequence("Connected"));
 }else {
RDebugUtils.currentLine=720903;
 //BA.debugLineNum = 720903;BA.debugLine="btnConnect.Text = \"Connect\"";
mostCurrent._btnconnect.setText(BA.ObjectToCharSequence("Connect"));
RDebugUtils.currentLine=720904;
 //BA.debugLineNum = 720904;BA.debugLine="lblStatus.Text = \"Disconnected\"";
mostCurrent._lblstatus.setText(BA.ObjectToCharSequence("Disconnected"));
 };
RDebugUtils.currentLine=720906;
 //BA.debugLineNum = 720906;BA.debugLine="lblMyIp.Text = \"My ip: \" & Starter.server.GetMyWi";
mostCurrent._lblmyip.setText(BA.ObjectToCharSequence("My ip: "+mostCurrent._starter._server /*anywheresoftware.b4a.objects.SocketWrapper.ServerSocketWrapper*/ .GetMyWifiIP()));
RDebugUtils.currentLine=720907;
 //BA.debugLineNum = 720907;BA.debugLine="End Sub";
return "";
}
public static String  _btn_ping_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btn_ping_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "btn_ping_click", null));}
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.keywords.StringBuilderWrapper _sb = null;
int _i = 0;
anywheresoftware.b4a.keywords.StringBuilderWrapper _stdout = null;
anywheresoftware.b4a.keywords.StringBuilderWrapper _stderr = null;
String[] _list1 = null;
anywheresoftware.b4a.objects.collections.List _list = null;
String _data = "";
String[] _list2 = null;
RDebugUtils.currentLine=1179648;
 //BA.debugLineNum = 1179648;BA.debugLine="Sub Btn_ping_Click";
RDebugUtils.currentLine=1179649;
 //BA.debugLineNum = 1179649;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
RDebugUtils.currentLine=1179650;
 //BA.debugLineNum = 1179650;BA.debugLine="Dim sb As StringBuilder";
_sb = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
RDebugUtils.currentLine=1179651;
 //BA.debugLineNum = 1179651;BA.debugLine="sb.Initialize";
_sb.Initialize();
RDebugUtils.currentLine=1179654;
 //BA.debugLineNum = 1179654;BA.debugLine="For i = 1 To 50";
{
final int step4 = 1;
final int limit4 = (int) (50);
_i = (int) (1) ;
for (;_i <= limit4 ;_i = _i + step4 ) {
RDebugUtils.currentLine=1179656;
 //BA.debugLineNum = 1179656;BA.debugLine="p.Shell(\"ping -c1 -n1 192.168.0.\" & i ,Null,sb,N";
_p.Shell("ping -c1 -n1 192.168.0."+BA.NumberToString(_i),(String[])(anywheresoftware.b4a.keywords.Common.Null),(java.lang.StringBuilder)(_sb.getObject()),(java.lang.StringBuilder)(anywheresoftware.b4a.keywords.Common.Null));
 }
};
RDebugUtils.currentLine=1179663;
 //BA.debugLineNum = 1179663;BA.debugLine="Dim stdout As StringBuilder";
_stdout = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
RDebugUtils.currentLine=1179664;
 //BA.debugLineNum = 1179664;BA.debugLine="stdout.Initialize";
_stdout.Initialize();
RDebugUtils.currentLine=1179665;
 //BA.debugLineNum = 1179665;BA.debugLine="Dim stderr As StringBuilder";
_stderr = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
RDebugUtils.currentLine=1179666;
 //BA.debugLineNum = 1179666;BA.debugLine="stderr.Initialize";
_stderr.Initialize();
RDebugUtils.currentLine=1179668;
 //BA.debugLineNum = 1179668;BA.debugLine="Try";
try {RDebugUtils.currentLine=1179669;
 //BA.debugLineNum = 1179669;BA.debugLine="p.Shell(\"cat\", Array As String(\"/proc/net/arp\"),";
_p.Shell("cat",new String[]{"/proc/net/arp"},(java.lang.StringBuilder)(_stdout.getObject()),(java.lang.StringBuilder)(_stderr.getObject()));
RDebugUtils.currentLine=1179670;
 //BA.debugLineNum = 1179670;BA.debugLine="Dim list1() As String= Regex.Split(Chr(10),stdou";
_list1 = anywheresoftware.b4a.keywords.Common.Regex.Split(BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (10))),BA.ObjectToString(_stdout));
RDebugUtils.currentLine=1179671;
 //BA.debugLineNum = 1179671;BA.debugLine="Dim list As List";
_list = new anywheresoftware.b4a.objects.collections.List();
RDebugUtils.currentLine=1179673;
 //BA.debugLineNum = 1179673;BA.debugLine="list.Initialize";
_list.Initialize();
RDebugUtils.currentLine=1179674;
 //BA.debugLineNum = 1179674;BA.debugLine="list.Clear";
_list.Clear();
RDebugUtils.currentLine=1179676;
 //BA.debugLineNum = 1179676;BA.debugLine="For Each data As String In list1";
{
final String[] group17 = _list1;
final int groupLen17 = group17.length
;int index17 = 0;
;
for (; index17 < groupLen17;index17++){
_data = group17[index17];
RDebugUtils.currentLine=1179677;
 //BA.debugLineNum = 1179677;BA.debugLine="Dim list2() As String=Regex.Split(\"    \",data)";
_list2 = anywheresoftware.b4a.keywords.Common.Regex.Split("    ",_data);
RDebugUtils.currentLine=1179678;
 //BA.debugLineNum = 1179678;BA.debugLine="If list2(5).Trim <> \"00:00:00:00:00:00\" Then";
if ((_list2[(int) (5)].trim()).equals("00:00:00:00:00:00") == false) { 
RDebugUtils.currentLine=1179679;
 //BA.debugLineNum = 1179679;BA.debugLine="ListView1.AddSingleLine(list2(0).Trim & \";\" &";
mostCurrent._listview1.AddSingleLine(BA.ObjectToCharSequence(_list2[(int) (0)].trim()+";"+_list2[(int) (5)].trim()));
RDebugUtils.currentLine=1179680;
 //BA.debugLineNum = 1179680;BA.debugLine="Log(list2(0).Trim & \";\" & list2(5).Trim)";
anywheresoftware.b4a.keywords.Common.LogImpl("21179680",_list2[(int) (0)].trim()+";"+_list2[(int) (5)].trim(),0);
RDebugUtils.currentLine=1179681;
 //BA.debugLineNum = 1179681;BA.debugLine="list.Add(list2(0).Trim & \";\" & list2(5).Trim)";
_list.Add((Object)(_list2[(int) (0)].trim()+";"+_list2[(int) (5)].trim()));
 };
 }
};
 } 
       catch (Exception e26) {
			processBA.setLastException(e26);RDebugUtils.currentLine=1179690;
 //BA.debugLineNum = 1179690;BA.debugLine="Msgbox(LastException.Message, \"No arp at this ti";
anywheresoftware.b4a.keywords.Common.Msgbox(BA.ObjectToCharSequence(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA).getMessage()),BA.ObjectToCharSequence("No arp at this time"),mostCurrent.activityBA);
 };
RDebugUtils.currentLine=1179706;
 //BA.debugLineNum = 1179706;BA.debugLine="End Sub";
return "";
}
public static String  _btnconnect_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btnconnect_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "btnconnect_click", null));}
RDebugUtils.currentLine=983040;
 //BA.debugLineNum = 983040;BA.debugLine="Sub btnConnect_Click";
RDebugUtils.currentLine=983041;
 //BA.debugLineNum = 983041;BA.debugLine="If Starter.connected = False Then";
if (mostCurrent._starter._connected /*boolean*/ ==anywheresoftware.b4a.keywords.Common.False) { 
RDebugUtils.currentLine=983042;
 //BA.debugLineNum = 983042;BA.debugLine="If edtIp.Text.Length = 0 Then";
if (mostCurrent._edtip.getText().length()==0) { 
RDebugUtils.currentLine=983043;
 //BA.debugLineNum = 983043;BA.debugLine="ToastMessageShow(\"Please enter the server ip ad";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Please enter the server ip address."),anywheresoftware.b4a.keywords.Common.True);
RDebugUtils.currentLine=983044;
 //BA.debugLineNum = 983044;BA.debugLine="Return";
if (true) return "";
 }else {
RDebugUtils.currentLine=983046;
 //BA.debugLineNum = 983046;BA.debugLine="CallSub2(Starter, \"ConnectToServer\", edtIp.Text";
anywheresoftware.b4a.keywords.Common.CallSubDebug2(processBA,(Object)(mostCurrent._starter.getObject()),"ConnectToServer",(Object)(mostCurrent._edtip.getText()));
 };
 }else {
RDebugUtils.currentLine=983049;
 //BA.debugLineNum = 983049;BA.debugLine="CallSub(Starter, \"Disconnect\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(mostCurrent._starter.getObject()),"Disconnect");
 };
RDebugUtils.currentLine=983051;
 //BA.debugLineNum = 983051;BA.debugLine="End Sub";
return "";
}
public static void  _btnsend_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btnsend_click", false))
	 {Debug.delegate(mostCurrent.activityBA, "btnsend_click", null); return;}
ResumableSub_btnSend_Click rsub = new ResumableSub_btnSend_Click(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_btnSend_Click extends BA.ResumableSub {
public ResumableSub_btnSend_Click(b4a.example.main parent) {
this.parent = parent;
}
b4a.example.main parent;
String _data_file_command = "";
String _data_file_read_conso = "";
String _conf_network = "";
String _tplink_entete = "";
byte[] _data_array = null;
String _file_name = "";
boolean _result = false;

@Override
public void resume(BA ba, Object[] result) throws Exception{
RDebugUtils.currentModule="main";

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
RDebugUtils.currentLine=851981;
 //BA.debugLineNum = 851981;BA.debugLine="bb.Initialize";
parent.mostCurrent._bb._initialize /*String*/ (null,processBA);
RDebugUtils.currentLine=851984;
 //BA.debugLineNum = 851984;BA.debugLine="Dim data_file_command As String=\"on_ascii2.txt\"";
_data_file_command = "on_ascii2.txt";
RDebugUtils.currentLine=851985;
 //BA.debugLineNum = 851985;BA.debugLine="Dim data_file_read_conso As String=\"Demande_conso";
_data_file_read_conso = "Demande_conso_live.txt";
RDebugUtils.currentLine=851986;
 //BA.debugLineNum = 851986;BA.debugLine="Dim conf_Network As String=\"network_conf_ascii_en";
_conf_network = "network_conf_ascii_entete.txt";
RDebugUtils.currentLine=851987;
 //BA.debugLineNum = 851987;BA.debugLine="Dim tplink_entete As String=\"Tplink_ascii_entete0";
_tplink_entete = "Tplink_ascii_entete0_ascii.txt";
RDebugUtils.currentLine=851988;
 //BA.debugLineNum = 851988;BA.debugLine="Dim data_array() As Byte";
_data_array = new byte[(int) (0)];
;
RDebugUtils.currentLine=851989;
 //BA.debugLineNum = 851989;BA.debugLine="Dim file_name As String=tplink_entete";
_file_name = _tplink_entete;
RDebugUtils.currentLine=851994;
 //BA.debugLineNum = 851994;BA.debugLine="login=edttLog.Text";
parent.mostCurrent._login = parent.mostCurrent._edttlog.getText();
RDebugUtils.currentLine=851995;
 //BA.debugLineNum = 851995;BA.debugLine="Password=edtpass.text";
parent.mostCurrent._password = parent.mostCurrent._edtpass.getText();
RDebugUtils.currentLine=852002;
 //BA.debugLineNum = 852002;BA.debugLine="If login.Contains(\"&\") Then";
if (true) break;

case 1:
//if
this.state = 4;
if (parent.mostCurrent._login.contains("&")) { 
this.state = 3;
}if (true) break;

case 3:
//C
this.state = 4;
RDebugUtils.currentLine=852003;
 //BA.debugLineNum = 852003;BA.debugLine="login=StrUtil.Stuff(login,\"\\u0026\",\"&\")";
parent.mostCurrent._login = parent.mostCurrent._strutil._vvvvvvv2(parent.mostCurrent._login,"\\u0026","&");
 if (true) break;
;
RDebugUtils.currentLine=852006;
 //BA.debugLineNum = 852006;BA.debugLine="If login.Contains(\"'\") Then";

case 4:
//if
this.state = 7;
if (parent.mostCurrent._login.contains("'")) { 
this.state = 6;
}if (true) break;

case 6:
//C
this.state = 7;
RDebugUtils.currentLine=852007;
 //BA.debugLineNum = 852007;BA.debugLine="login=StrUtil.Stuff(login,\"\\u0027\",\"&\")";
parent.mostCurrent._login = parent.mostCurrent._strutil._vvvvvvv2(parent.mostCurrent._login,"\\u0027","&");
 if (true) break;
;
RDebugUtils.currentLine=852011;
 //BA.debugLineNum = 852011;BA.debugLine="If Password.Contains(\"&\") Then";

case 7:
//if
this.state = 10;
if (parent.mostCurrent._password.contains("&")) { 
this.state = 9;
}if (true) break;

case 9:
//C
this.state = 10;
RDebugUtils.currentLine=852012;
 //BA.debugLineNum = 852012;BA.debugLine="Password= StrUtil.Stuff(Password,\"\\u0026\",\"&\")";
parent.mostCurrent._password = parent.mostCurrent._strutil._vvvvvvv2(parent.mostCurrent._password,"\\u0026","&");
 if (true) break;
;
RDebugUtils.currentLine=852015;
 //BA.debugLineNum = 852015;BA.debugLine="If Password.Contains(\"'\") Then";

case 10:
//if
this.state = 13;
if (parent.mostCurrent._password.contains("'")) { 
this.state = 12;
}if (true) break;

case 12:
//C
this.state = 13;
RDebugUtils.currentLine=852016;
 //BA.debugLineNum = 852016;BA.debugLine="Password= StrUtil.Stuff(Password,\"\\u0027\",\"&\")";
parent.mostCurrent._password = parent.mostCurrent._strutil._vvvvvvv2(parent.mostCurrent._password,"\\u0027","&");
 if (true) break;

case 13:
//C
this.state = -1;
;
RDebugUtils.currentLine=852031;
 //BA.debugLineNum = 852031;BA.debugLine="Wait For (load_data(file_name)) complete (result";
anywheresoftware.b4a.keywords.Common.WaitFor("complete", processBA, new anywheresoftware.b4a.shell.DebugResumableSub.DelegatableResumableSub(this, "main", "btnsend_click"), _load_data(_file_name));
this.state = 14;
return;
case 14:
//C
this.state = -1;
_result = (Boolean) result[0];
;
RDebugUtils.currentLine=852034;
 //BA.debugLineNum = 852034;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static anywheresoftware.b4a.keywords.Common.ResumableSubWrapper  _load_data(String _file_name) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "load_data", false))
	 {return ((anywheresoftware.b4a.keywords.Common.ResumableSubWrapper) Debug.delegate(mostCurrent.activityBA, "load_data", new Object[] {_file_name}));}
ResumableSub_load_data rsub = new ResumableSub_load_data(null,_file_name);
rsub.resume(processBA, null);
return (anywheresoftware.b4a.keywords.Common.ResumableSubWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.keywords.Common.ResumableSubWrapper(), rsub);
}
public static class ResumableSub_load_data extends BA.ResumableSub {
public ResumableSub_load_data(b4a.example.main parent,String _file_name) {
this.parent = parent;
this._file_name = _file_name;
}
b4a.example.main parent;
String _file_name;
anywheresoftware.b4a.objects.streams.File.InputStreamWrapper _reader = null;
byte[] _data_array = null;

@Override
public void resume(BA ba, Object[] result) throws Exception{
RDebugUtils.currentModule="main";

    while (true) {
try {

        switch (state) {
            case -1:
{
anywheresoftware.b4a.keywords.Common.ReturnFromResumableSub(this,null);return;}
case 0:
//C
this.state = 1;
RDebugUtils.currentLine=917506;
 //BA.debugLineNum = 917506;BA.debugLine="Dim reader As InputStream = File.OpenInput(File.D";
_reader = new anywheresoftware.b4a.objects.streams.File.InputStreamWrapper();
_reader = anywheresoftware.b4a.keywords.Common.File.OpenInput(anywheresoftware.b4a.keywords.Common.File.getDirDefaultExternal(),_file_name);
RDebugUtils.currentLine=917507;
 //BA.debugLineNum = 917507;BA.debugLine="Dim data_array(reader.BytesAvailable) As Byte";
_data_array = new byte[_reader.BytesAvailable()];
;
RDebugUtils.currentLine=917509;
 //BA.debugLineNum = 917509;BA.debugLine="Try";
if (true) break;

case 1:
//try
this.state = 6;
this.catchState = 5;
this.state = 3;
if (true) break;

case 3:
//C
this.state = 6;
this.catchState = 5;
RDebugUtils.currentLine=917510;
 //BA.debugLineNum = 917510;BA.debugLine="reader.ReadBytes(data_array,0,reader.BytesAvaila";
_reader.ReadBytes(_data_array,(int) (0),_reader.BytesAvailable());
RDebugUtils.currentLine=917511;
 //BA.debugLineNum = 917511;BA.debugLine="bconv.LittleEndian=False";
parent.mostCurrent._bconv.setLittleEndian(anywheresoftware.b4a.keywords.Common.False);
RDebugUtils.currentLine=917512;
 //BA.debugLineNum = 917512;BA.debugLine="encode_data(data_array)";
_encode_data(_data_array);
RDebugUtils.currentLine=917513;
 //BA.debugLineNum = 917513;BA.debugLine="Dim data_array(bb.Length) As Byte";
_data_array = new byte[parent.mostCurrent._bb._getlength /*int*/ (null)];
;
RDebugUtils.currentLine=917514;
 //BA.debugLineNum = 917514;BA.debugLine="data_array=bb.SubArray(0)";
_data_array = parent.mostCurrent._bb._subarray /*byte[]*/ (null,(int) (0));
RDebugUtils.currentLine=917516;
 //BA.debugLineNum = 917516;BA.debugLine="CallSub2(Starter, \"SendData\", data_array)";
anywheresoftware.b4a.keywords.Common.CallSubDebug2(processBA,(Object)(parent.mostCurrent._starter.getObject()),"SendData",(Object)(_data_array));
RDebugUtils.currentLine=917517;
 //BA.debugLineNum = 917517;BA.debugLine="NewData(data_array)";
_newdata(_data_array);
RDebugUtils.currentLine=917518;
 //BA.debugLineNum = 917518;BA.debugLine="Return True";
if (true) {
anywheresoftware.b4a.keywords.Common.ReturnFromResumableSub(this,(Object)(anywheresoftware.b4a.keywords.Common.True));return;};
 if (true) break;

case 5:
//C
this.state = 6;
this.catchState = 0;
RDebugUtils.currentLine=917520;
 //BA.debugLineNum = 917520;BA.debugLine="Log(LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("2917520",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA)),0);
RDebugUtils.currentLine=917521;
 //BA.debugLineNum = 917521;BA.debugLine="Return False";
if (true) {
anywheresoftware.b4a.keywords.Common.ReturnFromResumableSub(this,(Object)(anywheresoftware.b4a.keywords.Common.False));return;};
 if (true) break;
if (true) break;

case 6:
//C
this.state = -1;
this.catchState = 0;
;
RDebugUtils.currentLine=917526;
 //BA.debugLineNum = 917526;BA.debugLine="End Sub";
if (true) break;
}} 
       catch (Exception e0) {
			
if (catchState == 0)
    throw e0;
else {
    state = catchState;
processBA.setLastException(e0);}
            }
        }
    }
}
public static String  _encode_data(byte[] _data) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "encode_data", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "encode_data", new Object[] {_data}));}
int _key = 0;
byte[] _data_next = null;
int _data_byte_encrypted = 0;
String _network = "";
String _scan_network = "";
String _get_info = "";
String _set_off = "";
String _other = "";
String _conso_live = "";
String _get_time = "";
byte[] _entete_format = null;
byte _data2 = (byte)0;
byte[] _data3 = null;
byte _data1 = (byte)0;
byte[] _byte1 = null;
RDebugUtils.currentLine=1114112;
 //BA.debugLineNum = 1114112;BA.debugLine="Sub encode_data(data() As Byte)";
RDebugUtils.currentLine=1114113;
 //BA.debugLineNum = 1114113;BA.debugLine="Dim key As Int=144  '144 'Dernier octet encodé de";
_key = (int) (144);
RDebugUtils.currentLine=1114115;
 //BA.debugLineNum = 1114115;BA.debugLine="Dim data_next() As Byte";
_data_next = new byte[(int) (0)];
;
RDebugUtils.currentLine=1114116;
 //BA.debugLineNum = 1114116;BA.debugLine="Dim data_byte_encrypted As Int";
_data_byte_encrypted = 0;
RDebugUtils.currentLine=1114121;
 //BA.debugLineNum = 1114121;BA.debugLine="Dim network As String= Chr(34) & \"netif\" & Chr(34";
_network = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"netif"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"set_stainfo"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"key_type"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+"3"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (44)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"password"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+mostCurrent._password+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (44)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"ssid"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+mostCurrent._login+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114122;
 //BA.debugLineNum = 1114122;BA.debugLine="Dim scan_network As String= Chr(34) & \"netif\" & C";
_scan_network = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"netif"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"get_scaninfo"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"refresh"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+"1"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114123;
 //BA.debugLineNum = 1114123;BA.debugLine="Dim get_info As String=  Chr(34) & \"system\" & Chr";
_get_info = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"system"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"get_sysinfo"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114124;
 //BA.debugLineNum = 1114124;BA.debugLine="Dim set_off As String= Chr(34) & \"system\" & Chr(3";
_set_off = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"system"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"set_relay_state"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"state"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+"1"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114125;
 //BA.debugLineNum = 1114125;BA.debugLine="Dim other As String= Chr(34) & \"system\" & Chr(34)";
_other = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"system"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"set_led_off"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"off"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+"0"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114126;
 //BA.debugLineNum = 1114126;BA.debugLine="Dim conso_live As String= Chr(34) & \"emeter\" & Ch";
_conso_live = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"emeter"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"get_realtime"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114127;
 //BA.debugLineNum = 1114127;BA.debugLine="Dim get_time As String= Chr(34) & \"time\" & Chr(34";
_get_time = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"time"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+"get_time"+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (34)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (58)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (123)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)))+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (125)));
RDebugUtils.currentLine=1114129;
 //BA.debugLineNum = 1114129;BA.debugLine="data_next= bconv.StringToBytes(network,\"ASCII\")";
_data_next = mostCurrent._bconv.StringToBytes(_network,"ASCII");
RDebugUtils.currentLine=1114132;
 //BA.debugLineNum = 1114132;BA.debugLine="Dim entete_format(4) As Byte";
_entete_format = new byte[(int) (4)];
;
RDebugUtils.currentLine=1114134;
 //BA.debugLineNum = 1114134;BA.debugLine="entete_format(3)=data_next.Length + data.Length '";
_entete_format[(int) (3)] = (byte) (_data_next.length+_data.length);
RDebugUtils.currentLine=1114136;
 //BA.debugLineNum = 1114136;BA.debugLine="bb.Append(entete_format)";
mostCurrent._bb._append /*b4a.example.b4xbytesbuilder*/ (null,_entete_format);
RDebugUtils.currentLine=1114138;
 //BA.debugLineNum = 1114138;BA.debugLine="For Each data2 As Byte In data";
{
final byte[] group15 = _data;
final int groupLen15 = group15.length
;int index15 = 0;
;
for (; index15 < groupLen15;index15++){
_data2 = group15[index15];
RDebugUtils.currentLine=1114139;
 //BA.debugLineNum = 1114139;BA.debugLine="Dim data3(1) As Byte";
_data3 = new byte[(int) (1)];
;
RDebugUtils.currentLine=1114140;
 //BA.debugLineNum = 1114140;BA.debugLine="data3(0)=data2";
_data3[(int) (0)] = _data2;
RDebugUtils.currentLine=1114141;
 //BA.debugLineNum = 1114141;BA.debugLine="bb.Append(data3)";
mostCurrent._bb._append /*b4a.example.b4xbytesbuilder*/ (null,_data3);
 }
};
RDebugUtils.currentLine=1114147;
 //BA.debugLineNum = 1114147;BA.debugLine="For Each data1 As Byte In data_next";
{
final byte[] group20 = _data_next;
final int groupLen20 = group20.length
;int index20 = 0;
;
for (; index20 < groupLen20;index20++){
_data1 = group20[index20];
RDebugUtils.currentLine=1114148;
 //BA.debugLineNum = 1114148;BA.debugLine="data_byte_encrypted=Bit.Xor(data1,key) 'Mask FF";
_data_byte_encrypted = anywheresoftware.b4a.keywords.Common.Bit.Xor((int) (_data1),_key);
RDebugUtils.currentLine=1114149;
 //BA.debugLineNum = 1114149;BA.debugLine="Dim byte1(1) As Byte";
_byte1 = new byte[(int) (1)];
;
RDebugUtils.currentLine=1114150;
 //BA.debugLineNum = 1114150;BA.debugLine="byte1(0)=data_byte_encrypted";
_byte1[(int) (0)] = (byte) (_data_byte_encrypted);
RDebugUtils.currentLine=1114151;
 //BA.debugLineNum = 1114151;BA.debugLine="key=byte1(0)";
_key = (int) (_byte1[(int) (0)]);
RDebugUtils.currentLine=1114152;
 //BA.debugLineNum = 1114152;BA.debugLine="bb.Append(byte1)";
mostCurrent._bb._append /*b4a.example.b4xbytesbuilder*/ (null,_byte1);
 }
};
RDebugUtils.currentLine=1114156;
 //BA.debugLineNum = 1114156;BA.debugLine="End Sub";
return "";
}
public static String  _newdata(byte[] _data) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "newdata", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "newdata", new Object[] {_data}));}
int _key = 0;
int _data_byte_decrypted = 0;
int _pos = 0;
String _message = "";
byte[] _byte1 = null;
String _carac = "";
RDebugUtils.currentLine=1048576;
 //BA.debugLineNum = 1048576;BA.debugLine="Public Sub NewData (data() As Byte)";
RDebugUtils.currentLine=1048578;
 //BA.debugLineNum = 1048578;BA.debugLine="Dim key As Int=171";
_key = (int) (171);
RDebugUtils.currentLine=1048580;
 //BA.debugLineNum = 1048580;BA.debugLine="Dim data_byte_decrypted As Int";
_data_byte_decrypted = 0;
RDebugUtils.currentLine=1048581;
 //BA.debugLineNum = 1048581;BA.debugLine="Dim pos As Int=0";
_pos = (int) (0);
RDebugUtils.currentLine=1048584;
 //BA.debugLineNum = 1048584;BA.debugLine="Dim message As String=\"\"";
_message = "";
RDebugUtils.currentLine=1048585;
 //BA.debugLineNum = 1048585;BA.debugLine="For pos = 4 To data.Length-1";
{
final int step5 = 1;
final int limit5 = (int) (_data.length-1);
_pos = (int) (4) ;
for (;_pos <= limit5 ;_pos = _pos + step5 ) {
RDebugUtils.currentLine=1048587;
 //BA.debugLineNum = 1048587;BA.debugLine="data_byte_decrypted=Bit.Xor(Bit.And(data(pos), 0";
_data_byte_decrypted = anywheresoftware.b4a.keywords.Common.Bit.Xor(anywheresoftware.b4a.keywords.Common.Bit.And((int) (_data[_pos]),(int) (0xff)),_key);
RDebugUtils.currentLine=1048588;
 //BA.debugLineNum = 1048588;BA.debugLine="Dim byte1(1) As Byte";
_byte1 = new byte[(int) (1)];
;
RDebugUtils.currentLine=1048589;
 //BA.debugLineNum = 1048589;BA.debugLine="byte1(0)=data_byte_decrypted";
_byte1[(int) (0)] = (byte) (_data_byte_decrypted);
RDebugUtils.currentLine=1048591;
 //BA.debugLineNum = 1048591;BA.debugLine="Dim carac As String = bconv.StringFromBytes(byte";
_carac = mostCurrent._bconv.StringFromBytes(_byte1,"ASCII");
RDebugUtils.currentLine=1048592;
 //BA.debugLineNum = 1048592;BA.debugLine="key=data(pos)";
_key = (int) (_data[_pos]);
RDebugUtils.currentLine=1048593;
 //BA.debugLineNum = 1048593;BA.debugLine="message=message & carac";
_message = _message+_carac;
RDebugUtils.currentLine=1048594;
 //BA.debugLineNum = 1048594;BA.debugLine="bb.Append(byte1)";
mostCurrent._bb._append /*b4a.example.b4xbytesbuilder*/ (null,_byte1);
 }
};
RDebugUtils.currentLine=1048597;
 //BA.debugLineNum = 1048597;BA.debugLine="Log(message)";
anywheresoftware.b4a.keywords.Common.LogImpl("21048597",_message,0);
RDebugUtils.currentLine=1048614;
 //BA.debugLineNum = 1048614;BA.debugLine="End Sub";
return "";
}
public static String  _test_stream() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "test_stream", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "test_stream", null));}
RDebugUtils.currentLine=786432;
 //BA.debugLineNum = 786432;BA.debugLine="Sub test_stream";
RDebugUtils.currentLine=786434;
 //BA.debugLineNum = 786434;BA.debugLine="End Sub";
return "";
}
public static String getWifiMacAddress() {
  try {
  String interfaceName = "wlan0";
  List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
  for (NetworkInterface intf : interfaces) {
BA.Log("" + intf);
  byte[] mac = intf.getHardwareAddress();
  if (mac==null){
  continue;
  }

  StringBuilder buf = new StringBuilder();
  for (byte aMac : mac) {
  buf.append(String.format("%02X:", aMac));
  }
  if (buf.length()>0) {
  buf.deleteCharAt(buf.length() - 1);
  }
 
  BA.Log(buf.toString());
  }
  } catch (Exception ex) {
  ex.printStackTrace();
  }
  return "";
  }

public static String getIp(String interfaceName) throws Exception {
  for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
     NetworkInterface ni = e.nextElement();
     if (ni.getName().equals(interfaceName)) {
       Enumeration<InetAddress> en2 = ni.getInetAddresses();
       while (en2.hasMoreElements()) {
         InetAddress ia = en2.nextElement();
         if (!ia.isLoopbackAddress()) {
           if ((ia instanceof Inet6Address) == false) {
             return ia.getHostAddress();
           }
         }
       }
     }
  }
    return "";
  }
 
}