Exemple #1
0
    public static SWIGTYPE_p_proto_Command copy_proto_Command_t_p(proto_Command_t value)
    {
        global::System.IntPtr    cPtr = protocommPINVOKE.copy_proto_Command_t_p((int)value);
        SWIGTYPE_p_proto_Command ret  = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_proto_Command(cPtr, false);

        return(ret);
    }
        public int WriteRegisterToDevice(byte uiRegister, byte value)
        {
            proto_Frame_t      frame = new proto_Frame_t();
            proto_Command_t    cmd   = proto_Command_t.proto_CMD_SET;
            proto_frame_data_t data  = new proto_frame_data_t();

            data.req.reg   = uiRegister;
            data.req.value = value;
            byte nbBytes = protocomm.proto_makeFrame(frame, cmd, data);

            byte[] buffer = new byte[protocomm.sizeof_proto_Frame_t()];
            protocomm.protoframe_serialize(frame, buffer);

            // Create a protocole instance from frame decoding (device will not be used)
            proto_IfaceIODevice_t protodev = protocomm.devemulslave_create();
            var protoHdle = protocomm.proto_master_create(protodev);

            int ret = _devHandle.connection.BulkTransfer(_devHandle.ep_out, buffer, 0, buffer.Length, BULK_XFER_TOUT_MS);

            if (ret >= 0)
            {
                Log.Debug(DroidPandaVcom.LOG_TAG, "xfer : successfully sent nb bytes : " + ret);
                // Receive the reply frame
                // First version - take the answer with the max size possible
                // Remember that the protocol expect the peer to seed **at most** the max frame size.
                // We reuse the buffer as R/W frame size are constant
                ret = _devHandle.connection.BulkTransfer(_devHandle.ep_in, buffer, 0, protocomm.sizeof_proto_Frame_t(), BULK_XFER_TOUT_MS);
                if (ret >= 0)
                {
                    ret = protocomm.proto_pushToFrame(protoHdle, buffer, (uint)ret);
                    if (ret >= 0)
                    {
                        var pcmd = protocomm.new_proto_Command_t_p();
                        switch (protocomm.proto_decodeFrame(protoHdle, pcmd, data))
                        {
                        case proto_DecodeStatus_t.proto_COMPLETED:
                            ret = (protocomm.proto_Command_t_p_value(pcmd) == proto_Command_t.proto_CMD_REPLY) ? 0 : 1;
                            break;

                        case proto_DecodeStatus_t.proto_REFUSED:
                            ret = -1;
                            break;

                        default:
                            break;
                        }

                        protocomm.delete_proto_Command_t_p(pcmd);
                    }
                }
                else
                {
                    Log.Debug(DroidPandaVcom.LOG_TAG, "xfer : failed to sent bytes");
                }
            }
            return(ret);
        }
Exemple #3
0
    public static proto_Command_t proto_Command_t_p_value(SWIGTYPE_p_proto_Command obj)
    {
        proto_Command_t ret = (proto_Command_t)protocommPINVOKE.proto_Command_t_p_value(SWIGTYPE_p_proto_Command.getCPtr(obj));

        return(ret);
    }
Exemple #4
0
 public static void proto_Command_t_p_assign(SWIGTYPE_p_proto_Command obj, proto_Command_t value)
 {
     protocommPINVOKE.proto_Command_t_p_assign(SWIGTYPE_p_proto_Command.getCPtr(obj), (int)value);
 }
Exemple #5
0
    public static byte proto_makeFrame(proto_Frame_t frame, proto_Command_t command, proto_frame_data_t args)
    {
        byte ret = protocommPINVOKE.proto_makeFrame(proto_Frame_t.getCPtr(frame), (int)command, proto_frame_data_t.getCPtr(args));

        return(ret);
    }
Exemple #6
0
    public static byte proto_getArgsSize(proto_Command_t cmd)
    {
        byte ret = protocommPINVOKE.proto_getArgsSize((int)cmd);

        return(ret);
    }
Exemple #7
0
    public static int proto_writeFrame(proto_hdle_t _this, proto_Command_t command, proto_frame_data_t args)
    {
        int ret = protocommPINVOKE.proto_writeFrame(proto_hdle_t.getCPtr(_this), (int)command, proto_frame_data_t.getCPtr(args));

        return(ret);
    }
        /* TODO : put in common with the write register method */
        public int ReadRegisterFromDevice(byte uiRegister, ref byte value)
        {
            // Build the request frame using dllCom
            proto_Frame_t      frame = new proto_Frame_t();
            proto_Command_t    cmd   = proto_Command_t.proto_CMD_GET;
            proto_frame_data_t data  = new proto_frame_data_t();

            data.req.reg   = uiRegister;
            data.req.value = 0;
            byte nbBytes = protocomm.proto_makeFrame(frame, cmd, data);

            byte[] buffer = new byte[protocomm.sizeof_proto_Frame_t()];
            protocomm.protoframe_serialize(frame, buffer);

            // Create a protocole instance from frame decoding (device will not be used)
            proto_IfaceIODevice_t protodev = protocomm.devemulslave_create();
            var protoHdle = protocomm.proto_master_create(protodev);

            // Send request and receive reply
            int ret = _devHandle.connection.BulkTransfer(_devHandle.ep_out, buffer, 0, buffer.Length, BULK_XFER_TOUT_MS);

            if (ret >= 0)
            {
                Log.Debug(DroidPandaVcom.LOG_TAG, "xfer : successfully sent nb bytes : " + ret);
                // Receive the reply frame
                // First version - take the answer with the max size possible
                // TODO : Handle timeout as done by the library and returns its error.
                // We reuse the buffer as R/W frame size are constant
                ret = _devHandle.connection.BulkTransfer(_devHandle.ep_in, buffer, 0, protocomm.sizeof_proto_Frame_t(), BULK_XFER_TOUT_MS);
                if (ret >= 0)
                {
                    ret = protocomm.proto_pushToFrame(protoHdle, buffer, (uint)ret);
                    if (ret >= 0)
                    {
                        var pcmd = protocomm.new_proto_Command_t_p();
                        switch (protocomm.proto_decodeFrame(protoHdle, pcmd, data))
                        {
                        case proto_DecodeStatus_t.proto_COMPLETED:
                            if (protocomm.proto_Command_t_p_value(pcmd) == proto_Command_t.proto_CMD_REPLY)
                            {
                                value = data.reg_value;
                                ret   = 0;
                            }
                            else
                            {
                                ret = -1;
                            }
                            break;

                        case proto_DecodeStatus_t.proto_REFUSED:
                            ret = -1;
                            break;

                        default:
                            break;
                        }
                        protocomm.delete_proto_Command_t_p(pcmd);
                    }
                }
                else
                {
                    Log.Debug(DroidPandaVcom.LOG_TAG, "read : failed to read nb bytes");
                }
            }
            else
            {
                Log.Debug(DroidPandaVcom.LOG_TAG, "write : failed to sent nb bytes");
            }
            return(ret);
        }