root 3 settimane fa
parent
commit
992f985acb

+ 1 - 0
internal/app/ami/action/call.go

@@ -130,6 +130,7 @@ func HangupTask(TaskName string) {
 
 // interrupt the running task
 func InterruptRunningTask(toRunTask string) string {
+	utils.LoggerDebug.Printf("InterruptRunningTask  TorunType:%s", toRunTask)
 
 	var task priority.TaskInfo
 	var taskName string

+ 79 - 1
internal/app/ami/action/index.go

@@ -68,6 +68,11 @@ func HandleAMI(event map[string]string) {
 					Hangup(event["CallerIDNum"])
 				}
 
+				active.WaitTaskCreate("PA")
+				if active.TaskCreating == "" {
+					active.TaskCreating = "PA"
+				}
+
 				if priority.CheckPriority("ManuPa") {
 
 					//hangup others if priority is higher
@@ -82,6 +87,11 @@ func HandleAMI(event map[string]string) {
 				}
 
 			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
+				active.WaitTaskCreate("CPA")
+				if active.TaskCreating == "" {
+					active.TaskCreating = "CPA"
+				}
+
 				if priority.CheckPriority("CPA") {
 
 					lfshook.NewLogger().Infof("========event:%s  ========devide:%d", event["Event"], active.TrainDevide)
@@ -96,6 +106,7 @@ func HandleAMI(event map[string]string) {
 							Hangup(event["CallerIDNum"])
 						}
 					}
+
 					//hangup others if priority is higher
 					runningTaskName := InterruptRunningTask("CPA") //CPA interrupt other
 					if runningTaskName != "" {
@@ -107,6 +118,11 @@ func HandleAMI(event map[string]string) {
 			}
 		} else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab start; check cab cab priority
 
+			active.WaitTaskCreate("C2C")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "C2C"
+			}
+
 			if priority.CheckPriority("CabCab") { // interrupt OCC-PAD
 				//C2C start PAD interrupt
 
@@ -115,6 +131,7 @@ func HandleAMI(event map[string]string) {
 				lfshook.NewLogger().Infof("HighestPriorityRunningTask get task :%+v", taskName)
 				if ok {
 					if taskName == "PAD-ICP" || taskName == "PAD-TMS" || taskName == "PA" {
+
 						runningTaskName := InterruptRunningTask("C2C")
 						if runningTaskName != "" {
 							time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -556,6 +573,11 @@ func HandleAMI(event map[string]string) {
 		//PAD Page OCC+ICPs;
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Queue"] == "0301" && priority.OCCAnswer == 0 { // The first PAD to OCC ,caller is PAD
 
+			active.WaitTaskCreate("PAD-OCC")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "PAD-OCC"
+			}
+
 			if priority.CheckPriority("PAD-OCC") {
 
 				runningTaskName := InterruptRunningTask("PAD-OCC") //PAD-OCC interrupt other
@@ -597,6 +619,11 @@ func HandleAMI(event map[string]string) {
 			} else {
 				lfshook.NewLogger().Infof("====PAD-OCC Priority false===")
 			}
+
+			time.Sleep(1 * time.Second)
+			if active.TaskCreating == "PAD-OCC" {
+				active.TaskCreating = ""
+			}
 		}
 
 	case "ConfbridgeJoin":
@@ -615,6 +642,9 @@ func HandleAMI(event map[string]string) {
 					ConfbridgeID: event["Conference"],
 					Running:      true,
 				}
+				if active.TaskCreating == "EMG" {
+					active.TaskCreating = ""
+				}
 				priority.RegistryTask.Register("EMG", task)
 
 				alstatus.PaStatus("", "EMG", "start")
@@ -642,6 +672,10 @@ func HandleAMI(event map[string]string) {
 					ConfbridgeID: event["Conference"],
 					Running:      true,
 				}
+				if active.TaskCreating == "SPC" {
+					active.TaskCreating = ""
+				}
+
 				priority.RegistryTask.Register("SPC", task)
 				alstatus.PaStatus("", "SPC", "start")
 
@@ -669,6 +703,10 @@ func HandleAMI(event map[string]string) {
 					ConfbridgeID: event["Conference"],
 					Running:      true,
 				}
+				if active.TaskCreating == "DCS" {
+					active.TaskCreating = ""
+				}
+
 				priority.RegistryTask.Register("DCS", task)
 				alstatus.PaStatus("", "DCS", "start")
 				//check PAD timer
@@ -696,6 +734,10 @@ func HandleAMI(event map[string]string) {
 					ConfbridgeID: event["Conference"],
 					Running:      true,
 				}
+				if active.TaskCreating == "STN" {
+					active.TaskCreating = ""
+				}
+
 				priority.RegistryTask.Register("STN", task)
 				alstatus.PaStatus("", "STN", "start")
 
@@ -724,6 +766,10 @@ func HandleAMI(event map[string]string) {
 					ConfbridgeID: event["Conference"],
 					Running:      true,
 				}
+				if active.TaskCreating == "CHK" {
+					active.TaskCreating = ""
+				}
+
 				priority.RegistryTask.Register("CHK", task)
 				alstatus.PaStatus("", "CHK", "start")
 
@@ -750,6 +796,10 @@ func HandleAMI(event map[string]string) {
 					ConfbridgeID: event["Conference"],
 					Running:      true,
 				}
+				if active.TaskCreating == "VOL" {
+					active.TaskCreating = ""
+				}
+
 				priority.RegistryTask.Register("VOL", task)
 				alstatus.PaStatus("", "VOL", "start")
 
@@ -776,6 +826,10 @@ func HandleAMI(event map[string]string) {
 		*/
 		//Send PA start msg to STC
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
+			if active.TaskCreating == "PA" {
+				active.TaskCreating = ""
+			}
+
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
 			//================================
 			task := priority.TaskInfo{
@@ -801,6 +855,11 @@ func HandleAMI(event map[string]string) {
 
 			break
 		} else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
+
+			if active.TaskCreating == "CPA" {
+				active.TaskCreating = ""
+			}
+
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
 			//================================
 			task := priority.TaskInfo{
@@ -844,6 +903,10 @@ func HandleAMI(event map[string]string) {
 				Running:      true,
 			}
 			priority.RegistryTask.Register("PAD-ICP", task)
+			if active.TaskCreating == "PAD-ICP" {
+				active.TaskCreating = ""
+			}
+
 			lfshook.NewLogger().Infof("=========PAD-ICP answer==ListAll===%+v", priority.RegistryTask.ListAll())
 			go RedirectInQueue(event["ConnectedLineName"], "2311", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP1
 
@@ -865,6 +928,10 @@ func HandleAMI(event map[string]string) {
 				Running:      true,
 			}
 			priority.RegistryTask.Register("PAD-ICP", task)
+			if active.TaskCreating == "PAD-ICP" {
+				active.TaskCreating = ""
+			}
+
 			lfshook.NewLogger().Infof("=========PAD-ICP answer==ListAll===%+v", priority.RegistryTask.ListAll())
 			go RedirectInQueue(event["ConnectedLineName"], "2381", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP8
 
@@ -1083,6 +1150,7 @@ func HandleAMI(event map[string]string) {
 				ConfbridgeID: "",
 				Running:      true,
 			}
+			active.TaskCreating = ""
 			priority.RegistryTask.Register("C2C", task)
 
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
@@ -1126,7 +1194,9 @@ func HandleAMI(event map[string]string) {
 				Running:      true,
 			}
 			priority.RegistryTask.Register("PAD-TMS", task)
-
+			if active.TaskCreating == "PAD-TMS" {
+				active.TaskCreating = ""
+			}
 			lfshook.NewLogger().Infof("=========PAD-TMS answer==ListAll===%+v", priority.RegistryTask.ListAll())
 
 			if active.ActivedCab == "1" {
@@ -1187,6 +1257,11 @@ func HandleAMI(event map[string]string) {
 		//PAD-OCC start
 		if utils.IsIO(event["CallerIDNum"]) && utils.IsPAIU(event["ConnectedLineNum"]) {
 			if priority.PADOccStart == 0 {
+
+				if active.TaskCreating == "PAD-OCC" {
+					active.TaskCreating = ""
+				}
+
 				alstatus.OccPad("start")
 				priority.PADOccStart = 1
 			}
@@ -1236,6 +1311,9 @@ func HandleAMI(event map[string]string) {
 				Running:      true,
 			}
 			priority.RegistryTask.Register("PAD-TMS", task)
+			if active.TaskCreating == "PAD-TMS" {
+				active.TaskCreating = ""
+			}
 			lfshook.NewLogger().Infof("=========PAD-TMS answer==ListAll===%+v", priority.RegistryTask.ListAll())
 
 			alstatus.AlarmStatus(event["CallerIDNum"], "connect") // PAD connect ICP-TMS

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

@@ -19,7 +19,7 @@ var MasterTag = 0
 var TrainDevide = 0
 var RadioFault = 0
 
-//var TaskCreating = ""
+var TaskCreating = ""
 
 var TrainInfoMap = make(map[string]map[int]string)
 
@@ -155,3 +155,18 @@ func InitTrainInfoMap() {
 		}
 	}
 }
+
+func WaitTaskCreate(task string) {
+	utils.LoggerDebug.Printf("Check task creating ..... ")
+
+	for i := 0; i < 4; i++ {
+		if TaskCreating != "" {
+			utils.LoggerDebug.Printf("%s waiting previous task:%s creating ..... ", task, TaskCreating)
+			time.Sleep(time.Millisecond * 500)
+		} else {
+			TaskCreating = task
+			return
+		}
+	}
+	utils.LoggerDebug.Printf("%s waiting previous task:%s creating timeout ! ", task, TaskCreating)
+}

+ 138 - 18
internal/app/stc/broadcast/stc-broadcast.go

@@ -181,9 +181,14 @@ func processPacket(packet []byte) {
 
 	case 0x02: // STN
 		if active.ActivedCab != "" {
+			//检查是否有任务正在创建
+			active.WaitTaskCreate("STN")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "STN"
+			}
+
 			if priority.CheckPriority("STN") {
 
-				//检查是否有任务真正创建
 				runningTaskName := action.InterruptRunningTask("STN") //STN interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -193,9 +198,22 @@ func processPacket(packet []byte) {
 				alstatus.PaStatus("", "STN", "refuse")
 			}
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "STN" {
+			active.TaskCreating = ""
+		}
+
 	case 0x05: // SPC
 		if active.ActivedCab != "" {
+			//检查是否有任务正在创建
+			active.WaitTaskCreate("SPC")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "SPC"
+			}
+
 			if priority.CheckPriority("SPC") {
+
 				runningTaskName := action.InterruptRunningTask("SPC") //SPC interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -205,10 +223,23 @@ func processPacket(packet []byte) {
 				alstatus.PaStatus("", "SPC", "refuse")
 			}
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "SPC" {
+			active.TaskCreating = ""
+		}
+
 	case 0x06: // EMG
 
 		if active.ActivedCab != "" {
+			//检查是否有任务正在创建
+			active.WaitTaskCreate("EMG")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "EMG"
+			}
+
 			if priority.CheckPriority("EMG") {
+
 				runningTaskName := action.InterruptRunningTask("EMG") //EMG interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -218,13 +249,26 @@ func processPacket(packet []byte) {
 				alstatus.PaStatus("", "EMG", "refuse")
 			}
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "EMG" {
+			active.TaskCreating = ""
+		}
+
 	case 0x07: // STOP
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
 
 	case 0x08: // DCS
 
 		if active.ActivedCab != "" {
+			//检查是否有任务正在创建
+			active.WaitTaskCreate("DCS")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "DCS"
+			}
+
 			if priority.CheckPriority("DCS") {
+
 				runningTaskName := action.InterruptRunningTask("DCS") //DCS interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -234,10 +278,23 @@ func processPacket(packet []byte) {
 				alstatus.PaStatus("", "DCS", "refuse")
 			}
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "DCS" {
+			active.TaskCreating = ""
+		}
+
 	case 0x09: // SELF CHECK
 
 		if active.ActivedCab != "" {
+			//检查是否有任务正在创建
+			active.WaitTaskCreate("CHK")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "CHK"
+			}
+
 			if priority.CheckPriority("CHK") {
+
 				runningTaskName := action.InterruptRunningTask("CHK") //CHK interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -247,8 +304,20 @@ func processPacket(packet []byte) {
 				alstatus.PaStatus("", "CHK", "refuse")
 			}
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "CHK" {
+			active.TaskCreating = ""
+		}
+
 	case 0x0a: // Tone-test
 		if active.ActivedCab != "" {
+			//检查是否有任务正在创建
+			active.WaitTaskCreate("VOL")
+			if active.TaskCreating == "" {
+				active.TaskCreating = "VOL"
+			}
+
 			if priority.CheckPriority("VOL") {
 
 				runningTaskName := action.InterruptRunningTask("VOL") //VOL interrupt other
@@ -260,11 +329,43 @@ func processPacket(packet []byte) {
 				alstatus.PaStatus("", "VOL", "refuse")
 			}
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "VOL" {
+			active.TaskCreating = ""
+		}
+
 	case 0x0e: //TMS answer PAD
+
+		handler := packet[8]
+		key := suppressKey("exten", handler)
+
+		//Drop other handler in 2 sec
+		//PACUs---call---->ICP1
+		//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
+		if handler == 0x01 {
+			if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
+				utils.LoggerDebug.Printf("Suppressed duplicate ICP Alarm (handler=0x01) for PAD: within 2 seconds")
+				return
+			}
+
+			time.AfterFunc(2*time.Second, func() {
+				suppressedExts.Delete(key)
+				utils.LoggerDebug.Printf("Suppression released .")
+			})
+		}
+
+		//检查是否有任务正在创建
+		active.WaitTaskCreate("PAD-TMS")
+		if active.TaskCreating == "" {
+			active.TaskCreating = "PAD-TMS"
+		}
+
 		if priority.CheckPriority("PAD-TMS") {
 
 			//Before Answer PAD
 			if packet[8] == 0x01 {
+
 				runningTaskName := action.InterruptRunningTask("PAD-TMS") //PAD-TMS interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -285,6 +386,11 @@ func processPacket(packet []byte) {
 			alstatus.PaStatus("", "PAD-TMS", "refuse")
 		}
 
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "PAD-TMS" {
+			active.TaskCreating = ""
+		}
+
 	case 0x0b: // reset all PAD
 		AlarmHoldResetAll(packet[8]) // reset all pad
 
@@ -296,10 +402,35 @@ func processPacket(packet []byte) {
 
 	case 0x0d: // ICP answer PAD
 
+		handler := packet[8]
+		key := suppressKey("exten", handler)
+
+		//Drop other handler in 2 sec
+		//PACUs---call---->ICP1
+		//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
+		if handler == 0x01 {
+			if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
+				utils.LoggerDebug.Printf("Suppressed duplicate ICP Alarm (handler=0x01) for PAD: within 2 seconds")
+				return
+			}
+
+			time.AfterFunc(2*time.Second, func() {
+				suppressedExts.Delete(key)
+				utils.LoggerDebug.Printf("Suppression released for key: %s", key)
+			})
+		}
+
+		//检查是否有任务正在创建
+		active.WaitTaskCreate("PAD-ICP")
+		if active.TaskCreating == "" {
+			active.TaskCreating = "PAD-ICP"
+		}
+
 		if priority.CheckPriority("PAD-ICP") {
 
 			//Before Answer PAD
 			if packet[8] == 0x01 {
+
 				runningTaskName := action.InterruptRunningTask("PAD-ICP") //PAD-ICP interrupt other
 				if runningTaskName != "" {
 					time.Sleep(time.Millisecond * 100) //wait endpoint release
@@ -318,6 +449,12 @@ func processPacket(packet []byte) {
 		} else {
 			alstatus.PaStatus("", "PAD-ICP", "refuse")
 		}
+
+		time.Sleep(3 * time.Second)
+		if active.TaskCreating == "PAD-ICP" {
+			active.TaskCreating = ""
+		}
+
 		//case 0xf1: //Set remote master
 
 		//default:
@@ -603,23 +740,6 @@ func AlarmHandleICP(data []byte) {
 	pos := data[13]
 	exten := fmt.Sprintf("24%c%c", carr, pos)
 
-	key := suppressKey(exten, handler)
-
-	//Drop other handler in 2 sec
-	//PACUs---call---->ICP1
-	//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
-	if handler == 0x01 {
-		if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
-			utils.LoggerDebug.Printf("Suppressed duplicate ICP Alarm (handler=0x01) for PAD:%s within 4 seconds", exten)
-			return
-		}
-
-		time.AfterFunc(4*time.Second, func() {
-			suppressedExts.Delete(key)
-			utils.LoggerDebug.Printf("Suppression released for key: %s", key)
-		})
-	}
-
 	switch handler {
 	case 0x01: //answer(ICP+Alarm+PACU)
 		//NotifyPaiu(exten, "answer")

+ 1 - 6
internal/app/stc/priority/index.go

@@ -4,7 +4,6 @@ import (
 	"os"
 	"pbx-api-gin/pkg/utils"
 	"strconv"
-	"sync"
 
 	"gopkg.in/ini.v1"
 )
@@ -112,13 +111,9 @@ func GetPriorityByKey(key string) int {
 	}
 }
 
-var priorityLock sync.RWMutex
-
 // check priority , if the running priority is lowwer than the to run priority
 func CheckPriority(runType string) bool {
-
-	priorityLock.RLock()
-	defer priorityLock.RUnlock() // 自动释放
+	utils.LoggerDebug.Printf("CheckPriority  TorunType:%s 	SpecialVoice:%d", runType, SpecialVoice)
 
 	//Check special voice can not interrupt
 	if SpecialVoice == 1 {