Skip to content

Commit

Permalink
Přidány instrukce CmdSetStatus a CmdGetStatus + drobné úpravy v kódu.
Browse files Browse the repository at this point in the history
  • Loading branch information
Papouchcom committed Jun 12, 2018
1 parent a881461 commit 8568483
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
Binary file modified Latest/Papouch.Quido.dll
Binary file not shown.
Binary file modified Latest/Papouch.Quido.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion Papouch.Spinel/Spinel97.Device.Quido.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public Boolean CmdSetCounterSettings(byte index, bool rising, bool falling)
txPacket.ADR = this.ADR;
PacketSpinel97 rxPacket;

if (SendAndReceive(ref txPacket, out rxPacket) & (rxPacket.INST == (byte)ResponseACK.AllIsOk))
if (SendAndReceive(ref txPacket, out rxPacket) && (rxPacket.INST == (byte)ResponseACK.AllIsOk))
{
return true;
}
Expand Down
64 changes: 57 additions & 7 deletions Papouch.Spinel/Spinel97.Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace Papouch.Spinel.Spinel97.Device
{
public class Device : CsPropertyObject
{
public byte S97_INST_ReadInfo = 0xF3; // Čtení informací o výrobku (typové)
public byte S97_INST_ReadSN = 0xFA; // Čtení výrobních údajů
public byte S97_INST_ReadInfo = 0xF3; // Čtení informací o výrobku (typové)
public byte S97_INST_ReadSN = 0xFA; // Čtení výrobních údajů
public byte S97_INST_ReadStatus = 0xF1; // Čtení statusu
public byte S97_INST_SetStatus = 0xE1; // Nastavení statusu

internal ICommunicationInterface ci = null;
private byte fADR = 0xFE;
Expand All @@ -34,11 +36,10 @@ public Boolean CmdGetInfo(out SpinelDeviceVersion version)
if ((ci != null) && (ci.Active))
{
PacketSpinel97 txPacket = new PacketSpinel97(S97_INST_ReadInfo);
txPacket.ADR = fADR;
txPacket.ADR = this.ADR;

PacketSpinel97 rxPacket;

// if (Spinel97Utils.SendAndReceive(ref this.ci, ref txPacket, out rxPacket))
if (this.SendAndReceive(ref txPacket, out rxPacket))
{

Expand All @@ -57,7 +58,7 @@ public Boolean CmdGetSN(out SpinelDeviceSN dev_sn)
if ((ci != null) && (ci.Active))
{
PacketSpinel97 txPacket = new PacketSpinel97(S97_INST_ReadSN);
txPacket.ADR = fADR;
txPacket.ADR = this.ADR;

PacketSpinel97 rxPacket;

Expand All @@ -71,6 +72,57 @@ public Boolean CmdGetSN(out SpinelDeviceSN dev_sn)
return false;
}

/// <summary>
/// Přečte uživatelsky definované číslo, které lze využít k zjištění stavu přístroje.
/// </summary>
/// <param name="dev_status">Int s platným rozsahem 0 až 255. Pokud je -1, čtení se nepodařilo a i výstupem instrukce je false.</param>
/// <returns>true = přečtení statusu se podařilo</returns>
public Boolean CmdGetStatus(out int dev_status)
{
if ((ci != null) && (ci.Active))
{
PacketSpinel97 txPacket = new PacketSpinel97(S97_INST_ReadStatus);
txPacket.ADR = this.ADR;

PacketSpinel97 rxPacket;

if (SendAndReceive(ref txPacket, out rxPacket) && (rxPacket.INST == (byte)ResponseACK.AllIsOk))
{
if ((rxPacket.SDATA != null) && (rxPacket.SDATA.Length == 1))
{
dev_status = (int)rxPacket.SDATA[0];
return true;
}
}
}
dev_status = -1;
return false;
}

/// <summary>
/// Nastaví uživatelsky definované číslo, které lze využít k zjištění stavu přístroje.
/// </summary>
/// <param name="dev_status">Po zapnutí přístroje, nebo po resetu (i softwarovém) je
/// automaticky nastaven status 0x00. Pokud je touto funkcí status přestaven na jinou
/// hodnotu, lze později snadno identifikovat, v jakém stavu se přístroj nachází.</param>
/// <returns></returns>
public Boolean CmdSetStatus(byte dev_status)
{
if ((ci != null) && (ci.Active))
{
byte[] data = { dev_status };

PacketSpinel97 txPacket = new PacketSpinel97(S97_INST_SetStatus, data);
txPacket.ADR = this.ADR;

PacketSpinel97 rxPacket;

if (SendAndReceive(ref txPacket, out rxPacket) && (rxPacket.INST == (byte)ResponseACK.AllIsOk))
return true;
}
return false;
}


[CsProperty("ADR", 0xFE)]
public byte ADR
Expand Down Expand Up @@ -148,8 +200,6 @@ private void bwListen_DoWork(object sender, DoWorkEventArgs e)
{
SpinelStackRec ssr = packets_to_send.Peek();
packets_to_send.Dequeue();
//packets_to_send[0];
//packets_to_send.RemoveAt(0);

byte[] txData = ssr.tx_packet.GetBin();
ci.Write(txData, 0, txData.Length);
Expand Down

0 comments on commit 8568483

Please sign in to comment.