Пример #1
0
 public BPOperation(string lOperationName, int lRecvCode, int lSendCode, BinarySerializer lUplinkSerializer, BinarySerializer lDownlinkSerializer, ProcessReceivedData lCallbackDelegate, string[] lOperationGroups=null)
 {
     cOperationName = lOperationName;
     cRecvCode = lRecvCode;
     cSendCode = lSendCode;
     cUplinkSerializer = lUplinkSerializer;
     cDownlinkSerializer = lDownlinkSerializer;
     cCallbackDelegate = lCallbackDelegate;
     cOperationGroups = lOperationGroups;
 }
Пример #2
0
        private void RegisterProtocolHanders()
        {
            #region PROTOCOL_OPERATIONS_REGISTRATION
            #region COMMUNICATION_MANAGMENT_OPERATIONS
            cBPPRotocol.AddOperation(new BPOperation("MGMT_ACK",
                (int)MgmtCmd.MGMT_ACK,
                -1,
                null,
                null,
                new ProcessReceivedData(ProcessACK)));

            BinarySerializer lGetPeersDownlinkSerializer= new BinarySerializer(new Type[]{typeof(VarByte),typeof(Byte)});
            cBPPRotocol.AddOperation(new BPOperation("MGMT_GET_PEERS",
                (int)MgmtCmd.MGMT_GET_PEERS,
                (int)MgmtCmd.MGMT_GET_PEERS,
                null,
                lGetPeersDownlinkSerializer,
                new ProcessReceivedData(ProcessGetPeers)));

            BinarySerializer lNewPeerDownlinkSerializer = new BinarySerializer(new Type[] { typeof(Byte) });
            cBPPRotocol.AddOperation(new BPOperation("MGMT_NEW_PEER",
                (int)MgmtCmd.MGMT_NEW_PEER,
                -1,
                null,
                lNewPeerDownlinkSerializer,
                new ProcessReceivedData(ProcessNewPeer)));

            BinarySerializer lGetDeviceTypeDownlinkSerializer = new BinarySerializer(new Type[] { typeof(Byte) });
            cBPPRotocol.AddOperation(new BPOperation("MGMT_GET_DEVICE_TYPE",
                (int)MgmtCmd.MGMT_GET_DEVICE_TYPE,
                (int)MgmtCmd.MGMT_GET_DEVICE_TYPE,
                null,
                lGetDeviceTypeDownlinkSerializer,
                new ProcessReceivedData(ProcessDeviceType)));

            #endregion
            #region STATIC_OPERATIONS
            #region STATIC_CHAIR_OPERATIONS
            cBPPRotocol.AddOperation(new BPOperation("MGMT_MOTOR_UP",
                (int)MgmtCmd.MGMT_MOTOR_UP,
                (int)MgmtCmd.MGMT_MOTOR_UP,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_MOTOR_DOWN",
                (int)MgmtCmd.MGMT_MOTOR_DN,
                (int)MgmtCmd.MGMT_MOTOR_DN,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_MOTOR_STOP",
                (int)MgmtCmd.MGMT_MOTOR_STOP,
                (int)MgmtCmd.MGMT_MOTOR_STOP,
                null,
                null,
                null));

            BinarySerializer lGetWeight = new BinarySerializer(new Type[] { typeof(Int16), typeof(Int16) });
            cBPPRotocol.AddOperation(new BPOperation("MGMT_GET_WEIGHT",
                (int)MgmtCmd.MGMT_GET_WEIGHT,
                (int)MgmtCmd.MGMT_GET_WEIGHT,
                null,
                lGetWeight,
                new ProcessReceivedData(ProcessGetWeight),
                new string[] { "chair_read" }));

            #endregion

            cBPPRotocol.AddOperation(new BPOperation("MGMT_APP_START",
                (int)MgmtCmd.MGMT_APP_START,
                (int)MgmtCmd.MGMT_APP_START,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_APP_STOP",
                (int)MgmtCmd.MGMT_APP_STOP,
                (int)MgmtCmd.MGMT_APP_STOP,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_APP_INIT",
                (int)MgmtCmd.MGMT_APP_INIT,
                (int)MgmtCmd.MGMT_APP_INIT,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_APP_REINIT",
                (int)MgmtCmd.MGMT_APP_REINIT,
                (int)MgmtCmd.MGMT_APP_REINIT,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_SYS_RESET",
                (int)MgmtCmd.MGMT_SYS_RESET,
                (int)MgmtCmd.MGMT_SYS_RESET,
                null,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_SAVE_CONFIG",
                (int)MgmtCmd.MGMT_SAVE_CONFIG,
                (int)MgmtCmd.MGMT_SAVE_CONFIG,
                null,
                null,
                null));

            BinarySerializer lMGMT_TESTSerializer = new BinarySerializer(new Type[] { typeof(UInt32) });
            cBPPRotocol.AddOperation(new BPOperation("MGMT_APP_TEST",
                (int)MgmtCmd.MGMT_APP_TEST,
                (int)MgmtCmd.MGMT_APP_TEST,
                lMGMT_TESTSerializer,
                null,
                null));

            cBPPRotocol.AddOperation(new BPOperation("MGMT_SYS_SET_FACTORY_DEFAULT",
                (int)MgmtCmd.MGMT_SYS_SET_FACTORY_DEFAULT,
                (int)MgmtCmd.MGMT_SYS_SET_FACTORY_DEFAULT,
                null,
                null,
                null));

            #endregion
            #region TABLE_GET_SET_OPERATIONS
            #region TABLE_GET_SET_CHAIR_OPERATIONS

            DatasetRowSerializer lBASYS_ADDRSerializer = new DatasetRowSerializer(cDevices.BASYS_ADDR, 1, 2);
            cBPPRotocol.AddOperation(new BPOperation("BASYS_ADDR_READ",
                (int)MgmtCmd.MGMT_T_BASYS_ADDR_R,
                (int)MgmtCmd.MGMT_T_BASYS_ADDR_R,
                null,
                lBASYS_ADDRSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[]{"chair_read","remote_read"}));
            cBPPRotocol.AddOperation(new BPOperation("BASYS_ADDR_WRITE",
                (int)MgmtCmd.MGMT_T_BASYS_ADDR_W,
                (int)MgmtCmd.MGMT_T_BASYS_ADDR_W,
                lBASYS_ADDRSerializer,
                null,null, null));

            DatasetRowSerializer lBAFS_PRRSerializer = new DatasetRowSerializer(cDevices.BAFS_PR, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BAFS_PR_READ",
                (int)MgmtCmd.MGMT_T_BAFS_PR_R,
                (int)MgmtCmd.MGMT_T_BAFS_PR_R,
                null,
                lBAFS_PRRSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BAFS_PR_WRITE",
                (int)MgmtCmd.MGMT_T_BAFS_PR_W,
                (int)MgmtCmd.MGMT_T_BAFS_PR_W,
                lBAFS_PRRSerializer,
                null,null, null));

            DatasetRowSerializer lBAFS_PSSerializer = new DatasetRowSerializer(cDevices.BAFS_PS, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BAFS_PS_READ",
                (int)MgmtCmd.MGMT_T_BAFS_PS_R,
                (int)MgmtCmd.MGMT_T_BAFS_PS_R,
                null,
                lBAFS_PSSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BAFS_PS_WRITE",
                (int)MgmtCmd.MGMT_T_BAFS_PS_W,
                (int)MgmtCmd.MGMT_T_BAFS_PS_W,
                lBAFS_PSSerializer,
                null,null, null));

            DatasetRowSerializer lZSMI31014_EESerializer = new DatasetRowSerializer(cDevices.ZSMI31014_EE, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("ZSMI31014_EE_READ",
                (int)MgmtCmd.MGMT_T_ZSMI31014_EE_R,
                (int)MgmtCmd.MGMT_T_ZSMI31014_EE_R,
                null,
                lZSMI31014_EESerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read" }));
            cBPPRotocol.AddOperation(new BPOperation("ZSMI31014_EE_WRITE",
                (int)MgmtCmd.MGMT_T_ZSMI31014_EE_W,
                (int)MgmtCmd.MGMT_T_ZSMI31014_EE_W,
                lZSMI31014_EESerializer,
                null, null, null));

            DatasetRowSerializer lBAMOT_PRSerializer = new DatasetRowSerializer(cDevices.BAMOT_PR, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BAMOT_PR_READ",
                (int)MgmtCmd.MGMT_T_BAMOT_PR_R,
                (int)MgmtCmd.MGMT_T_BAMOT_PR_R,
                null,
                lBAMOT_PRSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BAMOT_PR_WRITE",
                (int)MgmtCmd.MGMT_T_BAMOT_PR_W,
                (int)MgmtCmd.MGMT_T_BAMOT_PR_W,
                lBAMOT_PRSerializer,
                null, null, null));

            DatasetRowSerializer lBAMOT_PSSerializer = new DatasetRowSerializer(cDevices.BAMOT_PS, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BAMOT_PS_READ",
                (int)MgmtCmd.MGMT_T_BAMOT_PS_R,
                (int)MgmtCmd.MGMT_T_BAMOT_PS_R,
                null,
                lBAMOT_PSSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BAMOT_PS_WRITE",
                (int)MgmtCmd.MGMT_T_BAMOT_PS_W,
                (int)MgmtCmd.MGMT_T_BAMOT_PS_W,
                lBAMOT_PSSerializer,
                null, null, null));

            #endregion
            #region TABLE_GET_SET_REMOTE_OPERATIONS
            DatasetRowSerializer lBAREM_PRSerializer = new DatasetRowSerializer(cDevices.BAREM_PR, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BAREM_PR_READ",
                (int)MgmtCmd.MGMT_T_BAREM_PR_R,
                (int)MgmtCmd.MGMT_T_BAREM_PR_R,
                null,
                lBAREM_PRSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "remote_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BAREM_PR_WRITE",
                (int)MgmtCmd.MGMT_T_BAREM_PR_W,
                (int)MgmtCmd.MGMT_T_BAREM_PR_W,
                lBAREM_PRSerializer,
                null, null, null));

            DatasetRowSerializer lBAREM_PSSerializer = new DatasetRowSerializer(cDevices.BAREM_PS, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BAREM_PS_READ",
                (int)MgmtCmd.MGMT_T_BAREM_PS_R,
                (int)MgmtCmd.MGMT_T_BAREM_PS_R,
                null,
                lBAREM_PSSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "remote_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BAREM_PS_WRITE",
                (int)MgmtCmd.MGMT_T_BAREM_PS_W,
                (int)MgmtCmd.MGMT_T_BAREM_PS_W,
                lBAREM_PSSerializer,
                null, null, null));

            DatasetRowSerializer lBASYS_SSerializer = new DatasetRowSerializer(cDevices.BASYS_S, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("BASYS_S_READ",
                (int)MgmtCmd.MGMT_BASYS_S_R,
                (int)MgmtCmd.MGMT_BASYS_S_R,
                null,
                lBASYS_SSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read" }));
            cBPPRotocol.AddOperation(new BPOperation("BASYS_S_WRITE",
                (int)MgmtCmd.MGMT_T_BAREM_PS_W,
                (int)MgmtCmd.MGMT_T_BAREM_PS_W,
                lBASYS_SSerializer,
                null, null, null));

            DatasetRowSerializer lSYS_INFOSerializer = new DatasetRowSerializer(cDevices.SYS_INFO_CHAIR, 1, 0);
            cBPPRotocol.AddOperation(new BPOperation("SYS_INFO_READ",
                (int)MgmtCmd.MGMT_T_SYS_INFO_R,
                (int)MgmtCmd.MGMT_T_SYS_INFO_R,
                null,
                lSYS_INFOSerializer,
                new ProcessReceivedData(ProcessTableData),
                new string[] { "chair_read", "remote_read" }));
            cBPPRotocol.AddOperation(new BPOperation("SYS_INFO_WRITE",
                (int)MgmtCmd.MGMT_T_SYS_INFO_W,
                (int)MgmtCmd.MGMT_T_SYS_INFO_W,
                lSYS_INFOSerializer,
                null, null, null));

            #endregion
            #endregion
            #endregion
        }
Пример #3
0
        public void TestMediumImport()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(string), typeof(Int16), typeof(UInt32), typeof(Int16), typeof(string) });
            Byte[] export = serializer.SerializeData(new object[] { "abcd", 100, 100000, 900, "defghi" });
            object[] import = serializer.DeserializeData(export,0,ref offset);

            Assert.AreEqual(new object[] { "abcd", (UInt16)100, (UInt32)100000, (UInt16)900, "defghi" }, import, "defghi");
            Assert.AreEqual(20, offset);
        }
