Skip to content

Commit 95db04e

Browse files
committed
[1.0.18] starting APITest
1 parent 5865f01 commit 95db04e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4979
-32
lines changed

APITest/APITest.csproj

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{729EFE7A-4CBA-45AA-84F0-4E9C8CF9539F}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>APITest</RootNamespace>
10+
<AssemblyName>APITest</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="LibUsbDotNet">
36+
<HintPath>..\lib\LibUsbDotNet.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
39+
<SpecificVersion>False</SpecificVersion>
40+
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
41+
</Reference>
42+
<Reference Include="System" />
43+
<Reference Include="System.Core" />
44+
<Reference Include="System.Xml.Linq" />
45+
<Reference Include="System.Data.DataSetExtensions" />
46+
<Reference Include="Microsoft.CSharp" />
47+
<Reference Include="System.Data" />
48+
<Reference Include="System.Deployment" />
49+
<Reference Include="System.Drawing" />
50+
<Reference Include="System.Net.Http" />
51+
<Reference Include="System.Windows.Forms" />
52+
<Reference Include="System.Xml" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Compile Include="Command.cs" />
56+
<Compile Include="CommandFactory.cs" />
57+
<Compile Include="Form1.cs">
58+
<SubType>Form</SubType>
59+
</Compile>
60+
<Compile Include="Form1.Designer.cs">
61+
<DependentUpon>Form1.cs</DependentUpon>
62+
</Compile>
63+
<Compile Include="Logger.cs" />
64+
<Compile Include="Program.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
<Compile Include="Util.cs" />
67+
<EmbeddedResource Include="Form1.resx">
68+
<DependentUpon>Form1.cs</DependentUpon>
69+
</EmbeddedResource>
70+
<EmbeddedResource Include="Properties\Resources.resx">
71+
<Generator>ResXFileCodeGenerator</Generator>
72+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
73+
<SubType>Designer</SubType>
74+
</EmbeddedResource>
75+
<Compile Include="Properties\Resources.Designer.cs">
76+
<AutoGen>True</AutoGen>
77+
<DependentUpon>Resources.resx</DependentUpon>
78+
</Compile>
79+
<None Include="Properties\Settings.settings">
80+
<Generator>SettingsSingleFileGenerator</Generator>
81+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
82+
</None>
83+
<Compile Include="Properties\Settings.Designer.cs">
84+
<AutoGen>True</AutoGen>
85+
<DependentUpon>Settings.settings</DependentUpon>
86+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
87+
</Compile>
88+
</ItemGroup>
89+
<ItemGroup>
90+
<None Include="App.config" />
91+
</ItemGroup>
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
</Project>

APITest/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

APITest/Command.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace APITest
8+
{
9+
public class Command
10+
{
11+
public enum Direction { HOST_TO_DEVICE, DEVICE_TO_HOST };
12+
public enum DataType
13+
{
14+
BOOL,
15+
BYTE_ARRAY,
16+
ENUM,
17+
FLOAT16, // "FunkyFloat" with MSB integer and LSB fraction
18+
STRING,
19+
UINT8,
20+
UINT12, // 12-bit DAC/ADC
21+
UINT16,
22+
UINT16_ARRAY,
23+
UINT32,
24+
UINT40, // 5-byte values
25+
};
26+
27+
public enum UsableFields { WVALUE, WINDEX };
28+
29+
public string name;
30+
public byte opcode;
31+
public string units;
32+
public Direction direction = Direction.HOST_TO_DEVICE;
33+
public DataType dataType = DataType.BYTE_ARRAY;
34+
35+
public int length = 0;
36+
public int readBack = 0;
37+
public int readBackARM = 0;
38+
public int readEndpoint = 0;
39+
public int readBlockSize = 0;
40+
public int fakeBufferLength = 0;
41+
public bool makeFakeBufferFromValue = false;
42+
43+
public HashSet<UsableFields> usesFields;
44+
public HashSet<string> supportsBoards; // make HashSet of enum?
45+
public Tuple<double, double> range;
46+
public List<string> enumValues;
47+
48+
public UInt16 wValue = 0;
49+
public UInt16 wIndex = 0;
50+
public bool fixedWValue = false;
51+
public bool fixedWIndex = false;
52+
53+
public bool armInvertedReturn = false;
54+
public bool reverse = false;
55+
public bool enabled = true;
56+
57+
public string notes;
58+
59+
60+
}
61+
}

