6 Commits f71c1779d0 ... 40b37513d1

Autor SHA1 Mensaje Fecha
  dujunchen 40b37513d1 PAD 录音传递分机参数,设置到来电显示中 hace 1 mes
  dujunchen 037f7980f4 去掉录音设置接口 hace 1 mes
  dujunchen f2cf31a112 无占用信号是不能发起相关操作 hace 1 mes
  dujunchen fd34fe9540 add active Master and Slave hace 1 mes
  dujunchen 10be6ae46d send PA start after connected hace 1 mes
  dujunchen 09abd130a4 fix hace 1 mes

+ 34 - 30
internal/app/ami/action/index.go

@@ -25,6 +25,7 @@ func HandleAMI(event map[string]string) {
 	switch event["Event"] {
 
 	case "DTMFBegin": //ICP interrupt PAD
+
 		if utils.IsICP(event["CallerIDNum"]) {
 			exten := strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0] //get ICP exten number
 			if utils.IsICP(exten) {
@@ -52,17 +53,11 @@ func HandleAMI(event map[string]string) {
 
 	case "UserEvent": // RCD filename; PA;CPA; CabCab
 		lfshook.NewLogger().Infof("========event:%s   File:%s", event["Event"], event["FILENAME"])
+
 		if event["UserEvent"] == "SetRecordFile" { //get  record file name
 			alstatus.SendRecordFile(event["FILENAME"], event["RecordType"])
 
 		} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
-			//check active signal  before PA; hangup if not actived
-			/*	if active.ActivedCab == "1" && event["CallerIDNum"] == "2311" {
-					Hangup(event["CallerIDNum"])
-				} else if active.ActivedCab == "8" && event["CallerIDNum"] == "2381" {
-					Hangup(event["CallerIDNum"])
-				}*/
-
 			//PA & CPA interrupt others
 			if utils.IsICP(event["CallerIDNum"]) {
 
@@ -79,13 +74,6 @@ func HandleAMI(event map[string]string) {
 
 			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
 				if priority.CheckPriority("CPA") {
-
-					//check active signal  before CPA; hangup if not actived
-					/*	if active.ActivedCab == "8" && event["CallerIDNum"] == "1411" {
-							Hangup(event["CallerIDNum"])
-						} else if active.ActivedCab == "1" && event["CallerIDNum"] == "1481" {
-							Hangup(event["CallerIDNum"])
-						}*/
 					if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
 						Hangup(event["CallerIDNum"])
 					}
@@ -158,8 +146,10 @@ func HandleAMI(event map[string]string) {
 					}
 
 					if PADChan != "" {
-						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-						go RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
+						Ext := strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0]
+
+						alstatus.AlarmStatus(Ext, "connect")
+						go RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", Ext) //PAD Page(OCC+ICPs)
 
 						go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
 					} else {
@@ -178,8 +168,10 @@ func HandleAMI(event map[string]string) {
 					}
 
 					if PADChan != "" {
-						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-						go RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
+						Ext := strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0]
+
+						alstatus.AlarmStatus(Ext, "connect")
+						go RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", Ext) //PAD Page(OCC+ICPs)
 
 						go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
 					} else {
@@ -273,32 +265,32 @@ func HandleAMI(event map[string]string) {
 				priority.OCCAnswer = 1
 
 				if active.ActivedCab == "1" /* && ExtenStatus("1411") == "Idle" */ { //check active and OCC status
-					if priority.PADOccStart == 0 {
+					/*if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
 						if priority.PADStart == 0 {
 							alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 							priority.PADStart = 1
 						}
-					}
+					}*/
 
 					alstatus.AlarmStatus(event["CallerIDNum"], "connect")
-					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
-					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1")    // PACUs dial OCC1
+					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
+					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1")                     // PACUs dial OCC1
 
 				} else if active.ActivedCab == "8" /*&& ExtenStatus("1481") == "Idle" */ {
-					if priority.PADOccStart == 0 {
+					/*if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
 						if priority.PADStart == 0 {
 							alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 							priority.PADStart = 1
 						}
-					}
+					}*/
 
 					alstatus.AlarmStatus(event["CallerIDNum"], "connect")
-					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
-					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8")    // PACUs dial OCC8
+					go RedirectInQueue(event["Channel"], "1481", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
+					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8")                     // PACUs dial OCC8
 				}
 			} else {
 				lfshook.NewLogger().Infof("====PAD-OCC Priority false===")
@@ -395,8 +387,9 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADICP)
 			go RedirectInQueue(event["ConnectedLineName"], "2311", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP1
 
-			go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "8") // PAD call ICP8
-
+			if ExtenStatus("2381") == "Idle" {
+				go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "8") // PAD call ICP8
+			}
 		}
 		if event["ConnectedLineNum"] == "ani8" && event["Exten"] == "0511" { //PAD ansered by ICP8; PACUs connected ICP8
 			lfshook.NewLogger().Infof("====PAD answered by ICP8:%s=====", event["ConnectedLineName"])
@@ -407,8 +400,9 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADICP)
 			go RedirectInQueue(event["ConnectedLineName"], "2381", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP8
 
-			go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "1") // PAD call ICP2
-
+			if ExtenStatus("2311") == "Idle" {
+				go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "1") // PAD call ICP1
+			}
 			break
 		}
 
@@ -512,6 +506,16 @@ func HandleAMI(event map[string]string) {
 
 	case "BridgeEnter": // TMS-ICP answer PAD; PACU connect ICP
 		lfshook.NewLogger().Infof("=========event:%s   callerid:%s", event["Event"], event["CallerIDNum"])
+		if utils.IsIO(event["CallerIDNum"]) && utils.IsPAIU(event["ConnectedLineNum"]) {
+			if priority.PADOccStart == 0 {
+				alstatus.OccPad("start")
+				priority.PADOccStart = 1
+				if priority.PADStart == 0 {
+					alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
+					priority.PADStart = 1
+				}
+			}
+		}
 
 		if utils.IsPACU(event["CallerIDNum"]) && utils.IsPAIU(event["CallerIDName"]) { //ICP and PACU connected
 			lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s   Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])

+ 15 - 19
internal/app/index.go

@@ -1,7 +1,6 @@
 package app
 
 import (
-	"os/exec"
 	"pbx-api-gin/internal/app/ami/action"
 	"pbx-api-gin/internal/app/stc"
 	"pbx-api-gin/internal/app/stc/active"
@@ -17,15 +16,12 @@ func StartApp() {
 	//mysql.CreateDBInstance()
 
 	//Get cab number acording to IP
-	_, err := SetMasterCabNum()
-	if err != nil {
-		lfshook.NewLogger().Infof("Set Role and Cab Num err :%+v", err)
-	}
+	SetMasterCabNum()
 
-	lfshook.NewLogger().Infof("=================cab number:%s========Master:%+v===", active.CabNum, active.Master)
+	//lfshook.NewLogger().Infof("=================cab number:%s========Master:%+v===", active.CabNum, active.Master)
 
 	//init the active status
-	active.ActivedCab = ""
+	//active.ActivedCab = ""
 
 	//get priority
 	priority.GetPriority()
@@ -37,10 +33,10 @@ func StartApp() {
 	go stc.StartStcConnection(socket.Conn8, "8")
 
 	//启动连接到Master服务器,检查Master是否在线
-	if active.CabNum == "8" {
-		socket.ConnectedMaster = false
-		go stc.StartConnectionToSipServer(socket.ConnToMaster)
-	}
+	//if active.CabNum == "8" {
+	//	socket.ConnectedMaster = false
+	//	go stc.StartConnectionToSipServer(socket.ConnToMaster)
+	//}
 	// 启动其他服务...
 	// 启动 AMI
 	go func() {
@@ -55,18 +51,18 @@ func StartApp() {
 }
 
 // Get eth0 IP
-func SetMasterCabNum() (string, error) {
-	cmd := "ip a |grep 10.0.11.11" //check Master IP
-
-	out, _ := exec.Command("bash", "-c", cmd).CombinedOutput()
+func SetMasterCabNum() {
 
+	ext, err := socket.IsIPExists("10.0.11.11")
+	if err != nil {
+		lfshook.NewLogger().Infof("Check IP :%+v", err)
+	}
 	// Init cab number and master role
-	if len(out) == 0 {
-		active.Master = false
+	if !ext {
 		active.CabNum = "8"
+		active.Master = false
 	} else {
-		active.Master = true
 		active.CabNum = "1"
+		active.Master = true
 	}
-	return string(out), nil
 }

+ 1 - 1
internal/app/stc/active/index.go

@@ -6,7 +6,7 @@ import "time"
 var CabNum string
 var ActivedCab = "1"
 
-var Master bool
+var Master = false
 
 var QueueTimer *time.Timer = nil
 

+ 131 - 123
internal/app/stc/broadcast/stc-broadcast.go

@@ -7,22 +7,15 @@ import (
 	"io"
 	"net"
 	"net/http"
-	"os"
 	"pbx-api-gin/internal/app/ami/action"
-	"pbx-api-gin/internal/app/ami/model"
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	"pbx-api-gin/internal/app/stc/priority"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
-	"sort"
 	"strconv"
-	"strings"
 	"sync"
 	"time"
-
-	"github.com/sirupsen/logrus"
-	"gopkg.in/ini.v1"
 )
 
 func HandleStcCmd(ctx context.Context, conn net.Conn) {
@@ -61,12 +54,6 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
 // 处理单个数据包(原 switch 逻辑迁移过来)
 func processPacket(packet []byte) {
 
-	//check if Master role
-	if !active.Master {
-		lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
-		return
-	}
-
 	if len(packet) < 6 {
 		fmt.Println("Invalid packet length")
 		return
@@ -79,138 +66,152 @@ func processPacket(packet []byte) {
 
 	//check if the cmd type is avtive
 	if packet[5] == 0x03 { // ACTIVE
-		Active([1]byte{packet[8]})
+		Active([2]byte{packet[8], packet[9]})
+		return
+	}
+
+	//check if Master role
+	if !active.Master {
+		lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
 		return
 	}
 
 	switch packet[5] {
 	case 0x01: //heartbeat
-
-		//PAD-OCC异常情况处理
-		if priority.OCCAnswer == 1 {
-			//定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
-			resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
-			if err != nil {
-				lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
-				return
-			}
-			if resCaller.Calls != "0" {
-				sort.Slice(resCaller.Entrys, func(i, j int) bool {
-					return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
-				})
-
-				for _, caller := range resCaller.Entrys {
-					priority.ICPAnswer = 0
-					lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
-					//order by pos
-					action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
-					time.Sleep(time.Microsecond * 200)                                                   //200 ms delay
+		/*
+			//PAD-OCC异常情况处理
+			if priority.OCCAnswer == 1 {
+				//定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
+				resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
+				if err != nil {
+					lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+					return
+				}
+				if resCaller.Calls != "0" {
+					sort.Slice(resCaller.Entrys, func(i, j int) bool {
+						return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
+					})
+
+					for _, caller := range resCaller.Entrys {
+						priority.ICPAnswer = 0
+						lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
+						//order by pos
+						action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
+						time.Sleep(time.Microsecond * 200)                                                   //200 ms delay
+					}
 				}
-			}
 
-			//定时监测OCC  queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
-			res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
-			if err != nil {
-				lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
-				return
-			}
-			if res.Calls != "0" { //OCC queue is not empty
-				//	HangupAllLocalChan()
-				lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
-				if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
-					time.Sleep(time.Second)
-					PADChan := ""
-					for _, chanEntry := range res.Entrys {
-						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
-						if chanEntry.Position == "1" {
-							PADChan = chanEntry.Channel
-							break
+				//定时监测OCC  queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
+				res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
+				if err != nil {
+					lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
+					return
+				}
+				if res.Calls != "0" { //OCC queue is not empty
+					//	HangupAllLocalChan()
+					lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
+					if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
+						time.Sleep(time.Second)
+						PADChan := ""
+						for _, chanEntry := range res.Entrys {
+							lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
+							if chanEntry.Position == "1" {
+								PADChan = chanEntry.Channel
+								break
+							}
 						}
-					}
 
-					if PADChan != "" {
-						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-						go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
+						if PADChan != "" {
+							alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
+							go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
 
-						go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
-					} else {
-						lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
-					}
-					break
-				} else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
-					time.Sleep(time.Second)
-					PADChan := ""
-					for _, chanEntry := range res.Entrys {
-						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
-						if chanEntry.Position == "1" {
-							PADChan = chanEntry.Channel
-							break
+							go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
+						} else {
+							lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+						}
+						break
+					} else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
+						time.Sleep(time.Second)
+						PADChan := ""
+						for _, chanEntry := range res.Entrys {
+							lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
+							if chanEntry.Position == "1" {
+								PADChan = chanEntry.Channel
+								break
+							}
 						}
-					}
 
-					if PADChan != "" {
-						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-						go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
+						if PADChan != "" {
+							alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
+							go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
 
-						go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
-					} else {
-						lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+							go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
+						} else {
+							lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+						}
+						break
 					}
-					break
 				}
 			}
-		}
-
+		*/
+		break
 	case 0x02: // STN
-		if priority.CheckPriority("STN") {
-			action.HangupRunningTask("STN") //STN interrupt other
-			StationAnn(packet)
-		} else {
-			alstatus.PaStatus("", "STN", "refuse")
+		if active.ActivedCab != "" {
+			if priority.CheckPriority("STN") {
+				action.HangupRunningTask("STN") //STN interrupt other
+				StationAnn(packet)
+			} else {
+				alstatus.PaStatus("", "STN", "refuse")
+			}
 		}
-
 	case 0x05: // SPC
-		if priority.CheckPriority("SPC") {
-			action.HangupRunningTask("SPC") //SPC interrupt other
-			SpecialAnn(packet)
-		} else {
-			alstatus.PaStatus("", "SPC", "refuse")
+		if active.ActivedCab != "" {
+			if priority.CheckPriority("SPC") {
+				action.HangupRunningTask("SPC") //SPC interrupt other
+				SpecialAnn(packet)
+			} else {
+				alstatus.PaStatus("", "SPC", "refuse")
+			}
 		}
-
 	case 0x06: // EMG
-		if priority.CheckPriority("EMG") {
-			action.HangupRunningTask("EMG") //EMG interrupt other
-			EmgMsg(packet)
-		} else {
-			alstatus.PaStatus("", "EMG", "refuse")
+		if active.ActivedCab != "" {
+			if priority.CheckPriority("EMG") {
+				action.HangupRunningTask("EMG") //EMG interrupt other
+				EmgMsg(packet)
+			} else {
+				alstatus.PaStatus("", "EMG", "refuse")
+			}
 		}
 	case 0x07: // STOP
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
 
 	case 0x08: // DCS
-		if priority.CheckPriority("DCS") {
-			action.HangupRunningTask("DCS") //DCS interrupt other
-			DcsAnn(packet)
-		} else {
-			alstatus.PaStatus("", "DCS", "refuse")
+		if active.ActivedCab != "" {
+			if priority.CheckPriority("DCS") {
+				action.HangupRunningTask("DCS") //DCS interrupt other
+				DcsAnn(packet)
+			} else {
+				alstatus.PaStatus("", "DCS", "refuse")
+			}
 		}
-
 	case 0x09: // SELF CHECK
-		if priority.CheckPriority("CHK") {
-			action.HangupRunningTask("CHK") //CHK interrupt other
-			SelfCheck(packet)
-		} else {
-			alstatus.PaStatus("", "CHK", "refuse")
+		if active.ActivedCab != "" {
+			if priority.CheckPriority("CHK") {
+				action.HangupRunningTask("CHK") //CHK interrupt other
+				SelfCheck(packet)
+			} else {
+				alstatus.PaStatus("", "CHK", "refuse")
+			}
 		}
-
 	case 0x0a: // Tone-test
-		if priority.CheckPriority("VOL") {
-			action.HangupRunningTask("VOL") //VOL interrupt other
-			ToneTest(packet)
-		} else {
-			alstatus.PaStatus("", "VOL", "refuse")
+		if active.ActivedCab != "" {
+			if priority.CheckPriority("VOL") {
+				action.HangupRunningTask("VOL") //VOL interrupt other
+				ToneTest(packet)
+			} else {
+				alstatus.PaStatus("", "VOL", "refuse")
+			}
 		}
-
 	case 0x0e: //TMS answer PAD
 		if priority.CheckPriority("PAD-TMS") {
 			action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
@@ -224,8 +225,8 @@ func processPacket(packet []byte) {
 	case 0x0b: // reset all PAD
 		AlarmHoldResetAll(packet[8]) // reset all pad
 
-	case 0x0c: // recored config
-		RecordStorageConf(packet[8:]) // RCD setting
+	//case 0x0c: // recored config
+	//	RecordStorageConf(packet[8:]) // RCD setting
 
 	case 0x0d: // ICP answer PAD
 		if priority.CheckPriority("PAD-ICP") {
@@ -260,13 +261,24 @@ func StationAnn(data []byte) (err error) {
 }
 
 // 激活信号
-func Active(data [1]byte) {
+func Active(data [2]byte) {
 
 	//var info model.Sysinfo
 	//active.Actived = true
 	Signal := int(data[0])
+	Master := int(data[1])
 	//lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
 
+	if !active.Master && active.CabNum == "8" { //slave role , check the Master data from STC
+		if Master == 8 {
+			active.Master = true
+		}
+	} else if !active.Master && active.CabNum == "1" {
+		if Master == 1 {
+			active.Master = true
+		}
+	}
+
 	switch Signal {
 	case 0:
 
@@ -277,17 +289,11 @@ func Active(data [1]byte) {
 	case 1:
 		active.ActivedCab = "1"
 		//lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
-		if active.CabNum == "8" { // local cab is MC1
-			action.InActiveHangup()
-		}
 
 	case 8:
 
 		active.ActivedCab = "8"
 		//lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
-		if active.CabNum == "1" { //Local cab is MC8
-			action.InActiveHangup()
-		}
 	}
 }
 
@@ -600,6 +606,7 @@ func AlarmHoldResetAll(handler byte) {
 	}
 }
 
+/*
 func RecordStorageConf(data []byte) {
 
 	var info model.RcdConf
@@ -639,3 +646,4 @@ func RecordStorageConf(data []byte) {
 	iniFile.SaveTo(filePath)
 
 }
+*/

+ 6 - 5
internal/app/stc/index.go

@@ -150,6 +150,7 @@ func CreateConnection(RemoteCab string) (net.Conn, error) {
 	}
 }
 
+/*
 func StartConnectionToSipServer(conn net.Conn) {
 
 	var connMux sync.Mutex // 保护 conn 的读写
@@ -200,13 +201,13 @@ func StartConnectionToSipServer(conn net.Conn) {
 		time.Sleep(time.Second) // 重连前等待
 
 		//check connected Master tag; connection err change to Master role ,exit
-		if socket.ConnectedMaster {
-			active.Master = true
-			return
-		}
+		//if socket.ConnectedMaster {
+		//	active.Master = true
+		//	return
+		//}
 	}
 }
-
+*/
 // 连接Master sipserver
 func CreateConnectionSipServer() (net.Conn, error) {
 	dialer := &net.Dialer{

+ 31 - 1
internal/app/stc/socket/index.go

@@ -1,6 +1,9 @@
 package socket
 
-import "net"
+import (
+	"fmt"
+	"net"
+)
 
 var Conn net.Conn
 var Conn8 net.Conn
@@ -18,3 +21,30 @@ const RemoteAddr = "10.0.11.11"
 const RemoteAddr8 = "10.0.11.81"
 
 var ConnectedMaster bool
+
+func IsIPExists(targetIP string) (bool, error) {
+	// 解析目标 IP
+	ip := net.ParseIP(targetIP)
+	if ip == nil {
+		return false, fmt.Errorf("invalid IP address: %s", targetIP)
+	}
+
+	// 获取所有网络接口的地址
+	addrs, err := net.InterfaceAddrs()
+	if err != nil {
+		return false, err
+	}
+
+	// 遍历每个接口地址
+	for _, addr := range addrs {
+		// 只处理 IP 网络类型地址 (*net.IPNet)
+		if ipnet, ok := addr.(*net.IPNet); ok {
+			// 检查该网段是否包含目标 IP
+			if ipnet.Contains(ip) {
+				return true, nil
+			}
+		}
+	}
+
+	return false, nil
+}