⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polarr.java

📁 This software transmits data (using TCP/IP) from I/O pins (of the Tini Board - from Dallas Semicondu
💻 JAVA
字号:
import com.dalsemi.onewire.*;
import com.dalsemi.onewire.container.*;
import com.dalsemi.onewire.adapter.*;

public class Polarr  
{
	boolean DEBUG = false;
	
	CommandPolarr cpCommandPolarr;		// clasa CommandPolarr
	TCPConnection tcpcTCPConnection;	// clasa TCPConnection
	DSPortAdapter dspa_adapter;			// adaptorul 1-Wire
	OneWireContainer12 owc_switch;		// switch-ul
	
	public static void main( String[] args)
	{
		final boolean const_DEBUG = false;
		final int const_SendPort = 1000;
		final int const_ReceivePort = 8000;
		final String const_DispatcherIPAddress="192.168.5.136";
		final String const_SwitchAddress="E80000001FDA6512";
	
		// Incarcam setarile default
		boolean liDebug=const_DEBUG;
		int liSendPort=const_SendPort;
		int liReceivePort=const_ReceivePort;
		String ltDispatcherIPAddress=const_DispatcherIPAddress;
		String ltSwitchAddress=const_SwitchAddress;
		// vedem daca exista comenzi in linia de comanda
		if( args.length != 0){
			for( int i = 0; i < args.length; ++i){
				// pt help
				if( "/?".equals( args[i]) || "-help".equals( args[i]) || "--help".equals( args[i])){
					// afisam un help scurt
					System.out.println("");
					System.out.println("help");
					System.out.println("");
					System.out.println("java polarr.tini [-debug] [-remoteip xxx.xxx.xxx.xxx] [-remoteport yyyy] [-hostport zzzz] [-switchaddress pppppppppppppppp]");
					System.out.println("");
					System.out.println("[-debug] - pt a face debug pe consola de Telnet (default fara debug)");
					System.out.println("");
					System.out.println("[-remoteip xxx.xxx.xxx.xxx] - pt a schimba IP-ul telecomenzii polarr (default 192.168.5.136)");
					System.out.println("");
					System.out.println("[-remoteport yyyy] - pt a schimba portul telecomenzii polarr (default 1000)");
					System.out.println("");
					System.out.println("[-hostport zzzz] - pt a schimba portul pe care asculta Tini (default 8000)");
					System.out.println("");
					System.out.println("[-switchaddress pppppppppppppppp] - pt a schimba switch-ului care comanda porturile pe Tini (default E80000001FDA6512)");
					System.out.flush();
					System.gc();
					return;
				}
				// pt debug
				if( "-debug".equals( args[i])){
					liDebug=true;
				}
				else{
					// pt remoteip
					if( "-remoteip".equals( args[i])){
						try { 
							ltDispatcherIPAddress = args[i+1]; 
						}
						catch( NumberFormatException nfe) { /* Ignore */ }
					}
					else{
						// pt remoteport
						if( "-remoteport".equals( args[i])){
							liSendPort=Integer.valueOf(args[i+1]).intValue();
						}
						else{
							// pt hostport
							if( "-hostport".equals( args[i])){
								try { 
									liReceivePort = Integer.valueOf(args[i+1]).intValue(); 
								}
								catch( NumberFormatException nfe) { /* Ignore */ }
							}
							else{
								// pt switchaddress
								if( "-switchaddress".equals( args[i])){
									ltSwitchAddress = args[i+1]; 
								}
							else{
								}
							}
						}
					}
				}
			}
		}
		// instantiem Polarr
		Polarr app=new Polarr(liDebug,const_SendPort,liReceivePort,ltDispatcherIPAddress,ltSwitchAddress);
	}
	public Polarr(boolean Debug,int SendPort,int ReceivePort,String DispatcherIPAddress,String SwitchAddress)
	{
		int liSendPort=SendPort;
		int liReceivePort=ReceivePort;
		String ltDispatcherIPAddress=DispatcherIPAddress;
		String ltSwitchAddress=SwitchAddress;
		
		// out
		if (DEBUG) System.out.println("Polarr: se incep procedurile de pornire.");
		// transferam cele doua variabile in variabile publice
		DEBUG=Debug;
		// out
		if (DEBUG) System.out.println("Polarr: DEBUG="+DEBUG);
		synchronized(this)
		{
			// instantiem CommandPolarr
			cpCommandPolarr=new CommandPolarr(this,DEBUG,3670016,2);
			// comandam DS 2406
			try{
				dspa_adapter=OneWireAccessProvider.getDefaultAdapter();
				dspa_adapter.beginExclusive(true);
				owc_switch=(OneWireContainer12) dspa_adapter.getDeviceContainer(ltSwitchAddress);
				owc_switch.setupContainer(dspa_adapter,ltSwitchAddress);
				byte[] state = owc_switch.readDevice();
				owc_switch.setLatchState(0,true,false,state);
				owc_switch.writeDevice(state);
				// out
				if (DEBUG) System.out.println("Polarr: a fost comandat SWITCH-ul");
			}
			catch(OneWireException owe){
				System.out.println("Polarr: DS 2406 nu s-a putut comanda");
			}
			// instantiem TCPConnection
			tcpcTCPConnection=new TCPConnection(this,DEBUG,liSendPort,liReceivePort,ltDispatcherIPAddress);
			// pornim firul care afiseaza datele
			cpCommandPolarr.start();
			// pornim firul care afiseaza datele
			tcpcTCPConnection.start();
		}
		// out
		System.out.println("Polarr: a pornit.");
	}

	protected void finalize()
	{
		// intrerupe bucla care face sa functioneze aplicatia
		cpCommandPolarr.stop();
		tcpcTCPConnection.stop();
		cpCommandPolarr.destroy();
		tcpcTCPConnection.destroy();
		System.out.println("Polarr a fost oprit.");		try{
			super.finalize();
		}
		catch(Throwable t){}
	}

	public void SendToTcpIP(byte FirstByte,byte SecondeByte)
	{
		byte liFirstByte=FirstByte;
		byte liSecondeByte=SecondeByte;
		synchronized(this)
		{
			if (tcpcTCPConnection!=null)
				tcpcTCPConnection.SendToTcpIP(liFirstByte,liSecondeByte);
		}
	}
	
	public void SendToPorts(int SentData)
	{
		// facem o conversie de la un byte care ne da butonul apasat la
		//       doi bytes care sunt valorile scoase la porturi
		int liSentData;
		int liFirstByte=0;
		int liSecondeByte=0;
		int liTemp;
		liSentData=SentData;
		// ridicam la putere numerele
		if (liSentData>7 && liSentData<=9){
			// al doilea numar
			liTemp=liSentData-8;
			liSecondeByte=1;
			while(liTemp>0){
				liSecondeByte=liSecondeByte*2;
				liTemp--;
			}
		}
		else {
			// primul numar
			liTemp=liSentData;
			liFirstByte=1;
			while(liTemp>0){
				liFirstByte=liFirstByte*2;
				liTemp--;
			}
		}
		synchronized(this)
		{
			if (DEBUG) System.out.println("Polarr: se transmite la port ("+ liFirstByte + ","+ liSecondeByte + ")");
			cpCommandPolarr.SendBytesToPort((byte)(liFirstByte),(byte)(liSecondeByte));
		}
	}
	public void SendActualBytesValue()
	{
		synchronized(this)
		{
			cpCommandPolarr.SendActualBytesValue();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -