summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfcolin2011-11-30 08:59:39 +0000
committerfcolin2011-11-30 08:59:39 +0000
commit4f5cb588bd29d89337a9286d4efdc88536931b32 (patch)
tree07f7d340577c55d20eccfd329ae704ea7636541c
parent34aba3fec072e68324b91a98e6962202c81615ee (diff)
downloadivy-csharp-4f5cb588bd29d89337a9286d4efdc88536931b32.zip
ivy-csharp-4f5cb588bd29d89337a9286d4efdc88536931b32.tar.gz
ivy-csharp-4f5cb588bd29d89337a9286d4efdc88536931b32.tar.bz2
ivy-csharp-4f5cb588bd29d89337a9286d4efdc88536931b32.tar.xz
ajout IvyTransduct
Tool to change message syntaxe based on an xml file
-rw-r--r--IvyTransduct/IvyTransduct.cs105
-rw-r--r--IvyTransduct/IvyTransduct.csproj86
-rw-r--r--IvyTransduct/IvyTransduct.csproj.user9
-rw-r--r--IvyTransduct/transduct_droid.xml48
4 files changed, 248 insertions, 0 deletions
diff --git a/IvyTransduct/IvyTransduct.cs b/IvyTransduct/IvyTransduct.cs
new file mode 100644
index 0000000..b8fc366
--- /dev/null
+++ b/IvyTransduct/IvyTransduct.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using IvyBus;
+using Gnu;
+using System.Xml;
+
+namespace IvyTransduct
+{
+ class IvyTransduct
+ {
+ public const String helpmsg =
+ "usage: IvyProbe [options] filename\n" +
+ "\t-b BUS\tspecifies the Ivy bus domain\n" +
+ "\t-n ivyname (default IvyTransduct)\n" +
+ "\t-d\tdebug\n" +
+ "\t-h\thelp\n\n" +
+ "\t-f filename ( message to transduct)";
+ static Ivy bus;
+ static bool debug = false;
+
+ static void resentCB(object sender, IvyMessageEventArgs args)
+ {
+ IvyApplicationBinding binding = sender as IvyApplicationBinding;
+ foreach (string msg in (List<string>)binding.CallbackArguments[0])
+ {
+ try
+ {
+ string msg_out = string.Format(msg, args.GetArguments());
+ if (debug)
+ Console.WriteLine("resent msg: {0} => {1}", args, msg_out);
+ bus.SendMsg(msg_out);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Error sending msg {0} : {1}", msg, ex.Message);
+ }
+ }
+
+ }
+ static void Main(string[] args)
+ {
+ string domain = Ivy.GetDomain(null);
+
+ string name = "IvyTransduct";
+
+ GetOpt opt = new GetOpt(args, "n:b:dh");
+ Arg a;
+ while ((a = opt.NextArg()) != null)
+ {
+ switch (a.Flag)
+ {
+ case 'd':
+ debug = true;
+ break;
+
+ case 'b':
+ domain = a.Parameter;
+ break;
+
+ case 'n':
+ name = a.Parameter;
+ break;
+
+ case 'h':
+ default:
+ System.Console.Out.WriteLine(helpmsg);
+ System.Environment.Exit(0);
+ break;
+
+ }
+ }
+ bus = new Ivy(name, name + " ready");
+
+ foreach (string filename in opt.Extras)
+ {
+ if (debug)
+ Console.WriteLine("Read File {0}", filename);
+ try
+ {
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.Load(filename);
+ foreach (XmlElement msg in xmlDoc.SelectNodes("/transduct/message"))
+ {
+ string msg_in = msg.SelectSingleNode("input").Attributes["bind"].Value;
+ if (debug) Console.WriteLine("message: " + msg_in);
+ List<string> outputs = new List<string>();
+ foreach ( XmlElement item in msg.SelectNodes( "output/item" ) )
+ {
+ string msg_out = item.Attributes["msg"].Value;
+ if (debug) Console.WriteLine("\t out: " + msg_out);
+ outputs.Add(msg_out);
+ }
+ bus.BindMsg(msg_in, resentCB, outputs);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Error reading file {0} : {1}", filename, ex.Message);
+ }
+ }
+ bus.Start(domain);
+ }
+ }
+}
diff --git a/IvyTransduct/IvyTransduct.csproj b/IvyTransduct/IvyTransduct.csproj
new file mode 100644
index 0000000..febed4c
--- /dev/null
+++ b/IvyTransduct/IvyTransduct.csproj
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E736A799-EE63-4905-940E-2DA1DC38B5A9}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>IvyTransduct</RootNamespace>
+ <AssemblyName>IvyTransduct</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ <CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="IvyTransduct.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="transduct_droid.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\getopt\getopt.csproj">
+ <Project>{228B5F0B-31AE-488F-A916-B7CBB269D25F}</Project>
+ <Name>getopt</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Ivy\Ivy.csproj">
+ <Project>{F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}</Project>
+ <Name>Ivy</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/IvyTransduct/IvyTransduct.csproj.user b/IvyTransduct/IvyTransduct.csproj.user
new file mode 100644
index 0000000..123fab5
--- /dev/null
+++ b/IvyTransduct/IvyTransduct.csproj.user
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
+ <StartArguments>..\transduct_droid.xml</StartArguments>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+ <StartArguments>-d ..\..\transduct_droid.xml</StartArguments>
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/IvyTransduct/transduct_droid.xml b/IvyTransduct/transduct_droid.xml
new file mode 100644
index 0000000..1650d0b
--- /dev/null
+++ b/IvyTransduct/transduct_droid.xml
@@ -0,0 +1,48 @@
+<?xml version='1.0' ?>
+
+<transduct>
+
+ <message>
+ <input bind="^AircraftLevel Flight=(.*) Fl=(.*)" />
+ <output>
+ <item msg="CflEvent Flight={0} Cfl={1}" />
+ </output>
+ </message>
+
+ <message>
+ <input bind="^AircraftSpeed Flight=(.*) Type=.* Value=(.*)" />
+ <output>
+ <item msg="SpeedEvent Flight={0} Speed={1}" />
+ </output>
+ </message>
+
+ <message>
+ <input bind="^AircraftHeading Flight=(.*) To=(.*)" />
+ <output>
+ <item msg="HeadingEvent Flight={0} Heading={1}" />
+ </output>
+ </message>
+
+ <message>
+ <input bind="^AircraftTurn Flight=(.*) Angle=(.*)" />
+ <output>
+ <item msg="HeadingEvent Flight={0} Heading={1}" />
+ </output>
+ </message>
+
+ <message>
+ <input bind="^AircraftDirect Flight=(.*) Beacon=(.*)" />
+ <output>
+ <item msg="DirectEvent Flight={0} To={1}" />
+ </output>
+ </message>
+
+
+ <message>
+ <input bind="^SetTfl Flight=(.*) Sector=(.*) Tfl=(.*)" />
+ <output>
+ <item msg="SetTfl Flight={0} Sector={1} Tfl={2}" />
+ </output>
+ </message>
+
+</transduct>