Commit 55d27899 by xjp0422

clientid设置为suid ini文件格式修改 主题改为四层 ip和port 从ini文件读取并连接服务器 不再用原来命令行参数方式

parent 0563a3d1
No preview for this file type
......@@ -5,30 +5,24 @@ namespace Mqtt_AGI
enum systemID {
SERVER=1,UI,DEVICE,AGI,OAM
}
enum AGI_Module {CACL_TLE=1,CACL_REPORT }
enum Server_Module { CACL_TLE = 1, CACL_REPORT }
//分解string类型的主题 工具类 暂时用不到
class ParseUid
{
public static uint getlevel1(string topic)
{
return (Convert.ToUInt32(topic) & 0xf0000000) >> 28;
return (Convert.ToUInt32(topic,2) & 0xf0000000) >> 28;
}
public static uint getlevel2(string topic)
{
return (Convert.ToUInt32(topic) & 0x0f000000) >> 24;
return (Convert.ToUInt32(topic,2) & 0x0f000000) >> 24;
}
public static uint getlevel3(string topic)
{
return (Convert.ToUInt32(topic) & 0x00f00000) >> 20;
return (Convert.ToUInt32(topic,2) & 0x00f00000) >> 20;
}
public static uint getsystem(string topic)
{
return (Convert.ToUInt32(topic) & 0x000f0000) >> 16;
}
public static uint getsymodule(string topic)
{
return (Convert.ToUInt32(topic) & 0x0000f000) >> 12;
return (Convert.ToUInt32(topic,2) & 0x000f0000) >> 16;
}
}
......@@ -43,18 +37,10 @@ namespace Mqtt_AGI
return Convert.ToString(numtopic, 2).PadLeft(32, '0');//uint转string 32位 前面补0
}
//由level id生成system id 和 module id
public static string SerilizeString(string level_uid, systemID system, uint module)
//由level_uid生成level_system_uid 和
public static string SerilizeString(string level_uid, systemID system)
{
return Convert.ToString((Convert.ToUInt32(level_uid) | ((uint)system << 16) | (((uint)module) << 12)), 2).PadLeft(32, '0');
}
//指定module id
public static string SerilizeString(string level_system_uid, uint module) {
return Convert.ToString( (Convert.ToUInt32(level_system_uid) |(((uint)module)<<12)) ,2).PadLeft(32,'0');
return Convert.ToString((Convert.ToUInt32(level_uid,2) | (((uint)system) << 16) ), 2).PadLeft(32, '0');
}
}
}
......@@ -43,11 +43,11 @@ namespace Mqtt_AGI
[DllImport("kernel32")]
private static extern long GetPrivateProfileString(string section, string key, string defa, StringBuilder buffer, int size, string filePath);
static MqttClient client = null; //主机为IP时
static string clientId = Guid.NewGuid().ToString();
//static string clientId = Guid.NewGuid().ToString();
static string ip, port;
static int count = 0;
static string LevelUid= getLevelUid();
static string LevelUid = getLevelUid();
static string clientId = SerializeUid.SerilizeString(LevelUid, systemID.AGI);
//获取配置信息中的站点等级信息 生成LevelUid
static string getLevelUid()
{
......@@ -58,7 +58,9 @@ namespace Mqtt_AGI
GetPrivateProfileString("role", "level1", "0", level1, 16, IniPath);
GetPrivateProfileString("role", "level2", "0", level2, 16, IniPath);
GetPrivateProfileString("role", "level3", "0", level3, 16, IniPath);
return SerializeUid.SerilizeString(Convert.ToUInt32(level1), Convert.ToUInt32(level2), Convert.ToUInt32(level3));
Console.WriteLine(SerializeUid.SerilizeString(Convert.ToUInt32(level1.ToString()), Convert.ToUInt32(level2.ToString()), Convert.ToUInt32(level3.ToString())));
return SerializeUid.SerilizeString(Convert.ToUInt32(level1.ToString()), Convert.ToUInt32(level2.ToString()), Convert.ToUInt32(level3.ToString()));
//Console.WriteLine(Convert.ToString(subTopic,2).PadLeft(32,'0'));//32位 前面补0
}
......@@ -74,7 +76,7 @@ namespace Mqtt_AGI
for (int messageNum = 0; messageNum < datastruct.Parameters.Count; ++messageNum)
{
Parameter = datastruct.Parameters[messageNum];
if (e.Topic == SerializeUid.SerilizeString(LevelUid, systemID.AGI, ((uint)AGI_Module.CACL_REPORT)))
if(datastruct.Cmd == TDSCmd.Types.IID.AgiReport)
{
CalcReportReq CalcReport = Parameter.Unpack<CalcReportReq>();
string[] args = { CalcReport.StartDateTime,CalcReport.EndDateTime,
......@@ -87,7 +89,7 @@ namespace Mqtt_AGI
CalcReport.Line0,CalcReport.Line1,CalcReport.Line2};
calc_report(args);//轨道预报
}
else if (e.Topic == SerializeUid.SerilizeString(LevelUid, systemID.AGI, ((uint)AGI_Module.CACL_TLE)))
else if (datastruct.Cmd == TDSCmd.Types.IID.AgiTle)
{
CalcTleReq CalcTle = Parameter.Unpack<CalcTleReq>();
string[] args = { CalcTle.NoradID.ToString(), CalcTle.NoradName,
......@@ -128,6 +130,7 @@ namespace Mqtt_AGI
{
// continue;
Console.WriteLine(ex.Message);
Console.WriteLine("client_MqttConnectionClosed异常");
return;
}
......@@ -137,17 +140,18 @@ namespace Mqtt_AGI
try
{
client.Connect(clientId, "", "", false, 30);
//level1/level2/level3/system/module
//level1/level2/level3/system
client.Subscribe(new string[] { SerializeUid.SerilizeString(LevelUid, systemID.AGI, ((uint)AGI_Module.CACL_TLE)) }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Subscribe(new string[] { SerializeUid.SerilizeString(LevelUid, systemID.AGI) }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Subscribe(new string[] { "xyz_topic_parameter" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Subscribe(new string[] { SerializeUid.SerilizeString(LevelUid, systemID.AGI, ((uint)AGI_Module.CACL_REPORT)) }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
//client.Subscribe(new string[] { SerializeUid.SerilizeString(LevelUid, systemID.AGI) }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
Console.WriteLine("Connect state:" + client.IsConnected);
}
catch (Exception ex)
{
// continue;
Console.WriteLine(ex.Message);
Console.WriteLine("MqttConnect异常");
return;
}
}
......@@ -159,12 +163,17 @@ namespace Mqtt_AGI
// Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Form1());
if (args.Length == 2)
{
try
{
ip = args[0];
port = args[1];
//从配置文件获取ip port
StringBuilder ip_build = new StringBuilder(32);
StringBuilder port_build = new StringBuilder(32);
string IniPath = System.Windows.Forms.Application.StartupPath + "\\config.ini";
GetPrivateProfileString("mqtt-local", "server", "0", ip_build, 32, IniPath);
GetPrivateProfileString("mqtt-local", "port", "0", port_build, 32, IniPath);
ip = ip_build.ToString();port = port_build.ToString();
Console.WriteLine(ip+" "+port);
client = new MqttClient(ip, int.Parse(port), false, null, null, MqttSslProtocols.None);
MqttConnect(ref client);
// 注册消息接收处理事件,还可以注册消息订阅成功、取消订阅成功、与服务器断开等事件处理函数
......@@ -176,22 +185,16 @@ namespace Mqtt_AGI
{
// continue;
Console.WriteLine(ex.Message);
return;
}
Console.WriteLine("Main 异常");
}
else
{
Console.WriteLine("Mqtt_AGI:need args [ip] [port].");
System.Environment.Exit(0);
return;
}
}
static void calc_tle(string [] args) //精轨转TLE
{
if (args.Count() < 14) return; //参数不够13个,无法计算
if (args.Count() < 14) { Console.WriteLine("args<14"); return; } //参数不够13个,无法计算
string noradid = "00000";
System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$"); //纯数字
if (rex.IsMatch(args[0])) //修改卫星双行根数中的卫星编号,卫星编号必须是五位为纯数字,否则无法做预报
......@@ -236,21 +239,25 @@ namespace Mqtt_AGI
//初始化包配置
TDSCmd MessageSend =new TDSCmd();
MessageSend.Cmd = TDSCmd.Types.IID.AgiTle;
MessageSend.DstSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.SERVER, ((uint)Server_Module.CACL_TLE)));
MessageSend.SrcSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.AGI, ((uint)AGI_Module.CACL_TLE)));
MessageSend.ForwardFlag = 0;//不需要回复
MessageSend.Cmd = TDSCmd.Types.IID.AgiTleRespond;
MessageSend.DstSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.SERVER));
MessageSend.SrcSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.AGI));
MessageSend.ForwardFlag = 0;//不需要转发
//加载数据段
Any Parameter = Any.Pack(calctleret);
MessageSend.Parameters.Add(Parameter);
client.Publish(SerializeUid.SerilizeString(LevelUid, systemID.SERVER, ((uint)Server_Module.CACL_TLE)), MessageSend.ToByteArray());
client.Publish(SerializeUid.SerilizeString(LevelUid, systemID.SERVER), MessageSend.ToByteArray());
//client.Publish("server/response/agi/tle", System.Text.Encoding.Default.GetBytes(line0+";"+line1+";"+line2));
Console.WriteLine(line0);
Console.WriteLine(line1);
Console.WriteLine(line2);
Console.WriteLine("pacakge length:" + MessageSend.ToByteArray().Length);
Console.WriteLine("Sucess send count:" + (++count));
//client.Publish("server/response/agi/tle", System.Text.Encoding.Default.GetBytes(line0+";"+line1+";"+line2));
}
......@@ -414,18 +421,18 @@ namespace Mqtt_AGI
//end
string report;
//string report;
report = nid + " " + sdate + " " + stime + " " + edate + " " + etime + " " + startAr + " " + endAr + " " + startEr + " " + maxEr + " " + index + " " + minDist + " " + maxDist + " " + slice + " " + circle + " " + XxdFileName + " " + "\r\n";
report_Message += report;
//report = nid + " " + sdate + " " + stime + " " + edate + " " + etime + " " + startAr + " " + endAr + " " + startEr + " " + maxEr + " " + index + " " + minDist + " " + maxDist + " " + slice + " " + circle + " " + XxdFileName + " " + "\r\n";
//report_Message += report;
//Console.WriteLine(report_Message);
//client.Publish("server/response/agi/report", System.Text.Encoding.Default.GetBytes(report_Message)); //将本圈次任务信息发布出去
/*本圈次任务点位信息*/
string linedata;
//string linedata;
//JArray DataArray = new JArray();//生成data json对象
for (int j = 0; j < count; j++)
......@@ -499,7 +506,7 @@ namespace Mqtt_AGI
int xxd_step = Convert.ToInt32(xxdcjjg); //星下点采集间隔设置
string xxd_line;
//string xxd_line;
//JArray XxdArray = new JArray();//生成xxd json对象
for (int j = 0; j < pyb.Detail_Dot_Fixed.Count; j = j +xxd_step)
{
......@@ -516,9 +523,9 @@ namespace Mqtt_AGI
string latstring, longstring;
latstring = lattitude.ToString("0.00");
longstring = longtitude.ToString("0.00");
xxd_line = laa.DateTime_UTCG.ToString("yyyyMMdd HH:mm:ss.fff") + " " + laa.X_Metre.ToString("0.00") + " " + laa.Y_Metre.ToString("0.00") + " " + laa.Z_Metre.ToString("0.00") + " " +latstring + " " +longstring + " " + laa.Altitude_Metre.ToString("0.00") + " \r\n";
//xxd_line = laa.DateTime_UTCG.ToString("yyyyMMdd HH:mm:ss.fff") + " " + laa.X_Metre.ToString("0.00") + " " + laa.Y_Metre.ToString("0.00") + " " + laa.Z_Metre.ToString("0.00") + " " +latstring + " " +longstring + " " + laa.Altitude_Metre.ToString("0.00") + " \r\n";
//xxd_line = laa.DateTime_UTCG.ToLocalTime().ToString("yyyyMMdd HH:mm:ss.fff") + " " + 0 + " " + 0 + " " + 0 + " " + latstring + " " + longstring + " " + 0 + ";";
xxd_Message += xxd_line;
//xxd_Message += xxd_line;
//protobuf xxd begin
......@@ -558,15 +565,15 @@ namespace Mqtt_AGI
//protobuf begin
//初始化包配置
TDSCmd MessageSend = new TDSCmd();
MessageSend.Cmd = TDSCmd.Types.IID.AgiReport;
MessageSend.DstSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.SERVER, ((uint)Server_Module.CACL_REPORT)));
MessageSend.SrcSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.AGI, ((uint)AGI_Module.CACL_REPORT)));
MessageSend.ForwardFlag = 0;//不需要回复
MessageSend.Cmd = TDSCmd.Types.IID.AgiReportRespond;
MessageSend.DstSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.SERVER));
MessageSend.SrcSUID = Convert.ToUInt32(SerializeUid.SerilizeString(LevelUid, systemID.AGI));
MessageSend.ForwardFlag = 0;//不需要转发
//加载数据段
Any Parameter = Any.Pack(CalcReport);
MessageSend.Parameters.Add(Parameter);
client.Publish(SerializeUid.SerilizeString(LevelUid, systemID.SERVER, ((uint)Server_Module.CACL_REPORT)), MessageSend.ToByteArray());
client.Publish(SerializeUid.SerilizeString(LevelUid, systemID.SERVER), MessageSend.ToByteArray());
//protobuf end
......
......@@ -3,8 +3,8 @@ level1=1
level2=2
level3=3
[mqtt-local]
server=null
port=null
server=127.0.0.1
port=1883
[mqtt-cloud]
server=null
port=null
\ No newline at end of file
server=127.0.0.1
port=1883
\ No newline at end of file
[role]
level1:1
level2:2
level3:3
level1=1
level2=2
level3=3
[mqtt-local]
server:
port:
server=127.0.0.1
port=1883
[mqtt-cloud]
server:
port:
\ No newline at end of file
server=127.0.0.1
port=1883
\ No newline at end of file
db2993a2800aeb7dc1754e20ffa465e6754241e0
b30ae5d6ea524ee0ee189b3222a07c4c6c7596c1
......@@ -27,3 +27,24 @@ D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Debug\System.Buffers.xml
D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Debug\System.Memory.xml
D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Debug\System.Runtime.CompilerServices.Unsafe.xml
D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\obj\Debug\Mqtt_AGI.csproj.AssemblyReference.cache
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Mqtt_AGI.exe.config
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Mqtt_AGI.exe
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Mqtt_AGI.pdb
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Google.Protobuf.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\M2Mqtt.Net.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Newtonsoft.Json.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\System.Buffers.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\System.Memory.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\System.Runtime.CompilerServices.Unsafe.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Google.Protobuf.pdb
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Google.Protobuf.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\M2Mqtt.Net.pdb
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\Newtonsoft.Json.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\System.Buffers.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\System.Memory.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Debug\System.Runtime.CompilerServices.Unsafe.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Debug\Mqtt_AGI.csproj.AssemblyReference.cache
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Debug\Mqtt_AGI.csproj.CoreCompileInputs.cache
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Debug\Mqtt_AGI.csproj.CopyComplete
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Debug\Mqtt_AGI.exe
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Debug\Mqtt_AGI.pdb
309040c17457bc65ae603286f7165730ab1aff9e
dc8766d0c3caf9d64c8ee1044151fbc91b8aab4f
......@@ -35,3 +35,28 @@ D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Release\Google.Protobuf.xml
D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Release\System.Buffers.xml
D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Release\System.Memory.xml
D:\MQTT_AGI\Mqtt_AGI\Kepler_J20002TLE\bin\Release\System.Runtime.CompilerServices.Unsafe.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Mqtt_AGI.exe.config
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Mqtt_AGI.exe
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Mqtt_AGI.pdb
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\AGI.Foundation.Core.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\AGI.Foundation.Models.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\AGI.Foundation.Platforms.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Basic_Astrodynamics.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Google.Protobuf.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\M2Mqtt.Net.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Newtonsoft.Json.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\System.Buffers.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\System.Memory.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\System.Runtime.CompilerServices.Unsafe.dll
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Google.Protobuf.pdb
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Google.Protobuf.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\M2Mqtt.Net.pdb
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\Newtonsoft.Json.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\System.Buffers.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\System.Memory.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\bin\Release\System.Runtime.CompilerServices.Unsafe.xml
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Release\Mqtt_AGI.csproj.AssemblyReference.cache
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Release\Mqtt_AGI.csproj.CoreCompileInputs.cache
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Release\Mqtt_AGI.csproj.CopyComplete
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Release\Mqtt_AGI.exe
D:\gitlab\MQTT_AGI_hy\Kepler_J20002TLE\obj\Release\Mqtt_AGI.pdb
......@@ -46,32 +46,32 @@ message CalcReportReq{
}
//AGI返回:任务预报report
message CalcReportRet{
repeated Xxd xxds = 1;
repeated Task tasks = 2;
repeated Xxd xxds = 1; //星下点
repeated Task tasks = 2; //任务预报信息
}
//星下点
message Xxd{
string dt=1;
double lon=2;
double lat=3;
double height=4;
string dt=1; //时间
double lon=2; //经度
double lat=3; //纬度
double height=4; //高度
}
//单圈次任务预报
message Task{
string start=1;
string end=2;
double startAzi=3;
double endAzi=4;
double startEle=5;
double maxEle=6;
double minDist=7;
double maxDist=8;
repeated Obs obss = 9;
string start=1; //开始时间
string end=2; //结束时间
double startAzi=3; //开始方位角
double endAzi=4; //结束方位角
double startEle=5; //开始俯仰角
double maxEle=6; //最大俯仰角
double minDist=7; //最短距离
double maxDist=8; //最大距离
repeated Obs obss = 9; //方位角俯仰角信息
}
//dat文件俯仰角方位角
message Obs{
string dt=1;
double azi=2;
double ele=3;
double range=4;
string dt=1; //时间
double azi=2; //方位角
double ele=3; //俯仰角
double range=4; //距离
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment