Example #1
0
        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);
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(proto_frame_data_t obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #3
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);
    }
Example #4
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);
    }
Example #5
0
    public static proto_DecodeStatus_t proto_decodeFrame(proto_hdle_t _this, SWIGTYPE_p_proto_Command cmd, proto_frame_data_t arg)
    {
        proto_DecodeStatus_t ret = (proto_DecodeStatus_t)protocommPINVOKE.proto_decodeFrame(proto_hdle_t.getCPtr(_this), SWIGTYPE_p_proto_Command.getCPtr(cmd), proto_frame_data_t.getCPtr(arg));

        return(ret);
    }
Example #6
0
        /* 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);
        }