APITest/CommandFactory.cs

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json;
7+
using System.IO;
8+
9+
namespace APITest
10+
{
11+
class CommandFactory
12+
{
13+
static Logger logger = Logger.getInstance();
14+
15+
public class JsonCommand
16+
{
17+
public string Opcode { get; set; }
18+
public string Direction { get; set; }
19+
public string Type { get; set; }
20+
public int Length { get; set; }
21+
public string wValue { get; set; }
22+
public string wIndex { get; set; }
23+
public string Units { get; set; }
24+
public IList<double> Range { get; set; }
25+
public IList<string> Uses { get; set; }
26+
public IList<string> Enum { get; set; }
27+
public IList<string> Supports { get; set; }
28+
public bool MakeFakeBufferFromValue { get; set; }
29+
public bool ARMInvertedReturn { get; set; }
30+
public int ReadBack { get; set; }
31+
public int ReadBackARM { get; set; }
32+
public int ReadBlockSize { get; set; }
33+
public int FakeBufferLength { get; set; }
34+
public int ReadEndpoint { get; set; }
35+
public bool Reverse { get; set; }
36+
public bool Enabled { get; set; }
37+
public string Notes { get; set; }
38+
}
39+
40+
public static SortedDictionary<string, Command> loadCommands(string pathname)
41+
{
42+
string text = File.ReadAllText(pathname);
43+
SortedDictionary <string, JsonCommand> jsonCommands = JsonConvert.DeserializeObject< SortedDictionary<string, JsonCommand> >(text);
44+
45+
if (jsonCommands == null)
46+
{
47+
logger.error("could not deserialize {0}", pathname);
48+
return null;
49+
}
50+
51+
SortedDictionary<string, Command> commands = new SortedDictionary<string, Command>();
52+
foreach (KeyValuePair<string, JsonCommand> pair in jsonCommands)
53+
{
54+
string name = pair.Key;
55+
JsonCommand jcmd = pair.Value;
56+
logger.debug("loaded {0} (opcode {1}, type {2})", name, jcmd.Opcode, jcmd.Type);
57+
58+
try
59+
{
60+
Command cmd = createCommand(name, jcmd);
61+
commands[name] = cmd;
62+
}
63+
catch(Exception ex)
64+
{
65+
logger.error("Couldn't parse JSON command {0}: {1}", name, ex);
66+
}
67+
}
68+
return commands;
69+
}
70+
71+
static Command createCommand(string name, JsonCommand jcmd)
72+
{
73+
Command cmd = new Command();
74+
75+
cmd.name = name;
76+
77+
cmd.opcode = (byte)Util.fromHex(jcmd.Opcode);
78+
if (jcmd.wValue != null)
79+
{
80+
cmd.fixedWValue = true;
81+
cmd.wValue = Util.fromHex(jcmd.wValue);
82+
}
83+
if (jcmd.wIndex != null)
84+
{
85+
cmd.wIndex = Util.fromHex(jcmd.wIndex);
86+
cmd.fixedWIndex = true;
87+
}
88+
89+
cmd.dataType = convertDataType(jcmd.Type);
90+
cmd.direction = jcmd.Direction.ToUpper().StartsWith("HOST") ? Command.Direction.HOST_TO_DEVICE : Command.Direction.DEVICE_TO_HOST;
91+
92+
cmd.units = jcmd.Units;
93+
cmd.length = jcmd.Length;
94+
cmd.readBack = jcmd.ReadBack;
95+
cmd.readBackARM = jcmd.ReadBackARM;
96+
cmd.readBlockSize = jcmd.ReadBlockSize;
97+
cmd.enabled = jcmd.Enabled;
98+
cmd.notes = jcmd.Notes;
99+
cmd.armInvertedReturn = jcmd.ARMInvertedReturn;
100+
cmd.reverse = jcmd.Reverse;
101+
cmd.readEndpoint = jcmd.ReadEndpoint;
102+
cmd.makeFakeBufferFromValue = jcmd.MakeFakeBufferFromValue;
103+
cmd.fakeBufferLength = jcmd.FakeBufferLength;
104+
105+
if (jcmd.Range != null && jcmd.Range.Count == 2)
106+
cmd.range = new Tuple<double, double>(jcmd.Range[0], jcmd.Range[1]);
107+
108+
if (jcmd.Supports != null && jcmd.Supports.Count > 0)
109+
{
110+
cmd.supportsBoards = new HashSet<string>();
111+
foreach (string s in jcmd.Supports)
112+
cmd.supportsBoards.Add(s);
113+
}
114+
115+
if (jcmd.Uses != null && jcmd.Uses.Count > 0)
116+
{
117+
cmd.usesFields = new HashSet<Command.UsableFields>();
118+
foreach (string s in jcmd.Uses)
119+
cmd.usesFields.Add(s.ToUpper() == "WVALUE" ? Command.UsableFields.WVALUE : Command.UsableFields.WINDEX);
120+
}
121+
122+
if (jcmd.Enum != null && jcmd.Enum.Count > 0)
123+
{
124+
cmd.enumValues = new List<string>();
125+
foreach (string s in jcmd.Enum)
126+
cmd.enumValues.Add(s);
127+
}
128+
129+
return cmd;
130+
}
131+
132+
static Command.DataType convertDataType(string s)
133+
{
134+
s = s.ToUpper();
135+
if (s == "BOOL") return Command.DataType.BOOL;
136+
else if (s == "BYTE[]") return Command.DataType.BYTE_ARRAY;
137+
else if (s == "ENUM") return Command.DataType.ENUM;
138+
else if (s == "FLOAT16") return Command.DataType.FLOAT16;
139+
else if (s == "STRING") return Command.DataType.STRING;
140+
else if (s == "UINT8") return Command.DataType.UINT8;
141+
else if (s == "UINT12") return Command.DataType.UINT12;
142+
else if (s == "UINT16") return Command.DataType.UINT16;
143+
else if (s == "UINT32") return Command.DataType.UINT32;
144+
else if (s == "UINT40") return Command.DataType.UINT40;
145+
else if (s == "UINT16[]") return Command.DataType.UINT16_ARRAY;
146+
else throw new Exception(String.Format("Unrecognized DataType {0}", s));
147+
}
148+
149+
public static void dumpCommands(string pathname)
150+
{
151+
string json = File.ReadAllText(pathname);
152+
JsonTextReader reader = new JsonTextReader(new StringReader(json));
153+
while (reader.Read())
154+
if (reader.Value != null)
155+
logger.info("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
156+
else
157+
logger.info("Token: {0}", reader.TokenType);
158+
}
159+
}
160+
}

0 commit comments

Comments
 (0)