Skip to content

Commit

Permalink
Add modem Cinterion MC55i (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjorgo authored Nov 6, 2023
1 parent 118c2a7 commit a7d7570
Show file tree
Hide file tree
Showing 28 changed files with 1,007 additions and 303 deletions.
68 changes: 38 additions & 30 deletions src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using HeboTech.ATLib.DTOs;
using HeboTech.ATLib.Events;
using HeboTech.ATLib.Modems;
using HeboTech.ATLib.Modems.D_LINK;
using HeboTech.ATLib.Modems.Cinterion;
using HeboTech.ATLib.Modems.Generic;
using HeboTech.ATLib.Parsers;
using System;
using System.Collections.Generic;
Expand All @@ -19,7 +20,7 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)

using AtChannel atChannel = AtChannel.Create(stream);
//atChannel.EnableDebug((string line) => Console.WriteLine(line));
using IModem modem = new DWM222(atChannel);
using IMC55i modem = new MC55i(atChannel);
atChannel.Open();
await atChannel.ClearAsync();

Expand All @@ -32,23 +33,23 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
modem.ErrorReceived += Modem_ErrorReceived;
modem.GenericEvent += Modem_GenericEvent;

// Configure modem with required settings
await modem.SetRequiredSettingsAsync();

await modem.SetSmsMessageFormatAsync(smsTextFormat);
// Configure modem with required settings before PIN
var requiredSettingsBeforePin = await modem.SetRequiredSettingsBeforePinAsync();
Console.WriteLine($"Successfully set required settings before PIN: {requiredSettingsBeforePin}");
await Task.Delay(TimeSpan.FromSeconds(2));

var simStatus = await modem.GetSimStatusAsync();
Console.WriteLine($"SIM Status: {simStatus}");

await modem.ReInitializeSimAsync();
//await modem.ReInitializeSimAsync();

simStatus = await modem.GetSimStatusAsync();
Console.WriteLine($"SIM Status: {simStatus}");

if (simStatus.IsSuccess && simStatus.Result == SimStatus.SIM_READY)
if (simStatus.Success && simStatus.Result == SimStatus.SIM_READY)
{
}
else if (simStatus.IsSuccess && simStatus.Result == SimStatus.SIM_PIN)
else if (simStatus.Success && simStatus.Result == SimStatus.SIM_PIN)
{
var simPinStatus = await modem.EnterSimPinAsync(new PersonalIdentificationNumber(pin));
Console.WriteLine($"SIM PIN Status: {simPinStatus}");
Expand All @@ -57,9 +58,9 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
{
simStatus = await modem.GetSimStatusAsync();
Console.WriteLine($"SIM Status: {simStatus}");
if (simStatus.IsSuccess && simStatus.Result == SimStatus.SIM_READY)
if (simStatus.Success && simStatus.Result == SimStatus.SIM_READY)
break;
await Task.Delay(TimeSpan.FromMilliseconds(1000));
await Task.Delay(TimeSpan.FromSeconds(1));
}
}
else
Expand All @@ -68,21 +69,33 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
return;
}

await Task.Delay(TimeSpan.FromSeconds(2));

for (int i = 0; i < 10; i++)
{
var imsi = await modem.GetImsiAsync();
Console.WriteLine($"IMSI: {imsi}");
if (imsi.IsSuccess)
if (imsi.Success)
break;
await Task.Delay(TimeSpan.FromMilliseconds(1000));
}

// Configure modem with required settings after PIN
var requiredSettingsAfterPin = await modem.SetRequiredSettingsAfterPinAsync();
Console.WriteLine($"Successfully set required settings after PIN: {requiredSettingsAfterPin}");

var smsMessageFormat = await modem.SetSmsMessageFormatAsync(smsTextFormat);
Console.WriteLine($"Setting SMS message format: {smsMessageFormat}");

var signalStrength = await modem.GetSignalStrengthAsync();
Console.WriteLine($"Signal Strength: {signalStrength}");

var batteryStatus = await modem.GetBatteryStatusAsync();
Console.WriteLine($"Battery Status: {batteryStatus}");

//var mc55iBatteryStatus = await modem.MC55i_GetBatteryStatusAsync();
//Console.WriteLine($"MC55i Battery Status: {mc55iBatteryStatus}");

var productInfo = await modem.GetProductIdentificationInformationAsync();
Console.WriteLine($"Product Information:{Environment.NewLine}{productInfo}");

Expand All @@ -92,34 +105,21 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
var dateTime = await modem.GetDateTimeAsync();
Console.WriteLine($"Date and time: {dateTime}");