Пример #4
0
        public void TestMediumExportSerialization()
        {
            BinarySerializer serializer = new BinarySerializer();

            serializer.SetSerializableTypes(new Type[] { typeof(UInt16), typeof(UInt32) });
            Byte[] output = serializer.SerializeData(new object[] { 1, 100000 });
            string CompareData = GetBinaryString(SumByteArrays(GetData(1, typeof(UInt16)), GetData(100000, typeof(UInt32))));
            Assert.AreEqual(GetBinaryString(output), CompareData);

            serializer.SetSerializableTypes(new Type[] { typeof(string) });
            output = serializer.SerializeData(new object[] { "abcd" });
            Assert.AreEqual(new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d', 0 }, output);

            serializer.SetSerializableTypes(new Type[] { typeof(string), typeof(Int16), typeof(UInt32), typeof(Int16), typeof(string) });
            output = serializer.SerializeData(new object[] { "abcd", 100, 100000, 900, "defghi" });
            CompareData = GetBinaryString(SumByteArrays(new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d', 0 }, GetData(100, typeof(Int16)), GetData(100000, typeof(Int32)), GetData(900, typeof(Int16)), new byte[] { (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', 0 }));
            Assert.AreEqual(GetBinaryString(output), CompareData);
        }
Пример #5
0
        public void TestManyParse()
        {
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(VarByte), typeof(UInt16) });
            object[] TestData= new object[]{ 5, 1, 2, 3, 4, 5 };

            Byte[] export = serializer.SerializeData(TestData);
            int offset=0;
            object[] import = serializer.DeserializeData(export, 0, ref offset);

            Assert.AreEqual(TestData, import);

            serializer.SetSerializableTypes(new Type[] { typeof(VarUInt32), typeof(string), typeof(Int16), typeof(VarUInt16), typeof(Byte) });
            TestData = new object[] { 5, "a", "b", "c", "d", "e", 10, 3, 1, 2, 3 };
            export = serializer.SerializeData(TestData);
            offset = 0;
            import = serializer.DeserializeData(export, 0, ref offset);

            Assert.AreEqual(TestData, import);
        }
