1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using FObjBase;
using FObjSysTest.IService;
using FObjSysTest.OBJ_INTERFACE;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FObjSysTest.Client
{
public class ObjAServiceClient : FObj, IObjAService
{
public DateTime Now { get; private set; }
public double[] Numbers { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
IFConn conn;
UInt32 serverId;
Stopwatch stopwatch = new Stopwatch();
public ObjAServiceClient(UInt32 serverId)
{
this.serverId = serverId;
}
public void GetNumbers(double offset, AsyncCBHandler asyncDelegate, object asyncState)
{
var request = new Pack_CallGetNumbersRequest()
{
offset = offset
};
string json = JsonConvert.SerializeObject(request);
CurrObjSys.CallFunctionEx(conn, serverId, ID,
OBJA_OBJ_INTERFACE.CALL_GETNUMBERS, Misc.Converter.StringToBytes(json), asyncDelegate, asyncState);
}
public void Apply()
{
var p = new OBJA_OBJ_INTERFACE.Pack_Params() {
numbers = Numbers
};
string json = JsonConvert.SerializeObject(p);
CurrObjSys.SetValueEx(
conn, serverId,ID,
OBJA_OBJ_INTERFACE.SET_PARAMS, Misc.Converter.StringToBytes(json));
}
#region FObj
public override void ConnectNotify(IFConn from)
{
conn = from;
if (conn.IsConnected)
{
CurrObjSys.GetValueEx(conn, serverId, ID, OBJA_OBJ_INTERFACE.GET_PARAMS);
CurrObjSys.GetValueEx(conn, serverId, ID, OBJA_OBJ_INTERFACE.GET_STATUS);
CurrObjSys.SenseConfigEx(conn, serverId, ID, 0xffffffff, SENSE_CONFIG.ADD);
stopwatch.Start();
}
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid)
{
case OBJA_OBJ_INTERFACE.CALL_GETNUMBERS:
{
string json = Misc.Converter.BytesToString(retdata);
var p = JsonConvert.DeserializeObject<Pack_CallGetNumbersReponse>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
} break;
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
PushGetValue(from, srcid, infoid, infodata);
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case OBJA_OBJ_INTERFACE.GET_PARAMS:
{
stopwatch.Stop();
Console.WriteLine($"PushGetValue OBJA_OBJ_INTERFACE.GET_PARAMS stopwatch = {stopwatch.ElapsedMilliseconds}ms");
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<OBJA_OBJ_INTERFACE.Pack_Params>(json);
Numbers = p.numbers;
}
break;
case OBJA_OBJ_INTERFACE.GET_STATUS:
{
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<OBJA_OBJ_INTERFACE.Pack_Status>(json);
Now = p.now;
} break;
}
}
#endregion
}
}