var newSmsIndicationResult = await modem.SetNewSmsIndication(2, 1, 0, 0, 0);
var newSmsIndicationResult = await modem.SetNewSmsIndication(2, 1, 0, 0, 1);
Console.WriteLine($"Setting new SMS indication: {newSmsIndicationResult}");

var supportedStorages = await modem.GetSupportedPreferredMessageStoragesAsync();
Console.WriteLine($"Supported storages:{Environment.NewLine}{supportedStorages}");
var currentStorages = await modem.GetPreferredMessageStoragesAsync();
Console.WriteLine($"Current storages:{Environment.NewLine}{currentStorages}");
var setPreferredStorages = await modem.SetPreferredMessageStorageAsync("ME", "ME", "ME");
var setPreferredStorages = await modem.SetPreferredMessageStorageAsync(MessageStorage.SM, MessageStorage.SM, MessageStorage.SM);
Console.WriteLine($"Storages set:{Environment.NewLine}{setPreferredStorages}");

//var singleSms = await modem.ReadSmsAsync(2, smsTextFormat);
//Console.WriteLine($"Single SMS: {singleSms}");

var smss = await modem.ListSmssAsync(SmsStatus.ALL);
if (smss.IsSuccess)
{
foreach (var sms in smss.Result)
{
Console.WriteLine($"SMS: {sms}");
var smsDeleteStatus = await modem.DeleteSmsAsync(sms.Index);
Console.WriteLine($"Delete SMS #{sms.Index} - {smsDeleteStatus}");
}
}

