static public int Get_MulticastIP(MulticastIPType Type, byte[] ID, int Num, byte[] IP) { uint FID; //设备编号 uint MID; //映射ID uint Unit_Num; int Room_Num; int Floor_Num; int Villa_Num; switch (Type) { case MulticastIPType.NET_MULICASTIP: FID = (uint)Num; MID = FID; break; case MulticastIPType.UNIT_MULICASTIP: Unit_Num = (uint)(BcdDeal.BCDToInt(ID[0]) * 10 + BcdDeal.BCDToInt(ID[1])); FID = (uint)Num; MID = (uint)(NET_FID_TOTAL + ((Unit_Num - 1) * UNIT_OFFSET) + FID); break; case MulticastIPType.INDOOR_MULICASTIP: //户内组播地址 Unit_Num = (uint)(BcdDeal.BCDToInt(ID[1]) * 10 + BcdDeal.BCDToInt(ID[2])); if (Unit_Num == 0) //别墅机组播分配 { Unit_Num = 1023; //将1023梯口号分配给别墅 Villa_Num = BcdDeal.BCDToInt(ID[3]) * 100 + BcdDeal.BCDToInt(ID[4]); //别墅号 MID = (uint)(NET_FID_TOTAL + UNIT_HOME_FONCTION_OFFSET + +((Unit_Num - 1) * UNIT_OFFSET) + Villa_Num); } else { Floor_Num = BcdDeal.BCDToInt(ID[3]); if (Floor_Num < 1 || Floor_Num > 63) { //printf("Floor_Num %d out of the range 1-63\n",Floor_Num); return(0); } Room_Num = BcdDeal.BCDToInt(ID[4]); if (Room_Num < 1 || Room_Num > 32) { //printf("Room_Num %d out of the range 1-32\n",Floor_Num); return(0); } MID = (uint)(NET_FID_TOTAL + UNIT_HOME_FONCTION_OFFSET + ((Unit_Num - 1) * UNIT_OFFSET) + (Floor_Num - 1) * ROOMNUMMAX + Room_Num); } break; default: //printf("ID TO IP :无效ID号\n"); return(0); } //printf("MID = %x",(MID>>16)); //printf("%x\n",MID); IP[0] = 238; //固定为238段 IP[1] = (byte)((MID >> 16) & 0xff); IP[2] = (byte)((MID >> 8) & 0xff); IP[3] = (byte)(MID & 0xff); return(1); }
static public int Change_IDToIP(byte[] ID, byte[] IP) { DevType DevType; //类型 int Type; int Num; //编号 int Unit_Num; //梯口号 int Floor_Num; //楼层号 int Room_Num; //房号 int Villa_Num; //别墅号 IP[0] = 10; //固定为10段 DevType = (DevType)ID[0]; if (DevType == DevType.DEV_INDOORPHONE) //室内机 { Unit_Num = BcdDeal.BCDToInt(ID[1]) * 10 + BcdDeal.BCDToInt(ID[2]); if (Unit_Num > 999) { //printf("Unit_Num %d out of the range 0-999\n",Unit_Num); return(0); } if (Unit_Num == 0) //别墅型 { Unit_Num = 1023; //映射到1023 Villa_Num = BcdDeal.BCDToInt(ID[3]) * 100 + BcdDeal.BCDToInt(ID[4]); Num = BcdDeal.BCDToInt(ID[5]); IP[1] = (byte)((Unit_Num >> 2) & 0xff); IP[2] = (byte)(((Unit_Num & 0x03) << 6) | ((Villa_Num >> 5) & 0xff)); IP[3] = (byte)((Villa_Num & 0x1f) | ((Num - 1) << 5)); } else { Floor_Num = BcdDeal.BCDToInt(ID[3]); if (Floor_Num < 1 || Floor_Num > 63) { //printf("Floor_Num %d out of the range 1-63\n",Floor_Num); return(0); } Room_Num = BcdDeal.BCDToInt(ID[4]); if (Room_Num < 1 || Room_Num > 32) { //printf("Room_Num %d out of the range 1-32\n",Floor_Num); return(0); } Num = BcdDeal.BCDToInt(ID[5]); if (Num < 1 || Num > 6) { //printf("Number %d out of the range 1-6\n",Num); return(0); } IP[1] = (byte)((Unit_Num >> 2) & 0xff); IP[2] = (byte)(((Unit_Num & 0x03) << 6) | Floor_Num); // IP[3] = ((Room_Num-1) << 3) | (Num-1); IP[3] = (byte)(((Num - 1) << 5) | (Room_Num - 1)); } } else if (DevType == DevType.DEV_SECONDOORSTATION) //二次门口机 { Unit_Num = BcdDeal.BCDToInt(ID[1]) * 10 + BcdDeal.BCDToInt(ID[2]); if (Unit_Num > 999) { //printf("Unit_Num %d out of the range 0-999\n",Unit_Num); return(0); } if (Unit_Num == 0) //别墅型二次门口机 { Unit_Num = 1023; //映射到1023 Villa_Num = BcdDeal.BCDToInt(ID[3]) * 100 + BcdDeal.BCDToInt(ID[4]); Num = BcdDeal.BCDToInt(ID[5]) + 6; IP[1] = (byte)((Unit_Num >> 2) & 0xff); IP[2] = (byte)(((Unit_Num & 0x03) << 6) | ((Villa_Num >> 5) & 0xff)); IP[3] = (byte)((Villa_Num & 0x1f) | ((Num - 1) << 5)); } else { Floor_Num = BcdDeal.BCDToInt(ID[3]); if (Floor_Num < 1 || Floor_Num > 63) { //printf("Floor_Num %d out of the range 1-63\n",Floor_Num); return(0); } Room_Num = BcdDeal.BCDToInt(ID[4]); if (Room_Num < 1 || Room_Num > 32) { //printf("Room_Num %d out of the range 1-32\n",Floor_Num); return(0); } Num = BcdDeal.BCDToInt(ID[5]) + 6; //室内设备号 1-8 ,最后两个IP预留给二次门口机 if (Num < 7 || Num > 8) { //printf("Number0 %d out of the range 1-2\n",Num); return(0); } IP[1] = (byte)((Unit_Num >> 2) & 0xff); IP[2] = (byte)(((Unit_Num & 0x03) << 6) | Floor_Num); //IP[3] = ((Room_Num-1) << 3) | (Num-1); IP[3] = (byte)(((Num - 1) << 5) | (Room_Num - 1)); } } else if ((DevType == DevType.DEV_DOORSTATION) || (DevType == DevType.DEV_ELEVOTAR) || (DevType == DevType.DEV_CARDUNIT)) //门口机、电梯联动模块、单元刷卡头 { Unit_Num = BcdDeal.BCDToInt(ID[1]) * 10 + BcdDeal.BCDToInt(ID[2]); if (Unit_Num > 999) { //printf("Unit_Num %d out of the range 0-999\n",Unit_Num); return(0); } Num = BcdDeal.BCDToInt(ID[3]) * 100 + BcdDeal.BCDToInt(ID[4]); if (Num < 1 || Num > 32) { //printf("Number %d out of the range 0-32\n",Num); return(0); } switch (DevType) { case DevType.DEV_DOORSTATION: //门口机 Type = 0; break; case DevType.DEV_ELEVOTAR: //电梯联动模块 Type = 1; Num--; break; case DevType.DEV_CARDUNIT: //单元刷卡头 Type = 2; Num--; break; default: return(0); } IP[1] = (byte)((Unit_Num >> 2) & 0xff); IP[2] = (byte)(((Unit_Num & 0x03) << 6)); //IP[3] = (Type << 5) | (Num-1); IP[3] = (byte)(((Num - 1) << 3) | Type); } else //围墙机、管理机、IPC、刷卡头 { Num = BcdDeal.BCDToInt(ID[1]) * 100 + BcdDeal.BCDToInt(ID[2]); if (Num < 1 || Num > 32) { //printf("Number %d out of the range 1-32\n",Num); return(0); } switch (DevType) { case DevType.DEV_PC: //PC管理机 Type = 0; break; case DevType.DEV_GUARDUNIT: case DevType.DEV_GUARD: //硬件管理机 Type = 1; break; case DevType.DEV_PERIMETERGATE: //围墙机 Type = 2; break; case DevType.DEV_IPCAMERA: //IP摄像头 Type = 3; break; case DevType.DEV_CARD: //刷卡头 Type = 4; break; default: return(0); } IP[1] = 0; IP[2] = (byte)Type; IP[3] = (byte)Num; } return(1); }