add msgType, Textype

This commit is contained in:
stubbfel
2013-08-29 22:49:06 +02:00
parent 1946124e9e
commit 62671c0593
10 changed files with 136 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
namespace ndefpclib.message
{
using ndefpclib.records;
using ndefpclib.type;
using System.Collections.Generic;
using System.IO;
@@ -22,7 +23,7 @@
/// <param name="content">The content.</param>
/// <param name="type"> The type.</param>
/// <param name="tnf"> (Optional) the tnf.</param>
public NDEFMessage(string content, TYPEVAL type, NDEFRecord.TNFVAL tnf = NDEFRecord.TNFVAL.WKT)
public NDEFMessage(string content, MsgType.TYPEVAL type, MsgType.TNFVAL tnf = MsgType.TNFVAL.WKT)
{
this.records = new List<NDEFRecord>();
float recordsCount = (float)content.Length / NDEFRecord.MaxRecordPayLoad;
@@ -54,6 +55,12 @@
this.records[this.records.IndexOf(tmpRecord)].ME = NDEFRecord.NDEFFlags.MESET;
}
public NDEFMessage(string content, MsgType type)
: this(content, type.TypeValue, type.TNFValue)
{
}
/// <summary>Initializes a new instance of the NDEFMessage class.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
/// <param name="array">The array.</param>
@@ -72,39 +79,21 @@
#endregion
#region enum
/// <summary>Values that represent TYPEVAL.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
public enum TYPEVAL
{
/// <summary>An enum constant representing the empty option.</summary>
EMPTY = 0x00,
/// <summary>An enum constant representing the URL option.</summary>
URL = 0x55,
/// <summary>An enum constant representing the text option.</summary>
TEXT = 0x54,
}
#endregion
#region Methods
/// <summary>Gets a praefix.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
/// <param name="type">The type.</param>
/// <returns>The praefix.</returns>
public static string GetPraefix(TYPEVAL type)
public static string GetPraefix(MsgType.TYPEVAL type)
{
string praefix = string.Empty;
switch (type)
{
case TYPEVAL.TEXT:
case MsgType.TYPEVAL.TEXT:
praefix = "\x02" + "de";
break;
case TYPEVAL.URL:
case MsgType.TYPEVAL.URL:
praefix = "\x01";
break;
default:

View File

@@ -41,6 +41,10 @@
<Compile Include="record\NDEFRecord.cs" />
<Compile Include="record\NDEFShortRecord.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="type\Const\Language.cs" />
<Compile Include="type\MsgType.cs" />
<Compile Include="type\Const\TextEncoding.cs" />
<Compile Include="type\TextType.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -1,6 +1,7 @@
namespace ndefpclib.records
{
using ndefpclib.message;
using ndefpclib.type;
using System.IO;
using System.Text;
@@ -64,35 +65,6 @@
TNFSET = 0x03
}
/// <summary>Values that represent TNFVAL.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
public enum TNFVAL
{
/// <summary>An enum constant representing the empty option.</summary>
EMPTY = 0x00,
/// <summary>An enum constant representing the Well-Know-Type option.</summary>
WKT = 0x01,
/// <summary>An enum constant representing the MediaType option.</summary>
MEDIATYPE = 0x02,
/// <summary>An enum constant representing the URI option.</summary>
URI = 0x03,
/// <summary>An enum constant representing the NFCE option.</summary>
NFCE = 0x04,
/// <summary>An enum constant representing the unknow option.</summary>
unknow = 0x05,
/// <summary>An enum constant representing the unchanged option.</summary>
UNCHANGED = 0x06,
/// <summary>An enum constant representing the reserved option.</summary>
RESERVED = 0x07
}
#endregion
#region Properties
@@ -118,11 +90,11 @@
/// <summary>Gets or sets the TNFField.</summary>
/// <value>The TNFField.</value>
public TNFVAL TNF { get; set; }
public MsgType.TNFVAL TNF { get; set; }
/// <summary>Gets or sets the type.</summary>
/// <value>The type.</value>
public NDEFMessage.TYPEVAL Type { get; set; }
public MsgType.TYPEVAL Type { get; set; }
/// <summary>Gets or sets the format flags.</summary>
/// <value>The format flags.</value>
@@ -135,7 +107,7 @@
protected set
{
this.TNF = (TNFVAL)(value & (byte)NDEFFlags.TNFSET);
this.TNF = (MsgType.TNFVAL)(value & (byte)NDEFFlags.TNFSET);
this.MB = (NDEFFlags)(value & (byte)NDEFFlags.MBSET);
this.ME = (NDEFFlags)(value & (byte)NDEFFlags.MESET);
this.CF = (NDEFFlags)(value & (byte)NDEFFlags.CFSET);

View File

@@ -1,6 +1,7 @@
namespace ndefpclib.records
{
using ndefpclib.message;
using ndefpclib.type;
using System.Text;
/// <summary>Ndef short record.</summary>
@@ -25,7 +26,7 @@
: base(array)
{
this.HeaderSize = 4;
this.Type = (NDEFMessage.TYPEVAL)array[index + 3];
this.Type = (MsgType.TYPEVAL)array[index + 3];
this.PayloadPraefix = NDEFMessage.GetPraefix(this.Type);
int payLoadSize = array[index + 2] - this.PayloadPraefix.Length;
this.Payload = Encoding.UTF8.GetString(array, index + this.HeaderSize + this.PayloadPraefix.Length, payLoadSize);

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ndefpclib.type.Const
{
public class Language
{
public const string DE ="de";
public const string EN = "en";
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ndefpclib.type.Const
{
public class TextEncoding
{
public const string UTF8 = "\x02";
public const string UTF16 = "\x82";
}
}

View File

@@ -0,0 +1,19 @@
using ndefpclib.type.Const;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ndefpclib.type
{
public class TextType : MsgType
{
public TextType(string encoding = TextEncoding.UTF8, string lang = Language.DE)
{
this.TNFValue = TNFVAL.WKT;
this.TypeValue = TYPEVAL.TEXT;
this.PayloadPrefix = encoding + lang;
}
}
}

View File

@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ndefpclib.type
{
public abstract class MsgType
{
#region enum
/// <summary>Values that represent TYPEVAL.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
public enum TYPEVAL
{
/// <summary>An enum constant representing the empty option.</summary>
EMPTY = 0x00,
/// <summary>An enum constant representing the URL option.</summary>
URL = 0x55,
/// <summary>An enum constant representing the text option.</summary>
TEXT = 0x54,
}
/// <summary>Values that represent TNFVAL.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
public enum TNFVAL
{
/// <summary>An enum constant representing the empty option.</summary>
EMPTY = 0x00,
/// <summary>An enum constant representing the Well-Know-Type option.</summary>
WKT = 0x01,
/// <summary>An enum constant representing the MediaType option.</summary>
MEDIATYPE = 0x02,
/// <summary>An enum constant representing the URI option.</summary>
URI = 0x03,
/// <summary>An enum constant representing the NFCE option.</summary>
NFCE = 0x04,
/// <summary>An enum constant representing the unknow option.</summary>
unknow = 0x05,
/// <summary>An enum constant representing the unchanged option.</summary>
UNCHANGED = 0x06,
/// <summary>An enum constant representing the reserved option.</summary>
RESERVED = 0x07
}
#endregion
#region property
public TYPEVAL TypeValue { get; protected set; }
public string PayloadPrefix { get; protected set; }
public TNFVAL TNFValue { get; protected set; }
#endregion
}
}