private static IZWaveController CreateZWaveController(string port) { var xmlConfig = File.OpenRead(@"ZWave_custom_cmd_classes.xml"); var xmlParser = new ZWaveClassesXmlParser(); var loggerFactory = CreateLogFactory(_logLevelOption); var zwController = new ZWaveSerialController(port, xmlParser.Parse(xmlConfig), loggerFactory); zwController.Connect(); return(zwController); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var dir = Path.GetDirectoryName(typeof(Startup).GetTypeInfo().Assembly.Location); var xmlConfig = File.OpenRead(Path.Combine(dir, "xml/ZWave_custom_cmd_classes.xml")); var xmlParser = new ZWaveClassesXmlParser(); var loggerFactory = new LoggerFactory() .AddConsole(); var zwaveController = new ZWaveSerialController("/dev/tty.usbmodem411", xmlParser.Parse(xmlConfig), loggerFactory); zwaveController.Connect(); var store = new InMemoryManager(); services.AddSingleton <IUpdateableStorage>(store); services.AddSingleton(zwaveController); Task.Run(async() => { var tcs = new CancellationTokenSource(20000); await zwaveController.DiscoverNodes(tcs.Token); await zwaveController.FetchNodeInfo(tcs.Token); var zwaveTripleCollector = new ZWaveTripleCollector(zwaveController, store); zwaveTripleCollector.SaveNodesToStore(); }).Wait(); // Add framework services. services.AddMvcCore() .AddRdfFormatters() .AddMvcOptions(opt => { opt.Filters.Add(new ApiDocumentationFilter()); }); services.AddCors(); }