Skip to content

Commit

Permalink
Feature/netstandard2.0 (#20)
Browse files Browse the repository at this point in the history
Support .NET Standard 2.0
  • Loading branch information
hbjorgo authored Sep 18, 2022
1 parent b88f66d commit 1f2e469
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 41 deletions.
24 changes: 14 additions & 10 deletions src/HeboTech.ATLib.TestConsole/HeboTech.ATLib.TestConsole.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HeboTech.ATLib\HeboTech.ATLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HeboTech.ATLib\HeboTech.ATLib.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/HeboTech.ATLib.TestConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.Versioning;
using System.Threading.Tasks;

namespace HeboTech.ATLib.TestConsole
Expand All @@ -10,6 +13,14 @@ class Program
{
static async Task Main(string[] args)
{
// Because of multi targeting, print out current framework target for information
var targetFrameworkAttribute = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(TargetFrameworkAttribute), false)
.SingleOrDefault() as TargetFrameworkAttribute;
Console.WriteLine($"Current target: {targetFrameworkAttribute.FrameworkName}");



Console.OutputEncoding = System.Text.Encoding.UTF8;

string pin = args[0];
Expand Down
37 changes: 20 additions & 17 deletions src/HeboTech.ATLib.Tests/HeboTech.ATLib.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.17.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.17.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HeboTech.ATLib\HeboTech.ATLib.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HeboTech.ATLib\HeboTech.ATLib.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/HeboTech.ATLib.Tests/PDU/PduTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HeboTech.ATLib.CodingSchemes;
using HeboTech.ATLib.DTOs;
using HeboTech.ATLib.PDU;
using System;
using Xunit;

namespace HeboTech.ATLib.Tests.PDU
Expand All @@ -23,7 +24,11 @@ public void Encode_SmsSubmit_test(string phoneNumber, string encodedMessage, byt
[InlineData("07911326040000F0040B911346610089F60000208062917314800CC8F71D14969741F977FD07", "31624000000", "31641600986", "02-08-26-19-37-41-+02", "How are you?")]
public void Decode_SmsDeliver_tests(string data, string serviceCenterNumber, string senderNumber, string timestamp, string message)
{
#if NETFRAMEWORK
SmsDeliver pduMessage = Pdu.DecodeSmsDeliver(data.AsSpan());
#else
SmsDeliver pduMessage = Pdu.DecodeSmsDeliver(data);
#endif

Assert.NotNull(pduMessage);
Assert.Equal(TypeOfNumber.International, pduMessage.ServiceCenterNumber.Ton);
Expand All @@ -39,7 +44,11 @@ public void Decode_SmsDeliver_tests(string data, string serviceCenterNumber, str
[InlineData("0011000802231537180000AA0D5062154403D1CB68D03DED06", "", "32517381", "PDU 4 teh win")]
public void Decode_SmsSubmit_tests(string data, string serviceCenterNumber, string senderNumber, string message)
{
#if NETFRAMEWORK
SmsSubmit pduMessage = Pdu.DecodeSmsSubmit(data.AsSpan());
#else
SmsSubmit pduMessage = Pdu.DecodeSmsSubmit(data);
#endif

Assert.NotNull(pduMessage);
Assert.Equal(serviceCenterNumber, pduMessage.ServiceCenterNumber?.Number ?? "");
Expand Down
20 changes: 20 additions & 0 deletions src/HeboTech.ATLib.Tests/Parsers/AtReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public async Task Lines_are_readAsync()

string input = "Line1\r\nLine2\r\nLine3\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(input);
#if NETFRAMEWORK
stream.Write(buffer, 0, buffer.Length);
#else
stream.Write(buffer);
#endif
stream.Position = 0;

dut.Open();
Expand All @@ -40,7 +44,11 @@ public async Task Lines_and_sms_prompts_are_readAsync()

string input = "Line1\r\nLine2\r\n> Line3\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(input);
#if NETFRAMEWORK
stream.Write(buffer, 0, buffer.Length);
#else
stream.Write(buffer);
#endif
stream.Position = 0;

dut.Open();
Expand All @@ -66,7 +74,11 @@ public async Task Empty_lines_are_readAsync()

string input = "\r\n\r\n\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(input);
#if NETFRAMEWORK
stream.Write(buffer, 0, buffer.Length);
#else
stream.Write(buffer);
#endif
stream.Position = 0;

dut.Open();
Expand All @@ -90,7 +102,11 @@ public async Task Cme_Error_is_readAsync()

string input = "+CME ERROR: ErrorMessage\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(input);
#if NETFRAMEWORK
stream.Write(buffer, 0, buffer.Length);
#else
stream.Write(buffer);
#endif
stream.Position = 0;

dut.Open();
Expand All @@ -110,7 +126,11 @@ public async Task Ring_is_readAsync()

string input = "RING\r\n\r\nRING\r\n\r\nMISSED_CALL: 01:23PM 12345678\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(input);
#if NETFRAMEWORK
stream.Write(buffer, 0, buffer.Length);
#else
stream.Write(buffer);
#endif
stream.Position = 0;

dut.Open();
Expand Down
6 changes: 3 additions & 3 deletions src/HeboTech.ATLib.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
# Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeboTech.ATLib", "HeboTech.ATLib\HeboTech.ATLib.csproj", "{F919890A-9835-4D57-80F1-8F6BF2CC2085}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeboTech.ATLib.TestConsole", "HeboTech.ATLib.TestConsole\HeboTech.ATLib.TestConsole.csproj", "{82A5A7D4-9AD3-4B95-AD72-CD1B48017AC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeboTech.ATLib.Tests", "HeboTech.ATLib.Tests\HeboTech.ATLib.Tests.csproj", "{97A95146-06D3-436E-AE16-8F0A6D86B26D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeboTech.ATLib.Tests", "HeboTech.ATLib.Tests\HeboTech.ATLib.Tests.csproj", "{97A95146-06D3-436E-AE16-8F0A6D86B26D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 4 additions & 0 deletions src/HeboTech.ATLib/DTOs/PhoneNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ public class PhoneNumber
{
public PhoneNumber(string number)
{
#if NETSTANDARD2_0
if (number.StartsWith("+"))
#else
if (number.StartsWith('+'))
#endif
{
Ton = TypeOfNumber.International;
Npi = NumberPlanIdentification.ISDN;
Expand Down
7 changes: 7 additions & 0 deletions src/HeboTech.ATLib/DTOs/SupportedPreferredMessageStorages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ public SupportedPreferredMessageStorages(IEnumerable<string> storage1, IEnumerab

public override string ToString()
{
#if NETSTANDARD2_0
return
$"Storage1: {string.Join(",", Storage1)}{Environment.NewLine}" +
$"Storage2: {string.Join(",", Storage2)}{Environment.NewLine}" +
$"Storage3: {string.Join(",", Storage3)}";
#elif NETSTANDARD2_1_OR_GREATER
return
$"Storage1: {string.Join(',', Storage1)}{Environment.NewLine}" +
$"Storage2: {string.Join(',', Storage2)}{Environment.NewLine}" +
$"Storage3: {string.Join(',', Storage3)}";
#endif
}
}
}
4 changes: 4 additions & 0 deletions src/HeboTech.ATLib/Events/MissedCallEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public MissedCallEventArgs(string time, string phoneNumber)

public static MissedCallEventArgs CreateFromResponse(string response)
{
#if NETSTANDARD2_0
string[] split = response.Split(new char[] { ' ' }, 3);
#elif NETSTANDARD2_1_OR_GREATER
string[] split = response.Split(' ', 3);
#endif
return new MissedCallEventArgs(split[1], split[2]);
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/HeboTech.ATLib/HeboTech.ATLib.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<Authors>HeboTech</Authors>
<Product>HeboTech ATLib</Product>
<Version>4.1.0</Version>
Expand All @@ -15,12 +15,16 @@
<PackageReleaseNotes>https://github.com/hbjorgo/ATLib/releases</PackageReleaseNotes>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<FileVersion>4.1.0.0</FileVersion>
<UserSecretsId>b8328b1a-795d-4e26-9238-43eee2160ffc</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IO.Pipelines" Version="6.0.2" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
<PackageReference Include="System.IO.Pipelines" Version="6.0.3" />
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Nerdbank.Streams" Version="2.9.91-alpha" />
</ItemGroup>

</Project>
33 changes: 26 additions & 7 deletions src/HeboTech.ATLib/Modems/Generic/ModemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ public virtual async Task<ModemResponse<IEnumerable<string>>> GetAvailableCharac
var match = Regex.Match(line, @"\+CSCS:\s\((?:""(?<characterSet>\w+)"",*)+\)");
if (match.Success)
{
#if NETSTANDARD2_0
return ModemResponse.ResultSuccess(match.Groups["characterSet"].Captures.Cast<Capture>().Select(x => x.Value));
#elif NETSTANDARD2_1_OR_GREATER
return ModemResponse.ResultSuccess(match.Groups["characterSet"].Captures.Select(x => x.Value));
#endif
}
}
return ModemResponse.ResultError<IEnumerable<string>>();
Expand Down Expand Up @@ -150,9 +154,9 @@ public virtual async Task<ModemResponse> SetCharacterSetAsync(string characterSe
AtResponse response = await channel.SendCommand($"AT+CSCS=\"{characterSet}\"");
return ModemResponse.Success(response.Success);
}
#endregion
#endregion

#region _3GPP_TS_27_005
#region _3GPP_TS_27_005
public event EventHandler<SmsReceivedEventArgs> SmsReceived;

public virtual async Task<ModemResponse> SetSmsMessageFormatAsync(SmsTextFormat format)
Expand Down Expand Up @@ -317,7 +321,11 @@ public virtual async Task<ModemResponse<Sms>> ReadSmsAsync(int index, SmsTextFor
SmsStatus status = SmsStatusHelpers.ToSmsStatus(statusCode);

string pdu = line2Match.Groups["status"].Value;
#if NETSTANDARD2_0
SmsDeliver pduMessage = Pdu.DecodeSmsDeliver(pdu.AsSpan());
#elif NETSTANDARD2_1_OR_GREATER
SmsDeliver pduMessage = Pdu.DecodeSmsDeliver(pdu);
#endif

return ModemResponse.ResultSuccess(new Sms(status, pduMessage.SenderNumber, pduMessage.Timestamp, pduMessage.Message));
}
Expand Down Expand Up @@ -408,9 +416,9 @@ public virtual async Task<ModemResponse> DeleteSmsAsync(int index)
AtResponse response = await channel.SendCommand($"AT+CMGD={index}");
return ModemResponse.Success(response.Success);
}
#endregion
#endregion

#region _3GPP_TS_27_007
#region _3GPP_TS_27_007
public event EventHandler<UssdResponseEventArgs> UssdResponseReceived;

public virtual async Task<ModemResponse<SimStatus>> GetSimStatusAsync()
Expand All @@ -429,6 +437,16 @@ public virtual async Task<ModemResponse<SimStatus>> GetSimStatusAsync()
if (match.Success)
{
string cpinResult = match.Groups["pinresult"].Value;
#if NETSTANDARD2_0
switch(cpinResult)
{
case "SIM PIN": return ModemResponse.ResultSuccess(SimStatus.SIM_PIN);
case "SIM PUK": return ModemResponse.ResultSuccess(SimStatus.SIM_PUK);
case "PH-NET PIN": return ModemResponse.ResultSuccess(SimStatus.SIM_NETWORK_PERSONALIZATION);
case "READY": return ModemResponse.ResultSuccess(SimStatus.SIM_READY);
default: return ModemResponse.ResultSuccess(SimStatus.SIM_ABSENT);// Treat unsupported lock types as "sim absent"
};
#elif NETSTANDARD2_1_OR_GREATER
return cpinResult switch
{
"SIM PIN" => ModemResponse.ResultSuccess(SimStatus.SIM_PIN),
Expand All @@ -437,6 +455,7 @@ public virtual async Task<ModemResponse<SimStatus>> GetSimStatusAsync()
"READY" => ModemResponse.ResultSuccess(SimStatus.SIM_READY),
_ => ModemResponse.ResultSuccess(SimStatus.SIM_ABSENT),// Treat unsupported lock types as "sim absent"
};
#endif
}

return ModemResponse.ResultError<SimStatus>();
Expand Down Expand Up @@ -530,7 +549,7 @@ public virtual async Task<ModemResponse> SendUssdAsync(string code, int codingSc
AtResponse response = await channel.SendCommand($"AT+CUSD=1,\"{code}\",{codingScheme}");
return ModemResponse.Success(response.Success);
}
#endregion
#endregion

public virtual async Task<ModemResponse> SetErrorFormat(int errorFormat)
{
Expand All @@ -543,7 +562,7 @@ public void Close()
Dispose();
}

#region Dispose
#region Dispose
protected virtual void Dispose(bool disposing)
{
if (!disposed)
Expand Down Expand Up @@ -573,6 +592,6 @@ public void Dispose()
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
#endregion
#endregion
}
}
6 changes: 5 additions & 1 deletion src/HeboTech.ATLib/Modems/SIMCOM/SIM5320.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public override async Task<ModemResponse<Sms>> ReadSmsAsync(int index, SmsTextFo
string alphabet = line1Match.Groups["alphabet"].Value;
int length = int.Parse(line1Match.Groups["length"].Value);
string pdu = line2Match.Groups["pdu"].Value;
#if NETSTANDARD2_0
SmsDeliver pduMessage = Pdu.DecodeSmsDeliver(pdu.AsSpan());
#elif NETSTANDARD2_1_OR_GREATER
SmsDeliver pduMessage = Pdu.DecodeSmsDeliver(pdu);
#endif
return ModemResponse.ResultSuccess(new Sms((SmsStatus)status, pduMessage.SenderNumber, pduMessage.Timestamp, pduMessage.Message));
}
}
Expand Down Expand Up @@ -130,6 +134,6 @@ public override async Task<ModemResponse<List<SmsWithIndex>>> ListSmssAsync(SmsS
}
return ModemResponse.ResultSuccess(smss);
}
#endregion
#endregion
}
}
Loading

0 comments on commit 1f2e469

Please sign in to comment.