Console.WriteLine("Done. Press 'a' to answer call, 'd' to dial, 'h' to hang up, 's' to send SMS, 'r' to read an SMS, 'u' to send USSD code, '+' to enable debug, '-' to disable debug and 'q' to exit...");
Console.WriteLine("Done. Press 'a' to answer call, 'd' to dial, 'h' to hang up, 's' to send SMS, 'r' to read an SMS, 'l' to list all SMSs, 'u' to send USSD code, '+' to enable debug, '-' to disable debug and 'q' to exit...");
ConsoleKey key;
while ((key = Console.ReadKey().Key) != ConsoleKey.Q)
{
Console.WriteLine();
switch (key)
{
case ConsoleKey.A:
Expand Down Expand Up @@ -186,6 +186,13 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
var ussdResult = await modem.SendUssdAsync(ussd);
Console.WriteLine($"USSD Status: {ussdResult}");
break;
case ConsoleKey.L:
Console.WriteLine("List all SMSs:");
var smss = await modem.ListSmssAsync(SmsStatus.ALL);
if (smss.Success)
foreach (var sms in smss.Result)
Console.WriteLine($"SMS: {sms}");
break;
case ConsoleKey.OemPlus:
atChannel.EnableDebug((string line) => Console.WriteLine(line));
Console.WriteLine("Debug enabled");
Expand All @@ -210,7 +217,8 @@ private static void Modem_ErrorReceived(object sender, ErrorEventArgs e)

private static void Modem_UssdResponseReceived(object sender, UssdResponseEventArgs e)
{
Console.WriteLine($"USSD Response: {e.Status} - {e.Response} - ({e.CodingScheme})");
if (e != null)
Console.WriteLine($"USSD Response: {e.Status} - {e.Response} - ({e.CodingScheme})");
}

private static void Modem_CallEnded(object sender, CallEndedEventArgs e)
Expand Down
26 changes: 13 additions & 13 deletions src/HeboTech.ATLib.TestConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ static async Task Main(string[] args)


/* ######## UNCOMMENT THIS SECTION TO USE SERIAL PORT ######## */
using SerialPort serialPort = new("COM1", 9600, Parity.None, 8, StopBits.One)
{
Handshake = Handshake.RequestToSend
};
serialPort.Open();
Console.WriteLine("Serialport opened");
Stream stream;
stream = serialPort.BaseStream;
//using SerialPort serialPort = new("COM1", 9600, Parity.None, 8, StopBits.One)
//{
// Handshake = Handshake.RequestToSend
//};
//serialPort.Open();
//Console.WriteLine("Serialport opened");
//Stream stream;
//stream = serialPort.BaseStream;


/* ######## UNCOMMENT THIS SECTION TO USE NETWORK SOCKET ######## */
//using Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//socket.Connect("192.168.1.144", 7000);
//Console.WriteLine("Network socket opened");
//Stream stream;
//stream = new NetworkStream(socket);
using Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect("192.168.1.144", 7000);
Console.WriteLine("Network socket opened");
Stream stream;
stream = new NetworkStream(socket);


// ### Choose what to run
Expand Down
2 changes: 1 addition & 1 deletion src/HeboTech.ATLib.TestConsole/StressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
Console.WriteLine($"Single SMS: {singleSms}");

var smss = await modem.ListSmssAsync(SmsStatus.ALL);
if (smss.IsSuccess)
if (smss.Success)
{
foreach (var sms in smss.Result)
{
Expand Down
2 changes: 0 additions & 2 deletions src/HeboTech.ATLib/CodingSchemes/UCS2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace HeboTech.ATLib.CodingSchemes
/// </summary>
public class UCS2
{
public const CodingScheme DataCodingSchemeCode = CodingScheme.UCS2;

/// <summary>
/// Encode to UCS2
/// </summary>
Expand Down
34 changes: 25 additions & 9 deletions src/HeboTech.ATLib/DTOs/PreferredMessageStorage.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System;
using HeboTech.ATLib.Modems.Generic;
using System;

namespace HeboTech.ATLib.DTOs
{
public class PreferredMessageStorages
{
/// <summary>
///
/// </summary>
/// <param name="storage1Name">Storage area to be used when reading or deleting SMS messages</param>
/// <param name="storage2Name">Storage area to be used when sending SMS messages from message storage or writing SMS messages</param>
/// <param name="storage3Name">Storage area to be used when storing newly received SMS messages</param>
public PreferredMessageStorages(
PreferredMessageStorage storage1Name,
PreferredMessageStorage storage2Name,
Expand All @@ -27,22 +34,31 @@ public override string ToString()
}
}


public class PreferredMessageStorage
{
public PreferredMessageStorage(string storage1Name, int storage1Messages, int storage1MessageLocations)
/// <summary>
/// SM: SIM card storage area
/// ME: Modem storage area
/// MT: All storage combined
/// BM: Broadcast message storage area
/// SR: Status report storage area
/// TA: Terminal adaptor storage area
/// </summary>
public PreferredMessageStorage(MessageStorage storageName, int storageMessages, int storageMessageLocations)
{
Storage1Name = storage1Name;
Storage1Messages = storage1Messages;
Storage1MessageLocations = storage1MessageLocations;
StorageName = storageName;
StorageMessages = storageMessages;
StorageMessageLocations = storageMessageLocations;
}

public string Storage1Name { get; }
public int Storage1Messages { get; }
public int Storage1MessageLocations { get; }
public MessageStorage StorageName { get; }
public int StorageMessages { get; }
public int StorageMessageLocations { get; }

public override string ToString()
{
return $"Name:{Storage1Name}, Messages:{Storage1Messages}, Locations:{Storage1MessageLocations}";
return $"Name:{StorageName}, Messages:{StorageMessages}, Locations:{StorageMessageLocations}";
}
}
}
15 changes: 5 additions & 10 deletions src/HeboTech.ATLib/DTOs/SmsStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace HeboTech.ATLib.DTOs
{
public enum SmsStatus
{
REC_UNREAD,
REC_READ,
STO_UNSENT,
STO_SENT,
ALL
REC_UNREAD = 0,
REC_READ = 1,
STO_UNSENT = 2,
STO_SENT = 3,
ALL = 4
}

public static class SmsStatusHelpers
Expand All @@ -23,11 +23,6 @@ public static class SmsStatusHelpers
{ SmsStatus.STO_UNSENT, "STO UNSENT" },
};

public static SmsStatus ToSmsStatus(int statusCode)
{
return LUT.First(x => (int)x.Key == statusCode).Key;
}

public static SmsStatus ToSmsStatus(string text)
{
return LUT.First(x => x.Value == text).Key;
Expand Down
2 changes: 1 addition & 1 deletion src/HeboTech.ATLib/Events/UssdResponseEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public UssdResponseEventArgs(int status, string response, int codingScheme)

public static UssdResponseEventArgs CreateFromResponse(string response)
{
var match = Regex.Match(response, @"\+CUSD:\s(?<status>\d),""(?<message>(?s).*)"",(?<codingScheme>\d+)");
var match = Regex.Match(response, @"\+CUSD:\s(?<status>\d)(,""(?<message>(?s).*)"",(?<codingScheme>\d+))?");
if (match.Success)
{
int status = int.Parse(match.Groups["status"].Value);
Expand Down
11 changes: 0 additions & 11 deletions src/HeboTech.ATLib/Exceptions/CmeException.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/HeboTech.ATLib/HeboTech.ATLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>HeboTech</Authors>
<Product>HeboTech ATLib</Product>
<Version>7.0.0-RC1</Version>
<PackageVersion>7.0.0-RC1</PackageVersion>
<Version>7.0.0-RC2</Version>
<PackageVersion>7.0.0-RC2</PackageVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<FileVersion>7.0.0.0</FileVersion>
<PackageId>HeboTech.ATLib</PackageId>
Expand Down
Loading

0 comments on commit a7d7570

Please sign in to comment.