コード例 #1
0
        private void LicenseInfoDlg_Load(object sender, EventArgs e)
        {
            string[]      vsMacs = MacAddr.GetMacs();
            StringBuilder sb     = new StringBuilder();

            sb.Append(_sVer);   // version
            sb.Append('|');
            sb.Append(vsMacs.Length.ToString());
            sb.Append('|');
            foreach (string sMac in vsMacs)
            {
                sb.Append(sMac);
                sb.Append('|');
            }
            sb.Append(SystemInformation.ComputerName);

            string str;
            // Attempt to get Windows Registration info
            RegistryKey regKey = Registry.LocalMachine.OpenSubKey(MainFrm.WIN_REG_KEY, true);

            if (regKey != null)
            {
                str = regKey.GetValue("RegisteredOwner") as string;
                sb.Append('|');
                sb.Append(str);
                str = regKey.GetValue("RegisteredOrganization") as string;
                sb.Append('|');
                sb.Append(str);
            }
            else
            {
                sb.Append("||");
            }
            str = sb.ToString();

            Rijndael encryptor = Encryption.GetLicenseEncryptor(MainFrm.ProdKey);

            byte[] vData = Encryption.EncryptString(encryptor, str);
            str = HexEncoding.ToString(vData);

            TxtMachineId.Text = str;

            if (!string.IsNullOrEmpty(MainFrm.TheAppWnd.LicenseInfo.LicName))
            {
                LblRegName.Text = MainFrm.TheAppWnd.LicenseInfo.LicName;
            }

            if (MainFrm.TheAppWnd.LicenseInfo.ExpiryDate > DateTime.MinValue)
            {
                LblExpiryDate.Text = MainFrm.TheAppWnd.LicenseInfo.ExpiryDate.ToShortDateString();
            }
        }
