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

SMS Deliver Report #45

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
107 changes: 80 additions & 27 deletions src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HeboTech.ATLib.DTOs;
using HeboTech.ATLib.Events;
using HeboTech.ATLib.Modems.Cinterion;
using HeboTech.ATLib.Modems.D_LINK;
using HeboTech.ATLib.Modems.Generic;
using HeboTech.ATLib.Parsers;
using System;
Expand All @@ -17,17 +18,29 @@ 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 IMC55i modem = new MC55i(atChannel);
//using IDWM222 modem = new DWM222(atChannel);
atChannel.Open();
await atChannel.ClearAsync();

modem.ErrorReceived += Modem_ErrorReceived;

modem.GenericEvent += Modem_GenericEvent;

modem.IncomingCall += Modem_IncomingCall;
modem.MissedCall += Modem_MissedCall;
modem.CallStarted += Modem_CallStarted;
modem.CallEnded += Modem_CallEnded;

modem.SmsStorageReferenceReceived += Modem_SmsStorageReferenceReceived;
modem.SmsReceived += Modem_SmsReceived;

modem.SmsStatusReportReceived += Modem_SmsStatusReportReceived;
modem.SmsStatusReportStorageReferenceReceived += Modem_SmsStatusReportStorageReferenceReceived;

modem.BroadcastMessageReceived += Modem_BroadcastMessageReceived;
modem.BroadcastMessageStorageReferenceReceived += Modem_BroadcastMessageStorageReferenceReceived;

modem.UssdResponseReceived += Modem_UssdResponseReceived;
modem.ErrorReceived += Modem_ErrorReceived;
modem.GenericEvent += Modem_GenericEvent;

// Configure modem with required settings before PIN
var requiredSettingsBeforePin = await modem.SetRequiredSettingsBeforePinAsync();
Expand Down Expand Up @@ -81,14 +94,6 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
var batteryStatus = await modem.GetBatteryStatusAsync();
Console.WriteLine($"Battery Status: {batteryStatus}");

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

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

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

var selectMessageService = await modem.SetSelectMessageService(0);
Console.WriteLine($"Setting select message service: {selectMessageService}");

var newSmsIndicationResult = await modem.SetNewSmsIndicationAsync(2, 1, 0, 0, 1);
var newSmsIndicationResult = await modem.SetNewSmsIndicationAsync(2, 1, 0, 2, 0); // 2, 1, 0, 2, 0 (CSMS=0)
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(MessageStorage.SM, MessageStorage.SM, MessageStorage.SM);
var setPreferredStorages = await modem.SetPreferredMessageStorageAsync(MessageStorage.MT, MessageStorage.MT, MessageStorage.MT);
Console.WriteLine($"Storages set:{Environment.NewLine}{setPreferredStorages}");

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, 'x' to send raw command, 'z' to send raw command with response, '+' 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, 'p' to delete an SMS, 'u' to send USSD code, 'x' to send raw command, 'z' to send raw command with response, '+' to enable debug, '-' to disable debug and 'q' to exit...");
ConsoleKey key;
while ((key = Console.ReadKey().Key) != ConsoleKey.Q)
{
Expand Down Expand Up @@ -164,21 +171,38 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
string smsMessage = Console.ReadLine();

Console.WriteLine("Sending SMS...");
IEnumerable<ModemResponse<SmsReference>> smsReferences = await modem.SendSmsAsync(phoneNumber, smsMessage);
IEnumerable<ModemResponse<SmsReference>> smsReferences = await modem.SendSmsAsync(new SmsSubmitRequest(phoneNumber, smsMessage) { EnableStatusReportRequest = true, ValidityPeriod = ValidityPeriod.Relative(RelativeValidityPeriods.Minutes_5) });
foreach (var smsReference in smsReferences)
Console.WriteLine($"SMS Reference: {smsReference}");
break;
}
case ConsoleKey.R:
Console.WriteLine("Enter SMS index:");
if (int.TryParse(Console.ReadLine(), out int smsIndex))
{
var sms = await modem.ReadSmsAsync(smsIndex);
Console.WriteLine(sms);
Console.WriteLine("Enter SMS index:");
if (int.TryParse(Console.ReadLine(), out int smsIndex))
{
var sms = await modem.ReadSmsAsync(smsIndex);
if (sms.Success)
{
Console.WriteLine(sms.Result);
}
}
else
Console.WriteLine("Invalid SMS index");
break;
}
case ConsoleKey.P:
{
Console.WriteLine("Enter SMS index:");
if (int.TryParse(Console.ReadLine(), out int smsIndex))
{
var deleteResponse = await modem.DeleteSmsAsync(smsIndex);
Console.WriteLine(deleteResponse);
}
else
Console.WriteLine("Invalid SMS index");
break;
}
else
Console.WriteLine("Invalid SMS index");
break;
case ConsoleKey.U:
Console.WriteLine("Enter USSD Code:");
var ussd = Console.ReadLine();
Expand All @@ -188,10 +212,14 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
case ConsoleKey.L:
Console.WriteLine("List all SMSs:");
var smss = await modem.ListSmssAsync(SmsStatus.ALL);
Console.WriteLine($"{smss.Result.Count} SMSs:");
if (smss.Success && smss.Result.Any())
{
foreach (var sms in smss.Result)
Console.WriteLine($"------------------------------------------------{Environment.NewLine}{sms}");
{
Console.WriteLine($"------------------------------------------------");
Console.WriteLine($"Index: {sms.Index}, {sms.Sms}");
}
Console.WriteLine($"------------------------------------------------");
}

Expand All @@ -208,6 +236,36 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
}
}

private static void Modem_BroadcastMessageStorageReferenceReceived(object sender, BreadcastMessageStorageReferenceReceivedEventArgs e)
{
Console.WriteLine($"Broadcast Message. Index {e.Index} at storage location {e.Storage}");
}

private static void Modem_SmsStorageReferenceReceived(object sender, SmsStorageReferenceReceivedEventArgs e)
{
Console.WriteLine($"SMS Deliver. Index {e.Index} at storage location {e.Storage}");
}

private static void Modem_SmsStatusReportStorageReferenceReceived(object sender, SmsStatusReportStorageReferenceEventArgs e)
{
Console.WriteLine($"SMS Status Report. Index {e.Index} at storage location {e.Storage}");
}

private static void Modem_BroadcastMessageReceived(object sender, BreadcastMessageReceivedEventArgs e)
{
Console.WriteLine($"Broadcast Message: {e.BroadcastMessage}");
}

private static void Modem_SmsReceived(object sender, SmsReceivedEventArgs e)
{
Console.WriteLine($"SMS Deliver: {e.SmsDeliver}");
}

private static void Modem_SmsStatusReportReceived(object sender, SmsStatusReportEventArgs e)
{
Console.WriteLine($"SMS Status Report: {e.SmsStatusReport}");
}

private static void Modem_GenericEvent(object sender, GenericEventArgs e)
{
Console.WriteLine($"Generic event: {e.Message}");
Expand All @@ -234,11 +292,6 @@ private static void Modem_CallStarted(object sender, CallStartedEventArgs e)
Console.WriteLine("Call started");
}

private static void Modem_SmsReceived(object sender, SmsReceivedEventArgs e)
{
Console.WriteLine($"SMS received. Index {e.Index} at storage location {e.Storage}");
}