Пример #6
0
        public void TestClassParse()
        {
            BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(test2) });
            test2 t2= new test2();
            t2.a1=1;
            t2.a2=2;
            t2.a3=3;
            t2.a4=4;

            int off = 0;
            byte[] serData= serializer.SerializeData(new object[] { t2 });
            test2 desData = (test2)serializer.DeserializeData(serData, 0, ref off)[0];

            Assert.AreEqual(t2.a1, desData.a1);
            Assert.AreEqual(t2.a2, desData.a2);
            Assert.AreEqual(t2.a3, desData.a3);
            Assert.AreEqual(t2.a4, desData.a4);
        }
Пример #7
0
        public void TestByteSerialize()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(Byte[]) });

            Byte[] input = new Byte[] { 1, 2, 3, 4, 5 };
            Byte[] export = serializer.SerializeData(new object[] { input });

            object[] import = serializer.DeserializeData(export, 0, ref offset);
            Assert.AreEqual(input, import[0]);
        }
Пример #8
0
        public void TestBasicImport()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(UInt16) });
            Byte[] export = serializer.SerializeData(new object[] { 1 });
            object[] import = serializer.DeserializeData(export,0,ref offset);

            Assert.AreEqual(new object[] { (UInt16)1 }, import);
            Assert.AreEqual(2, offset);
        }
Пример #9
0
 public void TestBasicExportSerialization()
 {
     BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(UInt16) });
     Byte[] output = serializer.SerializeData(new object[] { 1 });
     Assert.AreEqual(GetBinaryString(output), "0000000000000001");
 }
Пример #10
0
 public static Byte[] GetData(object data, Type type)
 {
     BinarySerializer serializer = new BinarySerializer(new Type[] { type });
     Byte[] output = serializer.SerializeData(new object[] { data });
     return output;
 }
Пример #11
0
 public void SetStaticSerializer(BinarySerializer lStaticSerializer)
 {
     cHeaderSerializer= lStaticSerializer;
 }