コード例 #2
0
 private static void GetActiveMacAndIpAndGateway()
 {
     _mac = new MacAddr();
     try
     {
         foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
         {
             if (f.OperationalStatus == OperationalStatus.Up)
             {
                 IPInterfaceProperties ipInterface = f.GetIPProperties();
                 if (ipInterface.GatewayAddresses.Count > 0)
                 {
                     foreach (UnicastIPAddressInformation unicastAddress in ipInterface.UnicastAddresses)
                     {
                         if ((unicastAddress.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) && (unicastAddress.IPv4Mask.ToString() != "0.0.0.0"))
                         {
                             _mac.IpAddress = unicastAddress.Address.ToString();
                             var g = ipInterface.GatewayAddresses.FirstOrDefault(i => !i.Address.ToString().Equals("fe80::1%12"));
                             _mac.Gateway = ipInterface.GatewayAddresses.FirstOrDefault(i => !i.Address.ToString().Equals("fe80::1%12")).Address.ToString();
                             var activeMac = (NetworkInterface.GetAllNetworkInterfaces()
                                              .FirstOrDefault(i => i.GetIPProperties()
                                                              .UnicastAddresses.Any(c => c.Address.ToString() == _mac.IpAddress)));
                             _mac.MacId = activeMac.GetPhysicalAddress().ToString();
                             _mac.Desc  = activeMac.Description;
                             _mac.Name  = activeMac.Name;
                             _mac.NetworkInterfaceType = activeMac.NetworkInterfaceType.ToString();
                             _mac.OperationalStatus    = activeMac.OperationalStatus.ToString();
                             break;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.LogError(ex);
     }
     if (string.IsNullOrEmpty(_mac.MacId))
     {
         Logger.LogInfo("Fixed Alternate Mac Address: " + GetMACAddress());
         _mac.MacId = GetMACAddress();
     }
     Logger.LogInfo("_mac.IpAddress" + _mac.IpAddress ?? string.Empty
                    + "_mac.Gateway" + _mac.Gateway ?? string.Empty
                    + "_mac.MacId" + _mac.MacId ?? string.Empty
                    + "_mac.Desc" + _mac.Desc ?? string.Empty
                    + "_mac.Name" + _mac.Name ?? string.Empty
                    + "_mac.NetworkInterfaceType" + _mac.NetworkInterfaceType ?? string.Empty
                    + "_mac.OperationalStatus" + _mac.OperationalStatus ?? string.Empty);
 }
コード例 #3
0
        private CommNode FindMac(MacAddr ma)
        {
            CommNode res = null;

            foreach (var item in CommunicationNet.CommNodes)
            {
                if (item.MacAddr == ma)
                {
                    item.IsUpdate = true;
                    return(item);
                }
            }
            return(res);
        }
コード例 #4
0
        /// <summary>
        /// 断开选择的设备
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 断开设备toolStripButton_Click(object sender, EventArgs e)
        {
            PersonnelManagement personnelManagement = new PersonnelManagement();

            PersonnelManagement.PersonInfo person = new PersonnelManagement.PersonInfo(5);
            Stm32Sync stm32_sync = new Stm32Sync();

            stm32_sync.output_dlg = output;
            MacAddr dst_addr;

            string addr_str = dgvDeviceInfo.SelectedRows[0].Cells[2].Value.ToString();

            dst_addr = new MacAddr(addr_str);

            /* 添加用户 */
            for (int i = 0; i < personnelManagement.PersonList.Count; i++)
            {
                stm32_sync.user_add(dst_addr.Mac, personnelManagement.PersonList[i]);
            }

            /* 删除用户 */
            //stm32_sync.user_del(dst_addr.Mac, (UInt32)1);

            /* 重新加载卡号-用户号,指纹号-用户号列表 */
            stm32_sync.list_reload(dst_addr.Mac);
            return;

            int rows = dgvDeviceInfo.SelectedRows.Count;//获取选中总行数

            for (int j = 0; j < rows; j++)
            {
                if (dgvDeviceInfo.SelectedRows[j].Cells[1].Value.ToString() == "未连接")
                {
                    output("设备" + dgvDeviceInfo.SelectedRows[j].Cells[0].Value.ToString() + "未连接");
                }
                else
                {
                    dgvDeviceInfo.SelectedRows[j].Cells[1].Value = "未连接";
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 同步所有已连接设备的时间
        /// </summary>
        private void SyncTime()
        {
            Stm32Sync stm32_sync = new Stm32Sync();

            stm32_sync.output_dlg = output;
            MacAddr dst_addr;

            int row      = dgvDeviceInfo.SelectedRows.Count; /* 获取选中总行数 */
            int rowIndex = dgvDeviceInfo.CurrentRow.Index;   /* 获取选择行号 */

            for (int i = 0; i < row; i++)
            {
                if (dgvDeviceInfo.SelectedRows[i].Cells[1].Value.ToString() == "已连接")
                {
                    string addr_str = dgvDeviceInfo.SelectedRows[i].Cells[2].Value.ToString();
                    dst_addr = new MacAddr(addr_str);
                    stm32_sync.time_sync(dst_addr.Mac);
                }
            }

            is_child_thread_stop = 0;
        }
コード例 #6
0
        private void ProcessMessage(byte[] message)
        {
            string       IpAddr;
            string       MacAddr;
            string       UnitName;
            string       swVer;
            ListViewItem currentRow;
            int          i = 0;
            ListViewItem listItem;

            // TODO : Search and update
            // TODO : Add last seen column

            if ((message.Length == 118) && (message[0] == (byte)CommandNo.SSC_REPLY_PING))
            {
                IpAddr  = message[4].ToString() + "." + message[3].ToString() + "." + message[2].ToString() + "." + message[1].ToString();
                MacAddr = message[10].ToString() + ":" + message[9].ToString() + ":" + message[8].ToString() + ":" + message[7].ToString() + ":" + message[6].ToString() + ":" + message[5].ToString();

                MacAddr = BitConverter.ToString(message, 5, 6);
                MacAddr = MacAddr.Replace("-", ":");

                swVer = BitConverter.ToString(message, 11, 2);
                swVer = message[11].ToString() + "." + message[12].ToString();

                // TODO : Check Length
                UnitName = System.Text.ASCIIEncoding.ASCII.GetString(message, 13, 23);

                listItem = null;

                try
                {
                    listItem = listRemotesFound.FindItemWithText(MacAddr, true, 0);
                }
                catch (Exception)
                {
                }

                if (listItem != null)
                {
                    // found it - update it
                    if (listItem.Text != UnitName)
                    {
                        listItem.Text = UnitName;
                    }
                    if (listItem.SubItems[1].Text != IpAddr)
                    {
                        listItem.SubItems[1].Text = IpAddr;
                    }
                    if (listItem.SubItems[3].Text != swVer)
                    {
                        listItem.SubItems[3].Text = swVer;
                    }
                    if (listItem.SubItems[4].Text != message[36].ToString())
                    {
                        listItem.SubItems[4].Text = message[36].ToString();
                    }

                    listItem.SubItems[5].Text = (BitConverter.ToUInt16(message, 38).ToString());
                    listItem.SubItems[6].Text = (BitConverter.ToUInt16(message, 40).ToString());
                    listItem.SubItems[7].Text = (BitConverter.ToUInt16(message, 42).ToString());
                }
                else
                {
                    currentRow = listRemotesFound.Items.Add(UnitName);
                    currentRow.SubItems.Add(IpAddr);
                    currentRow.SubItems.Add(MacAddr);
                    currentRow.SubItems.Add(swVer);
                    // Config
                    currentRow.SubItems.Add(message[36].ToString());

                    currentRow.SubItems.Add(BitConverter.ToUInt16(message, 38).ToString());
                    currentRow.SubItems.Add(BitConverter.ToUInt16(message, 40).ToString());
                    currentRow.SubItems.Add(BitConverter.ToUInt16(message, 42).ToString());
                }

                foreach (ControlFrm controlFrm in listOfControlForms)
                {
                    if (controlFrm.Text.Contains(MacAddr))
                    {
                        controlFrm.BroadcastRecieved(message);
                        break;
                    }
                }
            }

            if ((message.Length == 68) && (message[0] == (byte)CommandNo.SSC_REPLY_CONFIG))
            {
                IpAddr  = message[4].ToString() + "." + message[3].ToString() + "." + message[2].ToString() + "." + message[1].ToString();
                MacAddr = message[10].ToString() + ":" + message[9].ToString() + ":" + message[8].ToString() + ":" + message[7].ToString() + ":" + message[6].ToString() + ":" + message[5].ToString();

                MacAddr = BitConverter.ToString(message, 5, 6);
                MacAddr = MacAddr.Replace("-", ":");

                if (listRemotesFound.Items.Count > 0)
                {
                    listItem = null;
                    try
                    {
                        listItem = listRemotesFound.FindItemWithText(MacAddr, true, 0);
                    }
                    catch (Exception)
                    {
                    }

                    if (listItem != null)
                    {
                        // found it - update it
                        listItem.SubItems[1].Text = IpAddr;
                        listItem.SubItems[4].Text = message[11].ToString();

                        EdtSubNetAddr.Text  = message[29].ToString() + "." + message[28].ToString() + "." + message[27].ToString() + "." + message[26].ToString();
                        EdtGatewayAddr.Text = message[33].ToString() + "." + message[32].ToString() + "." + message[31].ToString() + "." + message[30].ToString();
                        EdtDnsAddr.Text     = EdtGatewayAddr.Text;

                        EdtNtpOffset.Value = (decimal)((decimal)BitConverter.ToUInt16(message, 66) / (decimal)60);

                        if (listItem.Selected)
                        {
                            for (i = 0; i < 5; i++)
                            {
                                try
                                {
                                    if (0xFF == message[13 + i])
                                    {
                                        ListSolderBridges.Items[i].SubItems[1].Text = SolderBridgeNames[0];
                                    }
                                    else
                                    {
                                        ListSolderBridges.Items[i].SubItems[1].Text = SolderBridgeNames[message[13 + i]];
                                    }
                                }
                                catch (global::System.Exception)
                                {
                                    ListSolderBridges.Items[i].SubItems[1].Text = message[13 + i].ToString();
                                }
                            }

                            for (i = 0; i < 8; i++)
                            {
                                if (message[18 + i] > 0x20)
                                {
                                    byte bridgeAddr = (byte)(message[18 + i] - (byte)0x20);

                                    if (bridgeAddr < 8)
                                    {
                                        ListSolderBridges.Items[5 + bridgeAddr].SubItems[1].Text = "GPIO Expander - PORT " + (char)(0x48 + bridgeAddr);
                                    }
                                }
                                else
                                {
                                    //ListSolderBridges.Items[i + 5].SubItems[1].Text = "None";
                                }
                            }

                            UpdateConfigDisplayFlags(message[11]);

                            // Snow NTP Host name :
                            EdNtpServerAddr.Text = System.Text.ASCIIEncoding.ASCII.GetString(message, 34, 32);
                        }
                    }
                    else
                    {
                        // We dont have this unit on the list
                    }
                }
            }

            if ((message.Length == 164) && (message[0] == (byte)CommandNo.SSC_REPLY_ALL_GPIO))
            {
                MacAddr = message[10].ToString() + ":" + message[9].ToString() + ":" + message[8].ToString() + ":" + message[7].ToString() + ":" + message[6].ToString() + ":" + message[5].ToString();
                MacAddr = BitConverter.ToString(message, 5, 6);
                MacAddr = MacAddr.Replace("-", ":");

                foreach (GpioControlFrm gpioControlFrm in listOfGpioControlForms)
                {
                    if (gpioControlFrm.Text.Contains(MacAddr))
                    {
                        gpioControlFrm.GpioTableRecvd(message);
                        break;
                    }
                }
            }

            if ((message.Length == 230) && (message[0] == (byte)CommandNo.SSC_REPLY_LOGIC_ACT))
            {
                MacAddr = message[10].ToString() + ":" + message[9].ToString() + ":" + message[8].ToString() + ":" + message[7].ToString() + ":" + message[6].ToString() + ":" + message[5].ToString();
                MacAddr = BitConverter.ToString(message, 5, 6);
                MacAddr = MacAddr.Replace("-", ":");

                foreach (LogicControlFrm controlFrm in listOfLogicForms)
                {
                    if (controlFrm.Text.Contains(MacAddr))
                    {
                        controlFrm.ActionTableRecvd(message);
                        break;
                    }
                }
            }

            if ((message.Length == 230) && (message[0] == (byte)CommandNo.SSC_REPLY_LOGIC_COND))
            {
                MacAddr = message[10].ToString() + ":" + message[9].ToString() + ":" + message[8].ToString() + ":" + message[7].ToString() + ":" + message[6].ToString() + ":" + message[5].ToString();
                MacAddr = BitConverter.ToString(message, 5, 6);
                MacAddr = MacAddr.Replace("-", ":");

                foreach (LogicControlFrm controlFrm in listOfLogicForms)
                {
                    if (controlFrm.Text.Contains(MacAddr))
                    {
                        controlFrm.ConditionTableRecvd(message);
                        break;
                    }
                }
            }

            if ((message.Length == 158) && (message[0] == (byte)CommandNo.SSC_REPLY_LOGIC_EVENTS))
            {
                MacAddr = message[10].ToString() + ":" + message[9].ToString() + ":" + message[8].ToString() + ":" + message[7].ToString() + ":" + message[6].ToString() + ":" + message[5].ToString();
                MacAddr = BitConverter.ToString(message, 5, 6);
                MacAddr = MacAddr.Replace("-", ":");

                foreach (LogicControlFrm controlFrm in listOfLogicForms)
                {
                    if (controlFrm.Text.Contains(MacAddr))
                    {
                        controlFrm.EventTableRecvd(message);
                        break;
                    }
                }
            }



            BroadcastUpdatingFlag = false;
        }
コード例 #7
0
        private void ParseTOPINFORSP(byte[] srcBuffer)
        {
            int index = ParseMsgHeader(srcBuffer);

            //nodeNum
            CommunicationNet.NodeNum = BitConverter.ToUInt16(srcBuffer, index);
            index += 2;
            if (IsLittle != (_configService.ConfigInfos.CPUType == "Little"))
            {
                CommunicationNet.NodeNum = Endian.SwapUInt16(CommunicationNet.NodeNum);
            }
            //set the update sign to false
            BeginUpdateNode();
            //mac info for nodes
            for (int i = 0; i < CommunicationNet.NodeNum; i++)
            {
                byte[] tmpbuffer = new byte[MacAddr.MACADDRLEN];
                Buffer.BlockCopy(srcBuffer, index, tmpbuffer, 0, MacAddr.MACADDRLEN);
                MacAddr  ma     = new MacAddr(tmpbuffer);
                CommNode cn     = FindMac(ma);
                bool     isNull = (cn == null);
                if (isNull)
                {
                    cn = new CommNode {
                        MacAddr = ma, Index = i, IsUpdate = true
                    };
                    CommunicationNet.CommNodes.Add(cn);
                }
                cn.Index = i;


                index       += MacAddr.MACADDRLEN;
                cn.Longitude = BitConverter.ToInt32(srcBuffer, index) / 1e7;
                index       += 4;
                cn.Latitude  = BitConverter.ToInt32(srcBuffer, index) / 1e7;
                index       += 4;
                cn.Altitude  = BitConverter.ToInt32(srcBuffer, index);
                index       += 4;
                cn.NodeType  = srcBuffer[index++];
                if (isNull)
                {
                    NodeChangeEvent(this, new NodeChangeEventArg {
                        oper = Operations.ADD, Node = cn
                    });
                }
            }

            BeginUpdateLine();
            //modify the net
            byte[,] TopInfo = new byte[CommunicationNet.NodeNum, CommunicationNet.NodeNum];
            Buffer.BlockCopy(srcBuffer, index, TopInfo, 0, CommunicationNet.NodeNum * CommunicationNet.NodeNum);
            for (int i = 0; i < CommunicationNet.NodeNum; i++)
            {
                for (int j = 0; j < CommunicationNet.NodeNum; j++)
                {
                    if (i > j)
                    {
                        CommLine cl     = FindLine(i, j);
                        bool     IsNull = (cl == null);
                        if (IsNull && ((CommStatues)TopInfo[i, j] != CommStatues.NON || (CommStatues)TopInfo[j, i] != CommStatues.NON))
                        {
                            cl = new CommLine {
                                StartNode = FindNode(i), EndNode = FindNode(j), CommStatuPre = (CommStatues)TopInfo[i, j], CommStatuBac = (CommStatues)TopInfo[j, i]
                            };
                            CommunicationNet.CommLines.Add(cl);
                            LineChangeEvent(this, new LineChangeEventArg  {
                                oper = Operations.ADD, Line = cl
                            });
                        }
                        else
                        {
                            cl.CommStatuPre = (CommStatues)TopInfo[i, j];
                            cl.CommStatuBac = (CommStatues)TopInfo[j, i];

                            if (cl.CommStatuBac == CommStatues.NON && cl.CommStatuPre == CommStatues.NON)
                            {
                                LineChangeEvent(this, new LineChangeEventArg {
                                    oper = Operations.DEL, Line = cl
                                });
                                CommunicationNet.CommLines.Remove(cl);
                            }
                        }
                    }
                }
            }
            ENdUpdateLine();
            EndUpdateNode();
        }
コード例 #8
0
        /// <summary>
        /// 同步所有已连接设备的用户信息
        /// </summary>
        private void SyncUser()
        {
            output("同步用户信息");
            DeviceManagement    deviceManagement    = new DeviceManagement();
            PersonnelManagement personnelManagement = new PersonnelManagement();

            PersonnelManagement.PersonInfo person = new PersonnelManagement.PersonInfo(5);
            Stm32Sync stm32_sync = new Stm32Sync();
            Stm32_crc stm32_crc  = new Stm32_crc();
            UInt32    crc        = 0;
            MacAddr   dst_addr;
            UInt16    total;
            UInt16    count;
            UInt16    total_get = 0;

            byte[]   user_crc_byte;
            UInt32[] user_crc  = new UInt32[0];
            bool     err       = true;
            bool     is_change = false;

            stm32_sync.output_dlg = output;

            int row      = dgvDeviceInfo.SelectedRows.Count; /* 获取选中总行数 */
            int rowIndex = dgvDeviceInfo.CurrentRow.Index;   /* 获取选择行号 */

            for (int j = 0; j < row; j++)
            {
                if (dgvDeviceInfo.SelectedRows[j].Cells[1].Value.ToString() == "已连接")
                {
                    string addr_str = dgvDeviceInfo.SelectedRows[j].Cells[2].Value.ToString();
                    dst_addr = new MacAddr(addr_str);

                    /* 首先获取设备内所有用户信息的crc */
                    while (true)
                    {
                        /* 获取用户crc */
                        if (stm32_sync.user_crc_get(dst_addr.Mac, (UInt16)(total_get + 1), (UInt16)200, out total, out count, out user_crc_byte) != true)
                        {
                            err = false;
                            break;
                        }

                        if (total_get == 0)
                        {
                            user_crc = new UInt32[total];
                        }

                        for (int i = 0; i < count; i++)
                        {
                            crc = (UInt32)((user_crc_byte[i * 4 + 0] << 0) +
                                           (user_crc_byte[i * 4 + 1] << 8) +
                                           (user_crc_byte[i * 4 + 2] << 16) +
                                           (user_crc_byte[i * 4 + 3] << 24));
                            user_crc[i + total_get] = crc;
                        }

                        total_get += count;

                        if (total_get == total)
                        {
                            output("已获取完成所有用户crc");
                            err = true;
                            break;
                        }
                    }
                    if (err == false)
                    {
                        output("crc获取错误");
                        continue;
                    }

                    /* 同步用户信息 */
                    for (UInt32 uID = 1; uID <= user_crc.Length; uID++)
                    {
                        /* 获取用户信息 */
                        person = personnelManagement.user_get(uID);

                        /* 用户不存在上位机,删除用户 */
                        if ((person.uID != uID) && (user_crc[uID - 1] != 0))
                        {
                            is_change = true;
                            if (stm32_sync.user_del(dst_addr.Mac, uID) == false)
                            {
                                output("删除" + uID.ToString() + "号用户失败");
                                err = false;
                                break;
                            }
                            continue;
                        }

                        if (person.uID != 0)
                        {
                            /* 计算用户crc */
                            crc = stm32_sync.user_crc_calc(person);

                            /* crc不同,证明用户信息改变,添加用户 */
                            if (crc != user_crc[uID - 1])
                            {
                                is_change = true;
                                if (stm32_sync.user_add(dst_addr.Mac, person) == false)
                                {
                                    output("添加" + uID.ToString() + "号用户失败");
                                    err = false;
                                    break;
                                }
                            }
                        }
                    }

                    UInt32 user_id_max_device = (UInt32)user_crc.Length;
                    UInt32 user_id_max_db     = personnelManagement.max_user_id_get();
                    if (user_id_max_device < user_id_max_db)
                    {
                        for (UInt32 uID = (UInt32)(user_id_max_device + 1); uID <= user_id_max_db; uID++)
                        {
                            /* 获取用户信息 */
                            person = personnelManagement.user_get(uID);

                            if (person.uID == uID)
                            {
                                is_change = true;
                                if (stm32_sync.user_add(dst_addr.Mac, person) == false)
                                {
                                    output("添加" + uID.ToString() + "号用户失败");
                                    err = false;
                                }
                            }
                        }
                    }

                    if (is_change == true)
                    {
                        /* 重新加载卡号-用户号,指纹号-用户号列表 */
                        stm32_sync.list_reload(dst_addr.Mac);
                    }

                    if (err == false)
                    {
                        output("同步用户信息出错");
                        continue;
                    }
                    else
                    {
                        output("同步用户信息成功");
                    }
                }
            }

            is_child_thread_stop = 0;
        }
コード例 #9
0
        /// <summary>
        /// 同步所有已连接设备的考勤记录
        /// </summary>
        private void SyncATT()
        {
            output("获取人员进出记录");
            DeviceManagement deviceManagement = new DeviceManagement();
            AttendanceInfo   attendanceInfo   = new AttendanceInfo();

            AttendanceInfo.AttInfo attInfo = new AttendanceInfo.AttInfo();
            Stm32Sync stm32_sync           = new Stm32Sync();
            Stm32_crc stm32_crc            = new Stm32_crc();
            UInt32    crc = 0;
            MacAddr   dst_addr;
            UInt32    total;
            UInt16    count;

            byte[] att_data;
            byte[] student_id = new byte[16];
            byte[] name       = new byte[16];

            stm32_sync.output_dlg = output;

            int row      = dgvDeviceInfo.SelectedRows.Count; /* 获取选中总行数 */
            int rowIndex = dgvDeviceInfo.CurrentRow.Index;   /* 获取选择行号 */

            for (int j = 0; j < row; j++)
            {
                if (dgvDeviceInfo.SelectedRows[j].Cells[1].Value.ToString() == "已连接")
                {
                    string addr_str = dgvDeviceInfo.SelectedRows[j].Cells[2].Value.ToString();
                    dst_addr = new MacAddr(addr_str);

                    while (true)
                    {
                        /* 获取考勤记录 */
                        if (stm32_sync.att_get(dst_addr.Mac, (UInt16)10, out total, out count, out att_data) != true)
                        {
                            break;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            crc = stm32_crc.block_crc_calc(att_data, (UInt32)(i * 53), 53 - 4);
                            if (crc != (UInt32)((att_data[i * 53 + 49] << 0) +
                                                (att_data[i * 53 + 50] << 8) +
                                                (att_data[i * 53 + 51] << 16) +
                                                (att_data[i * 53 + 52] << 24)))
                            {
                                output("crc failed");
                                continue;
                            }

                            Buffer.BlockCopy(att_data, i * 53 + 2, student_id, 0, student_id.Length);
                            Buffer.BlockCopy(att_data, i * 53 + 18, name, 0, name.Length);

                            attInfo.deviceID   = att_data[i * 53 + 34];                              /* 设备ID */
                            attInfo.deviceName = deviceManagement.device_name_get(attInfo.deviceID); /* 设备名称 */
                            attInfo.mac        = att_data[i * 53 + 35].ToString("x2") + ":" +
                                                 att_data[i * 53 + 36].ToString("x2") + ":" +
                                                 att_data[i * 53 + 37].ToString("x2") + ":" +
                                                 att_data[i * 53 + 38].ToString("x2") + ":" +
                                                 att_data[i * 53 + 39].ToString("x2") + ":" +
                                                 att_data[i * 53 + 40].ToString("x2");                                /* 设备mac地址 */
                            attInfo.uID       = (UInt32)(att_data[i * 53 + 0] + (att_data[i * 53 + 1] << 8));         /* 用户号 */
                            attInfo.studentID = System.Text.Encoding.Default.GetString(student_id).Replace("\0", ""); /* 学号 */
                            attInfo.name      = System.Text.Encoding.UTF8.GetString(name).Replace("\0", "");          /* 姓名 */
                            attInfo.state     = (char)att_data[i * 53 + 41];                                          /* 状态 0:出门 1:进门 */
                            attInfo.time      =
                                (att_data[i * 53 + 42] + (att_data[i * 53 + 43] << 8)).ToString("D4") + "年" +
                                att_data[i * 53 + 44].ToString("D2") + "月" +
                                att_data[i * 53 + 45].ToString("D2") + "日 " +
                                att_data[i * 53 + 46].ToString("D2") + ":" +
                                att_data[i * 53 + 47].ToString("D2") + ":" +
                                att_data[i * 53 + 48].ToString("D2"); /* 时间 */
                            attendanceInfo.AddInfo(attInfo);
                        }

                        /* 删除考勤记录 */
                        if (count != 0)
                        {
                            if (stm32_sync.att_del(dst_addr.Mac, count) != true)
                            {
                                break;
                            }
                        }

                        if (total == 0)
                        {
                            output("已获取完成所有考勤记录");
                            break;
                        }
                    }
                }
            }

            is_child_thread_stop = 0;
        }
コード例 #10
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Stm32Sync           stm32_sync          = new Stm32Sync();
            PersonnelManagement personnelManagement = new PersonnelManagement();

            PersonnelManagement.PersonInfo person = new PersonnelManagement.PersonInfo(5);
            MacAddr mac = new MacAddr();

            //stm32_sync.user_add(mac.Mac, personnelManagement.PersonList[2]);
            //byte[] name1 = {0x30, 0x5f, 0xd5, 0xc5, 0xbd, 0xf8, 0xbf,
            //                0xc6, 0x2e, 0x62, 0x69, 0x6e, 0x00, 0x33,
            //                0x20, 0x31, 0x33, 0x30, 0x37, 0x35, 0x35,
            //                0x37, 0x34, 0x30, 0x33, 0x36, 0x20, 0x30,
            //                0x20, 0x30, 0x20, 0x31, 0x20, 0x33};
            //string name_str1 = Encoding.Default.GetString(name1);
            //byte[] name = Encoding.Default.GetBytes(name_str1);

            //AttendanceInfo attendanceInfo = new AttendanceInfo();
            //AttendanceInfo.AttInfo attInfo = new AttendanceInfo.AttInfo();

            //attInfo.deviceID = 4;                     /* 设备ID */
            //attInfo.deviceName = "411";               /* 设备名称 */
            //attInfo.mac = "00:00:00:00:00:04";        /* 设备mac地址 */
            //attInfo.infoID = 0;                       /* 记录ID 可重复,只作为参考 */
            //attInfo.uID = 1;                          /* 用户号 */
            //attInfo.studentID = "11307030328";        /* 学号 */
            //attInfo.name = "张进科";                  /* 姓名 */
            //attInfo.state = (char)1;                  /* 状态 0:出门 1:进门 */
            //attInfo.time = "2017年03月18日 22:34:59"; /* 时间 */
            //attendanceInfo.AddInfo(attInfo);
            //attendanceInfo.DelInfo(attInfo);


            //PersonnelManagement personnelManagement = new PersonnelManagement();
            //PersonnelManagement.PersonInfo person = new PersonnelManagement.PersonInfo(5);

            //person.uID         = 0;
            //person.cardID      = 0xFFFFFFFF;
            //person.activeState = 0;
            //person.studentID   = "11307030328";
            //person.dormitory   = "柏轩 B414";
            //person.major       = "机械工程学院 测控技术与仪器";
            //person.name        = "张进科";
            //person.sex         = "男";
            //person.birthday    = "1995年02月23日";
            //person.tel         = "15825941073";
            //person.QQ          = "799658861";
            //person.weiXin      = "zhangjinke0220";
            //person.authority   = "authority";
            //person.isLimitTime = 0;
            //person.limitTime   = "2099年12月31日23时59分59秒";
            //person.eigenNum[0] = 0;
            //person.eigenNum[1] = 1;
            //person.eigenNum[2] = 2;
            //person.eigenNum[3] = 3;
            //person.eigenNum[4] = 4;
            //person.eigen[0]    = "eigen0";
            //person.eigen[1]    = "eigen1";
            //person.eigen[2]    = "eigen2";
            //person.eigen[3]    = "eigen3";
            //person.eigen[4]    = "eigen4";
            //person.recodeDate = "2017年2月3日17时49分26秒";
            //person.resv0       = 0;
            //person.resv1       = 0;
            //person.resv2       = "";
            //person.resv3       = "";
            //person.resv4       = "";
            //personnelManagement.AddPerson(person);
            //personnelManagement.DelPerson(person);

            //school_info_init();

            Control.CheckForIllegalCrossThreadCalls = false;        //不检查跨线程的调用是否合法(不好的解决方案)
            if (!Directory.Exists(Environment.CurrentDirectory + @"\dataBase"))
            {
                Directory.CreateDirectory(Environment.CurrentDirectory + @"\dataBase");//目录不存在,建立目录
            }
            if (!Directory.Exists(Environment.CurrentDirectory + @"\picture"))
            {
                Directory.CreateDirectory(Environment.CurrentDirectory + @"\picture");//目录不存在,建立目录
            }

            DeviceManagement deviceManagement = new DeviceManagement();

            dgvDeviceInfo.Rows.Clear();                    /* 清空表格 */
            deviceManagement = new DeviceManagement();
            int count = deviceManagement.DeviceList.Count; /* 设备数量 */

            for (int idx = 0; idx < count; idx++)          /* 将设备添加到表格中 */
            {
                int index = dgvDeviceInfo.Rows.Add();
                dgvDeviceInfo.Rows[index].Cells[0].Value = deviceManagement.DeviceList[idx].name; /* 设备名称 */
                dgvDeviceInfo.Rows[index].Cells[1].Value = "未连接";                                 /* 状态 */
                dgvDeviceInfo.Rows[index].Cells[2].Value = deviceManagement.DeviceList[idx].mac;  /* mac地址 */
                dgvDeviceInfo.Rows[index].Cells[3].Value = "";                                    /* 人员数 */
            }
        }