public override bool TrySetMember(SetMemberBinder binder, object value) { //look for field foreach (var p in node.properties.Keys) { if (p.Replace(" ", "") == binder.Name) { ccParameter param = node.properties[p]; int len = 0; if (param.Value.GetType().IsArray) { len = Math.Min(((Array)value).Length, ((Array)param.Value).Length); System.Array.Copy((Array)value, (Array)param.Value, len); } else { param.Value = value; } setProperty(param, 0, len); return(true); } } return(false); }
public List <string> GetEnumList() { // TODO tidy. quick fix enumeration values are held in another ccParameter // with an index held in the ArrayLen field ccParameter enumList = Owner.getParamByIdx((byte)ArrayLen); if (enumList != null && enumList.Value != null) { return(((string[])(enumList.Value)).ToList()); } else { return(new List <string>()); } }
public object getProperty(ccParameter param, int start, int num) { //send request message routedMessage m = new routedMessage(node.address, new byte[] { 0x03, (byte)param.Index, (byte)start, (byte)num }); MessageSubscription sub = new MessageSubscription() { singleShot = true, sent = m }; con.SendRoutedMessage(m, 0, sub); //wait for reply asyncWaitForReply(sub, defaultTimeout); //decode message param.parseValue(sub.reply); return(param.Value); }
public void setArrayItemFromInt(int paramIdx, int arrayIdx, int value) { ccParameter param = node.getParamByIdx(paramIdx); switch (param.TypeIdx) { case ccParameter.CC_UINT8_ARRAY: ((byte[])param.Value)[arrayIdx] = (byte)value; break; case ccParameter.CC_INT8_ARRAY: ((sbyte[])param.Value)[arrayIdx] = (sbyte)value; break; case ccParameter.CC_UINT16_ARRAY: ((UInt16[])param.Value)[arrayIdx] = (UInt16)value; break; case ccParameter.CC_INT16_ARRAY: ((Int16[])param.Value)[arrayIdx] = (Int16)value; break; case ccParameter.CC_UINT32_ARRAY: ((UInt32[])param.Value)[arrayIdx] = (UInt32)value; break; case ccParameter.CC_INT32_ARRAY: ((Int32[])param.Value)[arrayIdx] = (Int32)value; break; default: throw new Exception(" routed object setArrayItemFromInt type not handled " + param.TypeIdx); } setProperty(param, arrayIdx, 1); }
public void setProperty(ccParameter param, int start, int num) { //assume value already set in local param uint nBlocks = 1; uint blockSize = 0; if (param.Value.GetType().IsArray) { if (start >= param.ArrayLen) { throw (new Exception("Set routed Property index too big")); } num = Math.Min(num, (int)param.ArrayLen - start); //calc number of blocks to send blockSize = 32; nBlocks = ((uint)num - 1) / blockSize + 1; } UInt32 startidx = (UInt32)start; for (int i = 0; i < nBlocks; i++) { byte size = (byte)Math.Min(blockSize, start + num - startidx); routedMessage m = new routedMessage(node.address, param.buildSetCmd(startidx, size)); MessageSubscription sub = new MessageSubscription() { singleShot = true, sent = m }; con.SendRoutedMessage(m, 0, sub); //wait for ack asyncWaitForReply(sub, defaultTimeout); //TODO check ack? startidx += blockSize; } }
public int getItemAsInt(int paramIdx) { ccParameter param = node.getParamByIdx(paramIdx); getProperty(param, 0, 0); switch (param.TypeIdx) { case ccParameter.CC_BOOL: return((bool)param.Value?1:0); case ccParameter.CC_UINT8: return((int)((byte)param.Value)); case ccParameter.CC_INT8: return((int)((sbyte)param.Value)); case ccParameter.CC_UINT16: return((int)((UInt16)param.Value)); case ccParameter.CC_INT16: return((int)((Int16)param.Value)); case ccParameter.CC_UINT32: return((int)((UInt32)param.Value)); case ccParameter.CC_INT32: return((int)((Int32)param.Value)); default: throw new Exception(" routed object getItemAsInt type not handled " + param.TypeIdx); } }
public int getArrayItemAsInt(int paramIdx, int arrayIdx) { ccParameter param = node.getParamByIdx(paramIdx); getProperty(param, arrayIdx, 1); //TODO make work for all array types switch (param.TypeIdx) { case ccParameter.CC_UINT8_ARRAY: return((int)((byte[])param.Value)[arrayIdx]); case ccParameter.CC_INT8_ARRAY: return((int)((sbyte[])param.Value)[arrayIdx]); case ccParameter.CC_UINT16_ARRAY: return((int)((UInt16[])param.Value)[arrayIdx]); case ccParameter.CC_INT16_ARRAY: return((int)((Int16[])param.Value)[arrayIdx]); case ccParameter.CC_UINT32_ARRAY: return((int)((UInt32[])param.Value)[arrayIdx]); case ccParameter.CC_INT32_ARRAY: return((int)((Int32[])param.Value)[arrayIdx]); default: throw new Exception(" routed object getArrayItemAsInt type not handled " + param.TypeIdx); } }
public void setItemFromInt(int paramIdx, int value) { ccParameter param = node.getParamByIdx(paramIdx); switch (param.TypeIdx) { case ccParameter.CC_BOOL: param.Value = value == 0?false:true; break; case ccParameter.CC_UINT8: param.Value = (byte)value; break; case ccParameter.CC_INT8: param.Value = (sbyte)value; break; case ccParameter.CC_UINT16: param.Value = (UInt16)value; break; case ccParameter.CC_INT16: param.Value = (Int16)value; break; case ccParameter.CC_UINT32: param.Value = (UInt32)value; break; case ccParameter.CC_INT32: param.Value = (Int32)value; break; default: throw new Exception(" routed object setItemFromInt type not handled " + param.TypeIdx); } setProperty(param, 0, 0); }