コード例 #1
0
        public WallTimer(int period, Action <TimerEvent> handler, bool oneshot, RobotRaconteurNode node = null)
            : this(period, oneshot, node, AttachHandler(handler))
        {
            if (node == null)
            {
                node = RobotRaconteurNode.s;
            }

            if (RobotRaconteurNETPINVOKE.SWIGPendingException.Pending)
            {
                throw RobotRaconteurNETPINVOKE.SWIGPendingException.Retrieve();
            }
        }
コード例 #2
0
        private void SetData(object dat)
        {
            if (dat == null)
            {
                _SetData(null);
                return;
            }
            if (dat is Array)
            {
                using (RRBaseArray rb = MessageElementDataUtil.ArrayToRRBaseArray((Array)dat))
                {
                    _SetData(rb);
                }
                return;
            }

            if (dat is string)
            {
                using (RRBaseArray rb = MessageElementDataUtil.stringToRRBaseArray((string)dat))
                {
                    _SetData(rb);
                }

                return;
            }

            if (dat is MessageElementData)
            {
                _SetData((MessageElementData)dat);
                return;
            }

            string    datatype    = datatype = RobotRaconteurNode.GetTypeString(dat.GetType());
            DataTypes elementtype = DataTypeUtil.TypeIDFromString(datatype);

            if (elementtype != DataTypes.void_t && (elementtype < DataTypes.uint64_t || elementtype == DataTypes.bool_t) &&
                !(dat is Array))
            {
                object dat2 = DataTypeUtil.ArrayFromScalar(dat);

                using (RRBaseArray rb = MessageElementDataUtil.ArrayToRRBaseArray((Array)dat2))
                {
                    _SetData(rb);
                }

                return;
            }

            throw new DataTypeException("Invalid MessageElement data type");
        }
コード例 #3
0
        private void LoadAllServiceTypes(RobotRaconteurNode node)
        {
            // https://stackoverflow.com/questions/13493416/scan-assembly-for-classes-that-implement-certain-interface-and-add-them-to-a-con
            var assignableType = typeof(ServiceFactory);

            var scanners = AppDomain.CurrentDomain.GetAssemblies()
                           .ToList()
                           .SelectMany(x => x.GetTypes())
                           .Where(t => assignableType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
                           .ToList();

            foreach (Type type in scanners)
            {
                var service_factory = Activator.CreateInstance(type) as ServiceFactory;
                if (service_factory != null)
                {
                    node.RegisterServiceType(service_factory);
                }
            }
        }
コード例 #4
0
        public static RRBaseArray ArrayToRRBaseArray(Array i, RRBaseArray o)
        {
            if (i == null)
            {
                return(null);
            }
            DataTypes type = DataTypeUtil.TypeIDFromString(RobotRaconteurNode.GetTypeString(i.GetType().GetElementType()));

            if (i.Length != o.size())
            {
                throw new Exception("Length mismatch");
            }
            if (o.GetTypeID() != type)
            {
                throw new Exception("Type mismatch");
            }

            /*GCHandle h = GCHandle.Alloc(i, GCHandleType.Pinned);
             * rr_memcpy.memcpy(o.void_ptr(), h.AddrOfPinnedObject(), i.Length * o.ElementSize());
             * h.Free();*/

            switch (type)
            {
            case DataTypes.double_t: {
                var a = (double[])i;
                MessageElementDataUtil.DoublesToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.single_t: {
                var a = (float[])i;
                MessageElementDataUtil.FloatsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int8_t: {
                var a = (sbyte[])i;
                MessageElementDataUtil.BytesToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint8_t: {
                var a = (byte[])i;
                MessageElementDataUtil.BytesToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int16_t: {
                var a = (short[])i;
                MessageElementDataUtil.ShortsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint16_t: {
                var a = (ushort[])i;
                MessageElementDataUtil.ShortsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int32_t: {
                var a = (int[])i;
                MessageElementDataUtil.IntsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint32_t: {
                var a = (uint[])i;
                MessageElementDataUtil.IntsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int64_t: {
                var a = (long[])i;
                MessageElementDataUtil.LongsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint64_t: {
                var a = (ulong[])i;
                MessageElementDataUtil.LongsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.cdouble_t: {
                var a = (CDouble[])i;
                var b = new double[a.Length * 2];
                for (int j = 0; j < a.Length; j++)
                {
                    b[j * 2]     = a[j].Real;
                    b[j * 2 + 1] = a[j].Imag;
                }
                MessageElementDataUtil.DoublesToComplexRRBaseArray(b, b.Length, o);
                return(o);
            }

            case DataTypes.csingle_t: {
                var a = (CSingle[])i;
                var b = new float[a.Length * 2];
                for (int j = 0; j < a.Length; j++)
                {
                    b[j * 2]     = a[j].Real;
                    b[j * 2 + 1] = a[j].Imag;
                }
                MessageElementDataUtil.FloatsToComplexRRBaseArray(b, b.Length, o);
                return(o);
            }

            case DataTypes.bool_t: {
                var a = (bool[])i;
                var b = new byte[a.Length];
                for (int j = 0; j < a.Length; j++)
                {
                    b[j] = a[j] ? (byte)1 : (byte)0;
                }
                MessageElementDataUtil.BytesToBoolRRBaseArray(b, b.Length, o);
                return(o);
            }

            default:
                throw new DataTypeException("Invalid RRBaseArray type");
            }

            return(o);
        }