From 03b18081862f727ae20d9499ab52bd732cb323b4 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Sat, 9 Nov 2019 20:53:04 -0600 Subject: [PATCH 1/2] Added support for signed integer json reading --- .../JsonToSimpl/JsonToSimplChildObjectBase.cs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs index 2d74bbb..49512c7 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs @@ -137,20 +137,22 @@ namespace PepperDash.Core.JsonToSimpl // OnBoolChange(false, index, JsonToSimplConstants.BoolValueChange); } - // Processes the path to a ushort, converting to ushort if able, firing off UshrtChange event - void ProcessUshortPath(ushort index) - { - string response; - if (Process(UshortPaths[index], out response)) - { - ushort val; - try { val = Convert.ToUInt16(response); } - catch { val = 0; } - OnUShortChange(val, index, JsonToSimplConstants.UshortValueChange); - } - else { } - // OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange); - } + // Processes the path to a ushort, converting to ushort if able, twos complement if necessary, firing off UshrtChange event + void ProcessUshortPath(ushort index) { + string response; + if (Process(UshortPaths[index], out response)) { + ushort returnVal; + short val; + try { val = Convert.ToInt16(response); } + catch { val = 0; } + + returnVal = val < 0 ? (ushort)(val + 65536) : (ushort)val; + + OnUShortChange(returnVal, index, JsonToSimplConstants.UshortValueChange); + } + else { } + // OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange); + } // Processes the path to a string property and fires of a StringChange event. void ProcessStringPath(ushort index) From c59608d7b90247a7605e02c03f072c371d8271ac Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Sat, 9 Nov 2019 21:14:39 -0600 Subject: [PATCH 2/2] Fixed issues with parsing large ushort values --- .../JsonToSimpl/JsonToSimplChildObjectBase.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs index 49512c7..cdd4ccd 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs @@ -141,14 +141,11 @@ namespace PepperDash.Core.JsonToSimpl void ProcessUshortPath(ushort index) { string response; if (Process(UshortPaths[index], out response)) { - ushort returnVal; - short val; - try { val = Convert.ToInt16(response); } + ushort val; + try { val = Convert.ToInt32(response) < 0 ? (ushort)(Convert.ToInt16(response) + 65536) : Convert.ToUInt16(response); } catch { val = 0; } - returnVal = val < 0 ? (ushort)(val + 65536) : (ushort)val; - - OnUShortChange(returnVal, index, JsonToSimplConstants.UshortValueChange); + OnUShortChange(val, index, JsonToSimplConstants.UshortValueChange); } else { } // OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange);