User Tools

Site Tools


zalozeni:classes:configurationinitializer

ConfigurationInitializer

Trida ConfigurationInitializer zprostredkovava inicializaci vsech Instrumentu a jazykovych balicku specifickych pro tyto instrumenty. Detaily ohledne jazykovych balicku jsou popsany v dalsim kroku. Ted je hlavni metoda initInstrument().

Instrument se konfiguruje zpravidla ze souboru config.ini, ktery v sobe nese informace o pripojeni k jednotlivym Device unvitr Instrumentu (IP adresy, typ pripojeni…). Behem teto konfigurace se vytvari objektova reprezentace jednotlivych pripojeni

ModBusTcpConnection eurothermConnection = new ModBusTcpConnection(addr, 1, dokuwikiInstrument.getEurotherm());
DokuwikiLabJackT7Connection labjackConnection = new DokuwikiLabJackT7Connection(iniConf.getLabJackTYPE(), 
	iniConf.getLabJackTYPE(),
	iniConf.getLabJackTYPE(), 
	dokuwikiInstrument.getLabjack());

a rovnez se tato pripojeni prirazuji patricnym Device. Device jsou prirazeny Instrumentu jiz v ramci konstruktoru Instrumentu.

public class DokuwikiInitializer implements ConfigurationInitializer {
 
	public List<Instrument> initInstruments() {
		DokuwikiConfigIni iniConf = new DokuwikiConfigIni();
 
		List<Instrument> instruments = new ArrayList<Instrument>();
 
		DokuwikiInstrument dokuwikiInstrument = new DokuwikiInstrument();
 
		InetAddress addr = null;
		try {
			addr = InetAddress.getByName(iniConf.getEurothermIP());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
 
		ModBusTcpConnection eurothermConnection = new ModBusTcpConnection(addr, 1, dokuwikiInstrument.getEurotherm());
		dokuwikiInstrument.getEurotherm().setConnection(eurothermConnection);
 
		DokuwikiLabJackT7Connection labjackConnection = new DokuwikiLabJackT7Connection(iniConf.getLabJackTYPE(), iniConf.getLabJackTYPE(),
				iniConf.getLabJackTYPE(), dokuwikiInstrument.getLabjack());
		dokuwikiInstrument.getLabjack().setConnection(labjackConnection);
 
		dokuwikiInstrument.setName("Dokuwiki test instrument");
		dokuwikiInstrument.setDescription(dokuwikiInstrument.getName());
 
		instruments.add(dokuwikiInstrument);
 
		return instruments;
	}
 
	public void initLanguage() {
		I18n.getGraphicsBundle().addBundle(ResourceBundle.getBundle("cz.jlochman.marklar.dokuwiki.language.bundles.graphics"));
		I18n.getMsgBundle().addBundle(ResourceBundle.getBundle("cz.jlochman.marklar.dokuwiki.language.bundles.msg"));
	}
 
}

Vedle uvedenych metod poskytuje interface ConfigurationInitializer metodu

	public default Set<Class<?>> getRestApiClasses() {
		return null;
	};

Samotne jadro poskytuje ve tride CoreAPI api pro zakladni komunikaci s instrumentem. Konkretni implementace metody getClasses() by mela vypadat nasledovne

@Override
public Set<Class<?>> getClasses() {
	HashSet<Class<?>> classes = new HashSet<Class<?>>();
	classes.add(CoreAPI.class);
	// add more classes
	return classes;
}

kde CoreAPI.class je nasledujici trida

@Path("core")
public class CoreAPI {
	@GET
	@Path("testGetParam")
	public String testGetParameter(@QueryParam("number") int number) {
		return "" + (2 * number);
	}	
 
	@PUT
	@Path("testPutParam")
	public String testPutParameter(@FormParam("formParam") String sForm) {
		return sForm;
	}
}

URI k metodam testGetParameter a testPutParameter pak maji podobu marklar/core/testGetParam?number=2 a marklar/core/testPutParam.

zalozeni/classes/configurationinitializer.txt · Last modified: 2016/10/19 14:09 by jlochman