Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java rewrite #2

Merged
50 commits merged into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c5b2e55
Change to 3.5 from 4.0 framework
Aug 28, 2015
2ff5be7
Discard in buffer after reading
Aug 28, 2015
ec9f1ee
Restructure the API to be more like the Java API
Aug 28, 2015
7660ddf
Tested against version 0.7 of OpenNETCF
Aug 28, 2015
b3e73d5
Starting java rewrite
corytodd Sep 1, 2015
76be894
Remove reference to experimental OpenCFNET serial port
Sep 1, 2015
de55ee0
Bug fixes in StrongPort and implementation
Sep 1, 2015
25a3f90
Add more UI features to test app
Sep 1, 2015
a9fbbc3
Make consistent states vs events in the context of RS-232
corytodd Sep 2, 2015
b9f0142
Update to reflect latest API changes
corytodd Sep 2, 2015
5fe6800
Simplify debugBuffer
corytodd Sep 2, 2015
5668793
Doc update
corytodd Sep 2, 2015
cc50570
Remove Com port name enum
corytodd Sep 2, 2015
2839377
StrongPort open on instantiation so remove so make Connect() just ret…
Sep 2, 2015
77475de
Updated UI with data bindings and state diagram
Sep 2, 2015
870e32b
Broken commit, cleaning up all of the different state/event/error nam…
Sep 2, 2015
6e07966
Rewrote the slave message decoder
Sep 3, 2015
7c41aed
Finished slave message translator and unit tests
Sep 3, 2015
8e6a339
Cleaned up ApexValidator class to use new slave codex - very clean
Sep 3, 2015
cc8e912
Add enable/disable pattern support
Sep 3, 2015
2db458e
Rename BusyScanning to Offline because that makes more sense
Sep 3, 2015
8099728
Switch timestamp on debug packet to epoch like how wireshark does it
Sep 3, 2015
dd475d5
Fix ConsoleLogger so it does not grow too large
Sep 3, 2015
9f1ff6a
Add codex for mater messages
Sep 3, 2015
ba42bf8
Update UI to be more readable
Sep 3, 2015
af5a5e4
Remove unused code
Sep 3, 2015
e184bc1
Process states in reverse order to so we don't miss the less common s…
Sep 3, 2015
2bce472
Add stringified master and slave message to debug output
Sep 3, 2015
a244839
I think the escrow mode is backwards but by eye is twitching so I'm g…
Sep 3, 2015
9149b19
Add acceptor reset command
Sep 4, 2015
db5871e
Fix bug in enable mask check
Sep 4, 2015
3a92265
formatting clean up and comment update
Sep 4, 2015
83334c1
Remove uneeded logging
Sep 4, 2015
a4e467c
Rearranged sample app
corytodd Sep 5, 2015
8bad44e
Rename property
corytodd Sep 5, 2015
d0b2460
Move acceptor state variables into validator class
Sep 8, 2015
61d76e8
Add enable/disable mask support for escrow mode
Sep 8, 2015
ca5fa9e
Do not allow connecting when "Select Port" is the selected port
Sep 8, 2015
a3d181e
Add error for when port fails to open
Sep 8, 2015
b3724df
Doc and comment update
Sep 8, 2015
a1e2e60
Could never get sl4net to work properly Switching to log4net until so…
Sep 8, 2015
d179f19
Correctly implement EventArgs per CA1009
Sep 8, 2015
85acb92
CA2101 Fix
Sep 8, 2015
fcdba14
CA1060 Fix
Sep 8, 2015
ae14645
Update to use latest API
Sep 8, 2015
66ba152
Remove unused references and usings
Sep 8, 2015
4ae6921
Documentation update
Sep 8, 2015
c0a647d
Documentation Update
Sep 8, 2015
f639b63
Restructure events for less redundancy in declaration, naming, and sa…
Sep 8, 2015
49f75b8
Move remaining state variable from config into the validator class
Sep 8, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Apex7000_BillValidator_Test\obj\*
Apex7000_BillValidator/obj/
Apex7000_BillValidator_Test/bin/
Apex7000_BillValidator_Test/obj/
Apex7000_BillValidator/bin/
API_Test/bin/
API_Test/obj/
89 changes: 89 additions & 0 deletions API_Test/API_Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{71DEAB9A-CC67-4BD8-9FEC-C5E59ED2A75F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>API_Test</RootNamespace>
<AssemblyName>API_Test</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="SlaveCodex_Test.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Apex7000_BillValidator\Apex7000_BillValidator.csproj">
<Project>{735220bb-d8e8-4e21-80d9-aea6e41b13ed}</Project>
<Name>Apex7000_BillValidator</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<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>
36 changes: 36 additions & 0 deletions API_Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("API_Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("API_Test")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4681deb4-b35c-4be8-a264-cc4d89b60051")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
206 changes: 206 additions & 0 deletions API_Test/SlaveCodex_Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Apex7000_BillValidator;

namespace API_Test
{
[TestClass]
public class SlaveCodex_Test
{

[TestMethod]
public void TestToSlaveMessage()
{
byte[] testData;

// Test the we return invalid command on empty data
testData = new byte[] { };

Assert.AreEqual(SlaveCodex.SlaveMessage.InvalidCommand, SlaveCodex.ToSlaveMessage(testData));

// Test the we return invalid command on too large of data
testData = new byte[12];

Assert.AreEqual(SlaveCodex.SlaveMessage.InvalidCommand, SlaveCodex.ToSlaveMessage(testData));
}


[TestMethod]
public void TestGetState()
{

States state;
SlaveCodex.SlaveMessage message;
byte[] testData;

// Idling and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.Idling, state);

// Accepting and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x02, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.Accepting, state);

// Escrowed and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x04, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.Escrowed, state);

// Stacking and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x8, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.Stacking, state);

// Returning and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x20, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.Returning, state);

// Jammed and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x00, 0x14, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.BillJammed, state);

// Cashbox full and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x00, 0x18, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.StackerFull, state);

// Acceptor Failure and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x00, 0x10, 0x04, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

state = SlaveCodex.GetState(message);
Assert.AreEqual(States.AcceptorFailure, state);

Assert.IsTrue(SlaveCodex.IsCashboxPresent(message));

}

[TestMethod]
public void TestGetEvent()
{

Events events;
SlaveCodex.SlaveMessage message;
byte[] testData;

// Idling and Stacked
testData = new byte[] { 0x02, 0x0B, 0x21, 0x11, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

events = SlaveCodex.GetEvents(message);
Assert.AreEqual(Events.Stacked, events);

// Idling and returned
testData = new byte[] { 0x02, 0x0B, 0x21, 0x41, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

events = SlaveCodex.GetEvents(message);
Assert.AreEqual(Events.Returned, events);

// Cheated and returning
testData = new byte[] { 0x02, 0x0B, 0x21, 0x20, 0x11, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

events = SlaveCodex.GetEvents(message);
Assert.AreEqual(Events.Cheated, events);

// Rejected and cashbox present
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x12, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

events = SlaveCodex.GetEvents(message);
Assert.AreEqual(Events.BillRejected, events);

// Power up
testData = new byte[] { 0x02, 0x0B, 0x21, 0x00, 0x00, 0x01, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

events = SlaveCodex.GetEvents(message);
Assert.AreEqual(Events.PowerUp, events);
}


[TestMethod]
public void TestGetCredit()
{
int credit;
SlaveCodex.SlaveMessage message;
byte[] testData;

// None/Unknown
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x00, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(0, credit);

// $1
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x08, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(1, credit);

// $2
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x10, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(2, credit);

// $5
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x18, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(3, credit);

// $10
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x20, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(4, credit);

// $20
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x28, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(5, credit);

// $50
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x30, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(6, credit);

// $100
testData = new byte[] { 0x02, 0x0B, 0x21, 0x01, 0x10, 0x38, 0x00, 0x11, 0x11, 0x03, 0x3B };
message = SlaveCodex.ToSlaveMessage(testData);

credit = SlaveCodex.GetCredit(message);
Assert.AreEqual(7, credit);
}

}
}
27 changes: 20 additions & 7 deletions Apex7000_BillValidator/Apex7000_BillValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Apex7000_BillValidator</RootNamespace>
<AssemblyName>Apex7000_BillValidator</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -21,6 +21,9 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Apex7000_BillValidator.XML</DocumentationFile>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,20 +34,30 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApexValidator.cs" />
<Compile Include="Commands.cs" />
<Compile Include="DataContracts.cs" />
<Compile Include="DebugBuffer.cs" />
<Compile Include="EventArgs.cs" />
<Compile Include="Events.cs" />
<Compile Include="MasterCodex.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RS232Config.cs" />
<Compile Include="Serial\ICommPort.cs" />
<Compile Include="Serial\PortException.cs" />
<Compile Include="Serial\SerialPortFixer.cs" />
<Compile Include="Serial\StrongPort.cs" />
<Compile Include="SlaveCodex.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Loading