private static void Modem_MissedCall(object sender, MissedCallEventArgs e)
{
Console.WriteLine($"Missed call at {e.Time} from {e.PhoneNumber}");
Expand Down
2 changes: 1 addition & 1 deletion src/HeboTech.ATLib.TestConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static async Task Main(string[] args)

/* ######## 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);
socket.Connect("192.168.1.5", 7000);
Console.WriteLine("Network socket opened");
Stream stream;
stream = new NetworkStream(socket);
Expand Down
4 changes: 2 additions & 2 deletions src/HeboTech.ATLib.TestConsole/StressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)

modem.IncomingCall += Modem_IncomingCall;
modem.MissedCall += Modem_MissedCall;
modem.SmsReceived += Modem_SmsReceived;
modem.SmsStorageReferenceReceived += Modem_SmsReceived;

await modem.DisableEchoAsync();

Expand Down Expand Up @@ -73,7 +73,7 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
Console.ReadKey();
}

private static void Modem_SmsReceived(object sender, Events.SmsReceivedEventArgs e)
private static void Modem_SmsReceived(object sender, Events.SmsStorageReferenceReceivedEventArgs e)
{
Console.WriteLine($"SMS received. Index {e.Index} at storage location {e.Storage}");
}
Expand Down
6 changes: 2 additions & 4 deletions src/HeboTech.ATLib.Tests/PDU/SmsSubmitEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public void Encode_SmsSubmit_test(string countryCode, string subscriberNumber, s
encodedMessage,
dataCodingScheme)
{
IncludeEmptySmscLength = includeEmptySmscLength,
MessageReferenceNumber = 12
});
}, includeEmptySmscLength);

Assert.Equal(answer, encoded.ToArray());
}
Expand All @@ -57,10 +56,9 @@ public void Encode_SmsSubmit_message_too_long_test(string countryCode, string su
new string('a', characterCount),
dataCodingScheme)
{
IncludeEmptySmscLength = includeEmptySmscLength,
MessageReferenceNumber = 12
};
Assert.Throws<ArgumentException>(() => SmsSubmitEncoder.Encode(request).ToList());
Assert.Throws<ArgumentException>(() => SmsSubmitEncoder.Encode(request, includeEmptySmscLength).ToList());
}
}
}
9 changes: 9 additions & 0 deletions src/HeboTech.ATLib/DTOs/BroadcastMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace HeboTech.ATLib.DTOs
{
public class BroadcastMessage
{
public BroadcastMessage()
{
}
}
}
30 changes: 10 additions & 20 deletions src/HeboTech.ATLib/DTOs/Sms.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
using System;
using HeboTech.ATLib.PDU;

namespace HeboTech.ATLib.DTOs
{
public class Sms
{
public Sms(SmsStatus status, PhoneNumberDTO sender, DateTimeOffset receiveTime, string message)
: this(status, sender, receiveTime, message, 0, 1, 1)
protected Sms(MessageTypeIndicatorInbound messageTypeIndicator)
{
MessageTypeIndicator = messageTypeIndicator;
}

public Sms(SmsStatus status, PhoneNumberDTO sender, DateTimeOffset receiveTime, string message, int messageReferenceNumber, int totalNumberOfParts, int partNumber)
protected Sms(MessageTypeIndicatorInbound messageTypeIndicator, int messageReference)
: this(messageTypeIndicator)
{
Status = status;
Sender = sender;
ReceiveTime = receiveTime;
Message = message;
MessageReferenceNumber = messageReferenceNumber;
TotalNumberOfParts = totalNumberOfParts;
PartNumber = partNumber;
MessageReference = messageReference;
}

public SmsStatus Status { get; }
public PhoneNumberDTO Sender { get; }
public DateTimeOffset ReceiveTime { get;}
public string Message { get; }
public int MessageReferenceNumber { get; }
public int TotalNumberOfParts { get; }
public int PartNumber { get; }
public int MessageReference { get; }
public MessageTypeIndicatorInbound MessageTypeIndicator { get; }

public override string ToString()
{
return $"Sender:\t\t{Sender}{Environment.NewLine}ReceiveTime:\t{ReceiveTime}{Environment.NewLine}Ref. no.:\t{MessageReferenceNumber}{Environment.NewLine}Part:\t\t{PartNumber}/{TotalNumberOfParts}{Environment.NewLine}Message:\t{Message}";
return $"MTI: {MessageTypeIndicator}, Msg. ref.: {MessageReference}";
}
}
}
}
20 changes: 15 additions & 5 deletions src/HeboTech.ATLib/DTOs/SmsDeliver.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
using System;
using HeboTech.ATLib.PDU;
using System;

namespace HeboTech.ATLib.DTOs
{
/// <summary>
/// Data object for a received SMS
/// </summary>
public class SmsDeliver
public class SmsDeliver : Sms
{
public SmsDeliver(PhoneNumberDTO serviceCenterNumber, PhoneNumberDTO senderNumber, string message, DateTimeOffset timestamp)
: base(MessageTypeIndicatorInbound.SMS_DELIVER)
{
ServiceCenterNumber = serviceCenterNumber;
SenderNumber = senderNumber;
Message = message;
Timestamp = timestamp;
}

public SmsDeliver(PhoneNumberDTO serviceCenterNumber, PhoneNumberDTO senderNumber, string message, DateTimeOffset timestamp, int messageReferenceNumber, int totalNumberOfParts, int partNumber)
public SmsDeliver(PhoneNumberDTO serviceCenterNumber, PhoneNumberDTO senderNumber, string message, DateTimeOffset timestamp, int messageReference, int totalNumberOfParts, int partNumber)
: base(MessageTypeIndicatorInbound.SMS_DELIVER, messageReference)
{
ServiceCenterNumber = serviceCenterNumber;
SenderNumber = senderNumber;
Message = message;
Timestamp = timestamp;
MessageReferenceNumber = messageReferenceNumber;
TotalNumberOfParts = totalNumberOfParts;
PartNumber = partNumber;
}
Expand All @@ -30,8 +32,16 @@ public SmsDeliver(PhoneNumberDTO serviceCenterNumber, PhoneNumberDTO senderNumbe
public PhoneNumberDTO SenderNumber { get; }
public string Message { get; }
public DateTimeOffset Timestamp { get; }
public int MessageReferenceNumber { get; }
public int TotalNumberOfParts { get; }
public int PartNumber { get; }

public void DeliverMethod()
{
}

public override string ToString()
{
return base.ToString() + $" From: {SenderNumber}. Message: {Message}. Timestamp: {Timestamp}";
}
}
}
Loading
Loading