Fix method, property
This commit is contained in:
Родитель
7afd15b7fd
Коммит
e2ea1a49d2
|
@ -13,8 +13,8 @@ void CbSampleRate(int32_t *input, int32_t *output) {
|
|||
if (input) g_reportRate = *input;
|
||||
}
|
||||
|
||||
void CbSquare(int32_t *input, int32_t *output) {
|
||||
*output = *input << 2;
|
||||
void CbDouble(int32_t *input, int32_t *output) {
|
||||
*output = *input << 1;
|
||||
}
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
|
@ -36,12 +36,12 @@ void setup() {
|
|||
false, // required
|
||||
true, // writeable
|
||||
(SerialPnPCb*) CbSampleRate); // callback function on update
|
||||
SerialPnP::NewCommand("square",
|
||||
"Square (power of 2)",
|
||||
"Squares a value and returns the input",
|
||||
SerialPnP::NewCommand("double",
|
||||
"Multiply by 2",
|
||||
"Doubles a value and returns the input",
|
||||
SerialPnPSchema::SchemaInt,
|
||||
SerialPnPSchema::SchemaInt,
|
||||
(SerialPnPCb*) CbSquare);
|
||||
(SerialPnPCb*) CbDouble);
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace PnpGateway.Serial
|
|||
Buffer.BlockCopy(Data, 0, fa, 0, 4);
|
||||
rxstrdata = fa[0].ToString();
|
||||
}
|
||||
else if (((Schema == Schema.Float) && (Data.Length == 4)))
|
||||
else if (((Schema == Schema.Int) && (Data.Length == 4)))
|
||||
{
|
||||
var fa = new int[1];
|
||||
Buffer.BlockCopy(Data, 0, fa, 0, 4);
|
||||
|
@ -158,13 +158,8 @@ namespace PnpGateway.Serial
|
|||
// Now query all properties to get PnP the updated value
|
||||
foreach (var property in this.Interfaces[0].Properties)
|
||||
{
|
||||
var rxPacket = await TxNameDataAndRxResponse(0, property.Name, 0x07, null);
|
||||
|
||||
byte[] rxPayload = new byte[rxPacket.Length - (6 + property.Name.Length)];
|
||||
Buffer.BlockCopy(rxPacket, 6 + property.Name.Length, rxPayload, 0, rxPayload.Length);
|
||||
|
||||
var rxPayload = await TxNameDataAndRxResponse(0, property.Name, 0x07, null);
|
||||
var stval = BinarySchemaToString(property.DataSchema, rxPayload);
|
||||
|
||||
this.PnpInterface.WriteProperty(property.Name, stval);
|
||||
}
|
||||
|
||||
|
@ -247,11 +242,8 @@ namespace PnpGateway.Serial
|
|||
var inputPayload = StringSchemaToBinary(target.RequestSchema, input);
|
||||
|
||||
// execute method
|
||||
var rxPacket = await TxNameDataAndRxResponse(0, target.Name, 0x05, inputPayload);
|
||||
|
||||
byte[] rxPayload = new byte[rxPacket.Length - (6 + target.Name.Length)];
|
||||
Buffer.BlockCopy(rxPacket, 6 + target.Name.Length, rxPayload, 0, rxPayload.Length);
|
||||
|
||||
var rxPayload = await TxNameDataAndRxResponse(0, target.Name, 0x05, inputPayload);
|
||||
|
||||
var stval = BinarySchemaToString(target.ResponseSchema, rxPayload);
|
||||
|
||||
return stval;
|
||||
|
@ -270,10 +262,7 @@ namespace PnpGateway.Serial
|
|||
var inputPayload = StringSchemaToBinary(target.DataSchema, input);
|
||||
|
||||
// execute method
|
||||
var rxPacket = await TxNameDataAndRxResponse(0, target.Name, 0x07, inputPayload);
|
||||
|
||||
byte[] rxPayload = new byte[rxPacket.Length - (6 + target.Name.Length)];
|
||||
Buffer.BlockCopy(rxPacket, 6 + target.Name.Length, rxPayload, 0, rxPayload.Length);
|
||||
var rxPayload = await TxNameDataAndRxResponse(0, target.Name, 0x07, inputPayload);
|
||||
|
||||
var stval = BinarySchemaToString(target.DataSchema, rxPayload);
|
||||
|
||||
|
@ -408,7 +397,7 @@ namespace PnpGateway.Serial
|
|||
|
||||
var rxstrdata = BinarySchemaToString(ev.DataSchema, rxData);
|
||||
|
||||
Console.WriteLine("Got new event " + event_name + " with data size " + rxDataSize + " schema " + ev.DataSchema.ToString () + " " + rxstrdata);
|
||||
//Console.WriteLine("Got new event " + event_name + " with data size " + rxDataSize + " schema " + ev.DataSchema.ToString () + " " + rxstrdata);
|
||||
|
||||
if (DeviceClient != null)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,8 @@ namespace PnpGateway
|
|||
public Func<string, string, Task> propertyHandler;
|
||||
public Func<string, string, Task<string>> methodHandler;
|
||||
|
||||
public bool eventson = false;
|
||||
|
||||
public PnPInterface(string v, PnpDeviceClient deviceClient, Func<string, string, Task> propertyHandler, Func<string, string, Task<string>> methodHandler)
|
||||
{
|
||||
this.Id = v;
|
||||
|
@ -30,27 +32,28 @@ namespace PnpGateway
|
|||
|
||||
internal void WriteProperty(string name, string stval)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
internal void BindCommand(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
internal void BindEvent(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
internal void BindProperty(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
internal void SendEvent(string event_name, string rxstrdata)
|
||||
{
|
||||
Console.WriteLine("Got event " + event_name + " : " + rxstrdata);
|
||||
if (eventson)
|
||||
Console.WriteLine("EVENT : " + event_name + " : " + rxstrdata);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using PnpGateway;
|
||||
using PnpGateway.Serial;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SerialPnPUtility
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace SerialPnPUtility
|
|||
static void Main(string[] args)
|
||||
{
|
||||
SerialPnPDevice dev = null;
|
||||
PnpDeviceClient dclient = null;
|
||||
PnpDeviceClient dclient = new PnpDeviceClient();
|
||||
|
||||
while (true) {
|
||||
string command = Console.ReadLine();
|
||||
|
@ -22,6 +23,64 @@ namespace SerialPnPUtility
|
|||
dev.Start();
|
||||
}
|
||||
|
||||
else if (cmd[0].Equals("list"))
|
||||
{
|
||||
Console.WriteLine("Listing commands, interface " + dev.Interfaces[0].Id);
|
||||
if (cmd[1].Equals("c")) {
|
||||
foreach (var c in dev.Interfaces[0].Commands)
|
||||
{
|
||||
Console.WriteLine("COMMAND : " + c.Name);
|
||||
Console.WriteLine("\t Display Name: " + c.DisplayName);
|
||||
Console.WriteLine("\t Description : " + c.Description);
|
||||
Console.WriteLine("\t Req Schema : " + c.RequestSchema.ToString());
|
||||
Console.WriteLine("\t Resp Schema : " + c.ResponseSchema.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
else if (cmd[1].Equals("p"))
|
||||
{
|
||||
Console.WriteLine("Listing properties, interface " + dev.Interfaces[0].Id);
|
||||
foreach (var c in dev.Interfaces[0].Properties)
|
||||
{
|
||||
Console.WriteLine("PROPERTY : " + c.Name);
|
||||
Console.WriteLine("\t Display Name: " + c.DisplayName);
|
||||
Console.WriteLine("\t Description : " + c.Description);
|
||||
Console.WriteLine("\t Units : " + c.Units);
|
||||
Console.WriteLine("\t Schema : " + c.DataSchema.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
else if (cmd[1].Equals("e"))
|
||||
{
|
||||
Console.WriteLine("Listing events, interface " + dev.Interfaces[0].Id);
|
||||
foreach (var c in dev.Interfaces[0].Events)
|
||||
{
|
||||
Console.WriteLine("EVENT : " + c.Name);
|
||||
Console.WriteLine("\t Display Name: " + c.DisplayName);
|
||||
Console.WriteLine("\t Description : " + c.Description);
|
||||
Console.WriteLine("\t Units : " + c.Units);
|
||||
Console.WriteLine("\t Schema : " + c.DataSchema.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (cmd[0].Equals("e"))
|
||||
{
|
||||
dclient.iface.eventson = !dclient.iface.eventson;
|
||||
}
|
||||
|
||||
else if (cmd[0].Equals("sp"))
|
||||
{
|
||||
dclient.iface.propertyHandler(cmd[1], cmd[2]);
|
||||
}
|
||||
|
||||
else if (cmd[0].Equals("xc")) {
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var res = await dclient.iface.methodHandler(cmd[1], cmd[2]);
|
||||
Console.WriteLine("RET : " + res);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,4 +5,13 @@
|
|||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\PnpGateway\Serial\SerialPnPDevice.cs" Link="SerialPnPDevice.cs" />
|
||||
<Compile Include="..\PnpGateway\Serial\SerialPnPPacketInterface.cs" Link="SerialPnPPacketInterface.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.IO.Ports" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче