Skip to content

Commit

Permalink
A2类支持获取网络信息
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 25, 2023
1 parent 6743d46 commit 402831c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions SmartA2/A2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NewLife;
using NewLife.IoT.Controllers;
using NewLife.Serial.Protocols;
using SmartA2.Net;

namespace SmartA2;

Expand Down Expand Up @@ -144,5 +145,23 @@ public void SetHostName(String name)
if (!flag) File.AppendAllText(file, $"\r\n127.0.0.1\t{name}\t{name}\r\n");
}
}

/// <summary>获取网络信息</summary>
/// <returns></returns>
public NetInfo GetNetInfo()
{
using var module = new NetModule();
module.Open();

for (var i = 0; i < 3; i++)
{
var inf = module.GetNetInfo();
if (!inf.IMEI.IsNullOrEmpty()) return inf;

if (i < 3 - 1) Thread.Sleep(1000);
}

return null;
}
#endregion
}
13 changes: 13 additions & 0 deletions SmartA2/Net/NetInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SmartA2.Net;

/// <summary>网络信息</summary>
public class NetInfo
{
public String IMEI { get; set; }

Check warning on line 6 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-publish

Missing XML comment for publicly visible type or member 'NetInfo.IMEI'

Check warning on line 6 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-test

Missing XML comment for publicly visible type or member 'NetInfo.IMEI'

public String IMSI { get; set; }

Check warning on line 8 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-publish

Missing XML comment for publicly visible type or member 'NetInfo.IMSI'

Check warning on line 8 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-test

Missing XML comment for publicly visible type or member 'NetInfo.IMSI'

public String ICCID { get; set; }

Check warning on line 10 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-publish

Missing XML comment for publicly visible type or member 'NetInfo.ICCID'

Check warning on line 10 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-test

Missing XML comment for publicly visible type or member 'NetInfo.ICCID'

public Int32 CSQ { get; set; }

Check warning on line 12 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-publish

Missing XML comment for publicly visible type or member 'NetInfo.CSQ'

Check warning on line 12 in SmartA2/Net/NetInfo.cs

View workflow job for this annotation

GitHub Actions / build-test

Missing XML comment for publicly visible type or member 'NetInfo.CSQ'
}
16 changes: 16 additions & 0 deletions SmartA2/Net/NetModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,20 @@ public String GetState()
return rs.Message;
}
#endregion

#region 复合功能
/// <summary>获取网络信息</summary>
/// <returns></returns>
public NetInfo GetNetInfo()
{
var inf = new NetInfo
{
IMEI = GetIMEI(),
IMSI = GetIMSI(),
ICCID = GetICCID(),
CSQ = GetCSQ().ToInt(),
};
return inf;
}
#endregion
}
10 changes: 10 additions & 0 deletions Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NewLife.IoT.Drivers;
using NewLife.IoT.ThingModels;
using NewLife.Log;
using NewLife.Serialization;
using SmartA2;
using SmartA2.Drivers;
using SmartA2.Net;
Expand Down Expand Up @@ -93,4 +94,13 @@ static void Test3()

//Thread.Sleep(1000);
XTrace.WriteLine("LBS:\t{0}", module.GetLBS());

module.Close();

var n = "-1";
XTrace.WriteLine("n={0} n2={1}", n, n.ToInt());

var a2 = new A2();
var inf = a2.GetNetInfo();
XTrace.WriteLine(inf.ToJson(true));
}

0 comments on commit 402831c

Please sign in to comment.