static void Main(string[] args) { MainArgs arg = MainArgs.ValueOf(args); client = new DtuClient( arg.Get(MainArgs.KEY_SERVER_IP, "127.0.0.1"), arg.GetInt(MainArgs.KEY_SERVER_PORT, 5055) ); client.OnReceived += OnMsg; client.Connect(20120049, "18651895100", "218.3.150.108"); Thread t = new Thread(DoWork); t.Start(); t.Join(); }
public void TestAtCommandExecutor() { GprsDtuServer _server = new GprsDtuServer(5055); _server.Start(); string dtu = "12345678"; Thread.Sleep(500); if (client.Connect(12345678, "22222222", "127.0.0.2")) { Console.WriteLine("Connected"); } else { Console.WriteLine("ERROR"); } client.OnReceived = (msg, len) => client.Send("OK"); Thread.Sleep(500); GprsDtuConnection conn = (GprsDtuConnection)_server.GetConnection(new DtuNode { DtuCode = dtu }); ATCommand cmd = new EnterConfig(); CommandExecutor ce = new CommandExecutor(); Assert.IsNotNull(conn); if (conn != null && conn.IsAvaliable()) { ATCommandResult r = ce.Execute(conn, cmd); Assert.IsTrue(r.IsOK); } if (conn != null && conn.IsAvaliable()) { cmd = new SetPort("{'port':5008}"); ATCommandResult r = ce.Execute(conn, cmd); Assert.IsTrue(r.IsOK); } if (conn != null && conn.IsAvaliable()) { cmd = new SetPort("{'port':5009"); ATCommandResult r = ce.Execute(conn, cmd); Assert.IsTrue(r.IsOK); } }
[Timeout(10000)] // 10s public void TestReceiver() { DtuClient c = new DtuClient("127.0.0.1", 6066); TranDataReceiver r = new TranDataReceiver(new GprsDtuServer(6066)); r.Start(); c.Connect(20120049, "18900000000", "192.168.1.222"); c.OnReceived = (buff, len) => { Thread.Sleep(500); var msg = @"FA 2A 0C 00 01 74 01 FF 00 00 02 63 00 39 30 38 56 7A 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 38 56 7A 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 B8 70 80 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 B8 70 80 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 60 BA 01 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 60 BA 01 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 00 28 1C 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 00 28 1C 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 30 13 B0 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 30 13 B0 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 C0 E3 30 2A 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 C0 E3 30 2A 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 AF"; log.DebugFormat("[Client] Sending data..."); c.Send(ValueHelper.StrToToHexByte(msg)); }; // heartbeat, 激励 c.Send(new HeartBeatTranMsg(20120049, 0).Marshall()); int receivedCnt = 0; r.OnTranMsgReceived += (TranMsgType type, TranMsg msg) => { TranMsg m2 = msg; log.DebugFormat("[Server] Msg Received: id={3}, type={0},len={1}, pkg={2}", type, msg.LoadSize, msg.PackageCount, msg.ID); if (msg.ID == 0) { Assert.AreEqual(TranMsgType.HeartBeat, type); } else { Assert.AreEqual(TranMsgType.Dac, type); } receivedCnt++; }; while (receivedCnt <= 5) { Thread.Sleep(10); } c.Close(); log.DebugFormat("Test Done."); Assert.IsTrue(true); }
public void TestMsSqlInstantTask() { // Client Simulator client = new DtuClient("127.0.0.1", 5055); client.OnReceived += OnMsg; GprsDtuServer _server = new GprsDtuServer(5055); _server.Start(); client.Connect(20120049, "18651895100", "192.168.1.42"); DbAccessorHelper.Init(new MsDbAccessor(this.mssqlConnStr)); // Thread.Sleep(8000); string tid = new Guid().ToString(); List <uint> sensors = new List <uint> { (uint)17 }; DACTask ut = new DACTask(tid, 1, sensors, TaskType.INSTANT, this.OnTaskFinished); // tm = new DACTaskManager(_server, DbAccessorHelper.DbAccessor.QueryDtuNodes(), DbAccessorHelper.DbAccessor.GetUnfinishedTasks()); // tm.DealDailyWork(); // Thread.Sleep(8000); int r = tm.ArrangeInstantTask(tid, 1, sensors, this.OnTaskFinished, false); System.Console.WriteLine("result = {0}", r); }