root 10 horas atrás
pai
commit
e72488546f

+ 20 - 913
internal/app/ami/action/call.go

@@ -3,45 +3,12 @@ package action
 import (
 	"errors"
 	"fmt"
-	"pbx-api-gin/internal/app/stc/active"
 	"pbx-api-gin/internal/app/stc/priority"
-	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
-	"strings"
-	"sync"
 	"time"
 )
 
-var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "2425", "2431", "2432", "2433", "2434", "2435", "2441", "2442", "2443", "2444",
-	"2445", "2451", "2452", "2453", "2454", "2455", "2461", "2462", "2463", "2464", "2465", "2471", "2472", "2473", "2474", "2475", "2481", "2482", "2483",
-	"2484", "2485", "2411", "2412"}
-
-var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
-
-var Speakers = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181", "2311", "2381"}
-
-// Function triggered before no cab occupied signal interrupt
-func InActiveHangup() {
-	if active.ActivedCab == "" {
-		HangupTask("PA")
-		HangupTask("CPA")
-		HangupTask("VOL")
-		//HangupTask("PAD-OCC")
-	} else {
-		HangupTask("PA")
-		HangupTask("PAD-OCC")
-		HangupTask("CPA")
-		HangupTask("EMG")
-		HangupTask("SPC")
-		HangupTask("DCS")
-		HangupTask("STN")
-		HangupTask("CHK")
-		HangupTask("VOL")
-		Hangup("2311") //hangup cabcab
-	}
-}
-
 // Hangup 挂断指定分机或通道
 func Hangup(channel string) {
 	lfshook.NewLogger().Infof("Hangup extensions/channel :%s", channel)
@@ -59,361 +26,14 @@ func Hangup(channel string) {
 	}
 }
 
-// Hangup 挂断所有分机,除指定分机和PAD
-func HangupAllExcept(caller string) {
-
-	//all PACU
-	for _, ret := range Pacus {
-		Hangup(ret)
-	}
-
-	switch caller {
-	case "2311":
-		Hangup("1411") //IO1
-		Hangup("1481") //IO8
-		//Hangup("2311") //ICP1
-		Hangup("2381") //ICP8
-	case "2381":
-		Hangup("1411") //IO1
-		Hangup("1481") //IO8
-		Hangup("2311") //ICP1
-		//Hangup("2381") //ICP8
-	case "1411":
-		//Hangup("1411") //IO1
-		Hangup("1481") //IO8
-		Hangup("2311") //ICP1
-		Hangup("2381") //ICP8
-	case "1481":
-		Hangup("1411") //IO1
-		//Hangup("1481") //IO8
-		Hangup("2311") //ICP1
-		Hangup("2381") //ICP8
-	case "":
-		Hangup("1411") //IO1
-		Hangup("1481") //IO8
-		Hangup("2311") //ICP1
-		Hangup("2381") //ICP8
-	}
-}
-
 // Hangup task
-func HangupTask(TaskName string) {
-	lfshook.NewLogger().Infof("HangupTask Check TaskName:%s ", TaskName)
-
-	if TaskName == "PAD-OCC" {
-		resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
-		if err != nil {
-			lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
-			return
-		}
-
-		//lfshook.NewLogger().Infof("============QueueStatus ret :%+v", resCaller)
-		if resCaller != nil {
-			//lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", resCaller.Entrys)
-			if resCaller.Entrys != nil {
-				for _, caller := range resCaller.Entrys {
-					//lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
-					time.Sleep(time.Millisecond * 50)
-					RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
-				}
-			}
-		}
-		priority.OCCAnswer = 0
-	}
-
-	taskInfo, ok := priority.RegistryTask.Get(TaskName)
+func HangupTask() {
+	_, taskInfo, ok := priority.RegistryTask.HighestPriorityRunningTask()
 	if ok {
-		HangupAllLocalChan()
+		lfshook.NewLogger().Infof("HangupTask Check TaskName:%s ", taskInfo.RunType)
 		ConfbridgeKick(taskInfo.ConfbridgeID, "all")
 		Hangup(taskInfo.RunChannel)
-	}
-}
-
-// interrupt the running task
-func InterruptRunningTask(toRunTask string) string {
-	utils.LoggerDebug.Printf("InterruptRunningTask  TorunType:%s", toRunTask)
-
-	var task priority.TaskInfo
-	var taskName string
-	var ok bool
-
-	lfshook.NewLogger().Infof("InterruptRunningTask toRuntask:%s  ", toRunTask)
-
-	if toRunTask != "PA" && toRunTask != "PAD-ICP" && toRunTask != "PAD-TMS" { // ignore C2C
-		taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask1()
-		if !ok {
-			return ""
-		}
-	} else { // have to check C2C
-		taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask()
-		if !ok {
-			return ""
-		}
-	}
-
-	utils.LoggerDebug.Printf("InterruptRunningTask  RunningTask:%+v", taskName)
-	//lfshook.NewLogger().Infof("InterruptRunningTask RunningTask:%+v  ", task)
-	//same type return
-	if toRunTask == taskName {
-		if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" || toRunTask == "PAD-OCC" {
-
-			//Auto Answer PAD-OCC one by one, clean the old confbridge and channels before answer a new PAD .
-			if toRunTask == "PAD-OCC" {
-				Hangup(task.RunChannel) //pad
-				ConfbridgeKick(task.ConfbridgeID, "all")
-				//HangupIO() //io
-				//interrupt OCC-PAD Hangup OI
-				if active.ActivedCab == "1" {
-					Hangup("1411")
-				} else if active.ActivedCab == "8" {
-					Hangup("1481")
-				} else {
-					if active.ActivedCabDelay == "1" {
-						Hangup("1411")
-					} else if active.ActivedCabDelay == "8" {
-						Hangup("1481")
-					} else {
-						Hangup("1411")
-					}
-				}
-				//lfshook.NewLogger().Infof("===InterruptRunningTask=ret==== ")
-			}
-			return taskName
-		}
-	}
-
-	//pad all  reset
-	if toRunTask == "AlarmHoldResetAll" {
-		HangupAllLocalChan()
-		return taskName
-	}
-
-	switch task.RunType {
-	case "SPC":
-		if toRunTask == "C2C" {
-			HangupICP()
-		} else {
-			ConfbridgeKick(task.ConfbridgeID, "all")
-		}
-		time.Sleep(time.Millisecond * 200)
-	case "CHK":
-		if toRunTask == "C2C" {
-			HangupICP()
-		} else {
-			ConfbridgeKick(task.ConfbridgeID, "all")
-		}
-		time.Sleep(time.Millisecond * 200)
-	case "DCS":
-		if toRunTask == "STN" {
-			return taskName
-		} else if toRunTask == "C2C" {
-			HangupICP()
-		} else {
-			ConfbridgeKick(task.ConfbridgeID, "all")
-		}
-
-		time.Sleep(time.Millisecond * 200)
-	case "STN":
-		if toRunTask == "DCS" {
-			return taskName
-		} else if toRunTask == "C2C" {
-			HangupICP()
-		} else {
-			ConfbridgeKick(task.ConfbridgeID, "all")
-		}
-		time.Sleep(time.Millisecond * 200)
-	case "CPA":
-		//kick CPA members
-		if toRunTask != "C2C" {
-			CPAConfbridgeKick(task)
-			//alstatus.PaStatus("", "CPA", "end")
-		} else if toRunTask == "C2C" {
-			HangupICP()
-		}
-		time.Sleep(time.Millisecond * 200)
-	case "EMG":
-		//kick EMG members
-		if toRunTask == "EMG" {
-			ConfbridgeKick(task.ConfbridgeID, "all")
-		} else if toRunTask != "C2C" {
-
-			EMGConfbridgeKick(task)
-			//alstatus.PaStatus("", "EMG", "end")
-		} else if toRunTask == "C2C" {
-			HangupICP()
-		}
-		time.Sleep(time.Millisecond * 200)
-	case "C2C": // Interrupt C2C task running,
-		if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
-			HangupICP()
-			return taskName
-		}
-
-	case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
-		if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
-			break
-		}
-
-		priority.InterruptedPad = "PAD-ICP"
-
-		//lfshook.NewLogger().Infof("InterruptRunningTask interrupt PAD-ICP/PAD-TMS ,Running type :%s !", task.RunType)
-
-		chans, err := CoreShowChannels()
-		if err != nil {
-			lfshook.NewLogger().Infof("InterruptRunningTask CoreShowChannels err:%+v", err)
-			return taskName
-		}
-
-		//1. Redirect the connected PAD to 0300,hangup the other pad channel
-		for _, ret := range chans {
-			// Redirect the connected PAD to 0300
-			if utils.IsPAIU(ret.CallerIDNum) {
-				//lfshook.NewLogger().Infof("====interrupt PAD ==== %+v ", ret)
-
-				if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
-					err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
-					if err != nil {
-						lfshook.NewLogger().Infof("InterruptRunningTask Redirect err:%+v", err)
-						return taskName
-					}
-					//lfshook.NewLogger().Infof("====interrupt PAD =1111=== %+v ", ret)
-					number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
-					active.NotifyPaiu(number, "hold")
-					//HangupAllLocalChan()
-				}
-			}
-		}
-
-		for _, ret := range chans {
-			//hangup pad call ICP channel
-			if utils.IsPAIU(ret.CallerIDNum) {
-				if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
-					//lfshook.NewLogger().Infof("Hangup PAD Channel :%+v", ret.Channel)
-					Hangup(ret.Channel)
-				}
-			}
-		}
-		alstatus.PaStatus("", "PAD", "end")
-		priority.RegistryTask.StopAndUnregister("PAD-ICP")
-		priority.RegistryTask.StopAndUnregister("PAD-TMS")
-		//2. hangup task channel (ICP + PACU)
-		//lfshook.NewLogger().Infof("===InterruptRunningTask=2. hangup task channel === ")
-		HangupAllLocalChan()
-		HangupICP()
-
-	case "PAD-OCC": // Interrupt PAD-OCC task running,
-
-		if toRunTask == "C2C" {
-			HangupICP()
-			break
-
-		} else {
-			priority.InterruptedPad = "PAD-OCC"
-			priority.OCCAnswer = 0
-
-			resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
-			if err != nil {
-				lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
-				return taskName
-			}
-
-			if resCaller == nil {
-				return taskName
-			}
-
-			if resCaller.Entrys != nil {
-				for _, caller := range resCaller.Entrys {
-					//lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
-					time.Sleep(time.Millisecond * 50)
-					RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
-				}
-			}
-
-			priority.RegistryTask.StopAndUnregister("PAD-OCC")
-			//2. Hangup connected PAD
-			//lfshook.NewLogger().Infof("===InterruptRunningTask=Hangup connected PAD=== ")
-			Hangup(task.RunChannel)
-
-			//3. interrupt OCC-PAD Hangup OI
-			if active.ActivedCab == "1" {
-				Hangup("1411")
-			} else if active.ActivedCab == "8" {
-				Hangup("1481")
-			} else {
-				if active.ActivedCabDelay == "1" {
-					Hangup("1411")
-				} else if active.ActivedCabDelay == "8" {
-					Hangup("1481")
-				} else {
-					Hangup("1411")
-				}
-			}
-
-			HangupAllLocalChan()
-			ConfbridgeKick(task.ConfbridgeID, "all")
-
-			//occ pad end
-			if priority.PADOccStart == 1 {
-				alstatus.OccPad("end")
-				alstatus.PaStatus("", "PAD", "end")
-				priority.PADOccStart = 0
-				priority.OCCAnswer = 0
-			}
-		}
-
-	default:
-		lfshook.NewLogger().Infof("InterruptRunningTask goto default !")
-		//if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
-		//	Hangup(priority.RunningPATaskChan)
-		//}
-		if toRunTask != "C2C" && task.RunType != "PA" {
-			Hangup(task.RunChannel)
-			ConfbridgeKick(task.ConfbridgeID, "all")
-		}
-	}
-	return taskName
-}
-
-// Hangup all ICP
-func HangupICP() {
-	Hangup("2311") //ICP1
-	Hangup("2381") //ICP8
-}
-
-// Hangup all IO
-func HangupIO() {
-	Hangup("1411") //IO1
-	Hangup("1481") //IO8
-}
-
-// Hangup all PACU
-func HangupAllPACU() {
-	//all PACU
-	for _, ret := range Pacus {
-		Hangup(ret)
-	}
-}
-
-func HangupAllLocalChan() {
-	chans, err := CoreShowChannels()
-	if err != nil {
-		lfshook.NewLogger().Infof("CoreShowChannels %+v", err)
-		return
-	}
-
-	for _, ret := range chans {
-		if strings.Contains(ret.Channel, "Local") && !strings.Contains(ret.Channel, "0502@default") {
-			//lfshook.NewLogger().Infof("HangupAllLocalChan=====hangup========= %+v", ret)
-			Hangup(ret.Channel)
-		}
-	}
-}
-
-// Hangup all PACU
-func HangupAllPAD() {
-	//all PAD
-	for _, ret := range Pads {
-		Hangup(ret)
+		time.Sleep(100 * time.Millisecond)
 	}
 }
 
@@ -422,48 +42,6 @@ func HangupAll() {
 	utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "hangup request all")
 }
 
-// Dial 拨打号码
-func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
-	chanel := fmt.Sprintf("%s/%s@default", "Local", src)
-	action := map[string]string{
-		"Action":   "Originate",
-		"Channel":  chanel,
-		"Exten":    dst,
-		"Context":  dialrule,
-		"CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
-		"Priority": "1",
-		"Variable": fmt.Sprintf("CAB=%s", callType),
-		"async":    "true",
-	}
-	//lfshook.NewLogger().Infof("================dial action %+v", action)
-	res, _, err := AminInstance.Send(action)
-	if err != nil {
-		lfshook.NewLogger().Errorf("%+v", err)
-	}
-	lfshook.NewLogger().Info(res)
-}
-
-// Dial 拨打号码
-func DialICP(src, dst, dialrule, callerID, callerName string) {
-	chanel := fmt.Sprintf("%s/%s@call-icp", "Local", src)
-	action := map[string]string{
-		"Action":   "Originate",
-		"Channel":  chanel,
-		"Exten":    dst,
-		"Context":  dialrule,
-		"CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
-		"Priority": "1",
-		"Variable": fmt.Sprintf("CBID=%s", callerID),
-		"async":    "true",
-	}
-	lfshook.NewLogger().Infof("dial action %+v", action)
-	res, _, err := AminInstance.Send(action)
-	if err != nil {
-		lfshook.NewLogger().Errorf("%+v", err)
-	}
-	lfshook.NewLogger().Info(res)
-}
-
 // 获取分机状态
 func ExtenStatus(exten string) (Status string) {
 	action := map[string]string{
@@ -482,160 +60,6 @@ func ExtenStatus(exten string) (Status string) {
 	return res["StatusText"]
 }
 
-// PACU ChanSpy
-func ChanSpy(src, dst string, whisper, bargein bool) {
-	lfshook.NewLogger().Infof("chan spy src:%s dst:%s", src, dst)
-
-	//channel := fmt.Sprintf("%s/%s", utils.DialPrefix, dst)
-	channel := fmt.Sprintf("Local/%s@aio-rule", dst)
-	data := fmt.Sprintf("%s/%s,qBE", utils.DialPrefix, src)
-	/*
-		if whisper {
-			data = fmt.Sprintf("%s,w", data)
-		}
-
-		if bargein {
-			data = fmt.Sprintf("%s,B", data)
-		}
-	*/
-	action := map[string]string{
-		"Action":      "Originate",
-		"Channel":     channel, // 不存在的通话
-		"Application": "ChanSpy",
-		"Data":        data, // 存在的通话
-		"CallerID":    dst,
-		"Async":       "true",
-	}
-	lfshook.NewLogger().Infof("PACU ChanSpy action %+v", action)
-	_, _, err := AminInstance.Send(action)
-	if err != nil {
-		lfshook.NewLogger().Errorf("%+v", err)
-	}
-}
-
-// Redirect 转接
-func RedirectInQueue(channel, dst, dialrule, callerID string) (err error) {
-	//callerID := "redirect"
-	//lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
-	if !utils.IsChannel(channel) {
-		//callerID = channel
-		if channel, err = GetChannelByExtenNotBridged(channel); err != nil {
-			return err
-		}
-	}
-
-	action := map[string]string{
-		"Action":   "Redirect",
-		"Channel":  channel,
-		"Exten":    dst,
-		"Context":  dialrule,
-		"CallerID": callerID,
-		"Priority": "1",
-		"async":    "true",
-	}
-	lfshook.NewLogger().Infof("RedirectInQueue: %+v", action)
-	res, _, err := AminInstance.Send(action)
-	if err != nil {
-		lfshook.NewLogger().Error(err)
-	}
-	lfshook.NewLogger().Info(res)
-	return err
-}
-
-// Redirect 转接
-func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
-	//callerID := "redirect"
-	//lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
-	if !utils.IsChannel(channel) {
-		callerID = channel
-		if channel, err = GetChannelByExten(channel); err != nil {
-			return err
-		}
-	}
-
-	action := map[string]string{
-		"Action":   "Redirect",
-		"Channel":  channel,
-		"Exten":    dst,
-		"Context":  dialrule,
-		"CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
-		"Priority": "1",
-		"async":    "true",
-	}
-	lfshook.NewLogger().Infof("Redirect: %+v", action)
-	res, _, err := AminInstance.Send(action)
-	if err != nil {
-		lfshook.NewLogger().Error(err)
-	}
-	lfshook.NewLogger().Info(res)
-	return err
-}
-
-func SetPadTimer() {
-
-	//toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) //Get PAD priori 获取之前打断的报警优先级
-	toRunPadpriority := priority.GetPriorityByKey("PAD-ICP")
-	_, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
-	if ok {
-		if taskTmp.Priority < toRunPadpriority { //higher priority task running ,do not set timer
-			utils.LoggerDebug.Printf("PAD SetPadTimer runing priority:%d toRun priority:%d , return !", taskTmp.Priority, toRunPadpriority)
-			return
-		}
-	}
-
-	utils.LoggerDebug.Printf("PAD SetPadTimer check 0300")
-	res, err := QueueStatus("0300", "")
-	if err != nil {
-		lfshook.NewLogger().Infof("QueueStatus err%+v", err)
-		return
-	}
-	if res == nil {
-		return
-	}
-	if res.Calls != "0" {
-
-		utils.LoggerDebug.Printf("PAD SetPadTimer Set QueueTimer timeout %ds !", active.PADTimeout)
-		//active.SetTimer = true
-		//lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
-		if active.QueueTimer != nil {
-			if active.QueueTimer.Stop() {
-				utils.LoggerDebug.Printf("Stop PAD timer true !")
-			} else {
-				utils.LoggerDebug.Printf("Stop PAD timer false !")
-			}
-		}
-		//lfshook.NewLogger().Logger.Infof("=========Start PAD timer !======%d=======", active.PADTimeout)
-		active.QueueTimer = time.AfterFunc(time.Duration(active.PADTimeout)*time.Second, func() { // check the PAD 30s timeout
-			//active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
-			//if both not active , return
-			if active.ActivedCab == "" {
-				return
-			}
-
-			res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
-			if err != nil {
-				lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
-				return
-			}
-
-			if res == nil {
-				return
-			}
-
-			if res.Calls == "0" { // OCC queue empty
-				priority.ICPAnswer = 0
-				for _, ret := range alstatus.PadQueues {
-					//utils.LoggerDebug.Printf("PAD to OCC exten:%s", ret.Exten)
-					//order by pos
-					RedirectInQueue(ret.Exten, "0301", "queues-occ", ret.Exten) // redirect All ICP-PAD redirect to OCC queue
-					time.Sleep(time.Millisecond * 100)
-				}
-			}
-		})
-	}
-
-}
-
 func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
 
 	action := map[string]string{
@@ -657,186 +81,6 @@ func ConfbridgeKick(confnum, channel string) (res map[string]string, err error)
 	return res, nil
 }
 
-func CPAConfbridgeKick(confInfo priority.TaskInfo) (res map[string]string, err error) {
-
-	if !confInfo.Running {
-		utils.LoggerDebug.Printf("CPA CPAConfbridgeKick , not running, return .")
-		return
-	}
-
-	utils.LoggerDebug.Printf("CPA CPAConfbridgeKick , kick all members .")
-
-	chans, err := ConfbridgeList(confInfo.ConfbridgeID)
-	if err != nil {
-		return nil, errors.New(res["Message"])
-	}
-
-	for _, confChan := range chans {
-		if active.TrainDevide == 1 {
-			if active.CabNum == "1" { //在1车车厢内
-				if !strings.Contains(confChan, "PJSIP/1411") {
-					ConfbridgeKick(confInfo.ConfbridgeID, confChan)
-				}
-			} else { //在8车车厢内
-				if !strings.Contains(confChan, "PJSIP/1481") {
-					ConfbridgeKick(confInfo.ConfbridgeID, confChan)
-				}
-			}
-		} else {
-			if active.ActivedCab != "1" {
-				if !strings.Contains(confChan, "PJSIP/1411") {
-					ConfbridgeKick(confInfo.ConfbridgeID, confChan)
-				}
-			} else {
-				if !strings.Contains(confChan, "PJSIP/1481") {
-					ConfbridgeKick(confInfo.ConfbridgeID, confChan)
-				}
-			}
-		}
-	}
-	if confInfo.Running {
-		alstatus.PaStatus("", "CPA", "end")
-	}
-	priority.RegistryTask.UpdateStatus("CPA", false)
-	return res, nil
-}
-
-func CPAConfbridgeReinvite(task priority.TaskInfo) bool {
-
-	if task.Running {
-		utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , already running, return .")
-		return false
-	}
-
-	time.Sleep(time.Millisecond * 100)
-	utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , resume CPA .")
-
-	chans, err := ConfbridgeList(task.ConfbridgeID)
-	if len(chans) > 1 || err != nil {
-		utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , return . ConfbridgeList chans > 1 or err !")
-		return false
-	}
-
-	if priority.PAInterrupt == 1 { // PA 打断标签判断
-		utils.LoggerDebug.Printf("CPA ConfbridgeReinvite , PA ready to go , return !")
-		return false
-	} else if priority.CABInterrupt == 1 { //CABCAB 打断标签判断
-
-		priority.TaskCreating = "CPA"
-		for _, ext := range Speakers { //高优先级被cabcab打断,或者高优先级直接挂断
-			if utils.IsICP(ext) {
-				if priority.CABInterrupt == 1 {
-					utils.LoggerDebug.Printf("CPA ConfbridgeReinvite , Get CABCAB Interrupt resume CPA , ignore %s continue .", ext)
-					continue
-				}
-			}
-			ConfbridgeReinvite(ext, "call-speakers-cpa", task.ConfbridgeID)
-		}
-		//task.Running = true
-		priority.RegistryTask.UpdateStatus("CPA", true)
-		time.Sleep(time.Millisecond * 200) //等待通道建立
-		priority.TaskCreating = ""
-		alstatus.PaStatus("", "CPA", "start")
-		priority.CPAActived = 0
-	} else if priority.TaskCreating != "" {
-		utils.LoggerDebug.Printf("CPA ConfbridgeReinvite , other PA ready to go , return !")
-		return false
-	} else {
-		priority.TaskCreating = "CPA"
-		for _, ext := range Speakers {
-			ConfbridgeReinvite(ext, "call-speakers-cpa", task.ConfbridgeID)
-		}
-		//task.Running = true
-		priority.RegistryTask.UpdateStatus("CPA", true)
-		time.Sleep(time.Millisecond * 200) //等待通道建立
-		priority.TaskCreating = ""
-		alstatus.PaStatus("", "CPA", "start")
-		priority.CPAActived = 0
-	}
-	return true
-}
-
-func EMGConfbridgeKick(confInfo priority.TaskInfo) (res map[string]string, err error) {
-
-	if !confInfo.Running {
-		utils.LoggerDebug.Printf("EMG EMGConfbridgeKick , not running, return .")
-		return
-	}
-
-	utils.LoggerDebug.Printf("EMG EMGConfbridgeKick , kick all members .")
-	chans, err := ConfbridgeList(confInfo.ConfbridgeID)
-	if err != nil {
-		return nil, errors.New(res["Message"])
-	}
-
-	for _, confChan := range chans {
-		if !strings.Contains(confChan, "0502@default") {
-			ConfbridgeKick(confInfo.ConfbridgeID, confChan)
-		}
-	}
-
-	if confInfo.Running {
-		alstatus.PaStatus("", "EMG", "end")
-	}
-	//confInfo.Running = false
-	priority.RegistryTask.UpdateStatus("EMG", false)
-	return res, nil
-}
-
-func EMGConfbridgeReinvite(task priority.TaskInfo) {
-
-	if priority.CPAActived == 1 && priority.AllTasks.EMG.Priority > priority.AllTasks.CPA.Priority {
-		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , CPA actived , return .")
-		return
-	}
-
-	//if priority.CABInterrupt != 1 {
-	//	time.Sleep(time.Millisecond * 100)
-	//} else {
-	//time.Sleep(time.Second * 1) //wait cpa start first
-	//}
-
-	utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , resume EMG .")
-	if task.Running {
-		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , already running ,return .")
-		return
-	}
-
-	if priority.PAInterrupt == 1 { // PA 打断标签判断
-		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , PA ready to go , return !")
-		return
-	} else if priority.CABInterrupt == 1 { //CABCAB 打断标签判断
-		priority.TaskCreating = "EMG"
-		for _, ext := range Speakers { //高优先级被cabcab打断,或者高优先级直接挂断
-			if utils.IsICP(ext) {
-				if priority.CABInterrupt == 1 {
-					utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , Get CABCAB Interrupt resume EMG , ignore %s continue .", ext)
-					continue
-				}
-			}
-			ConfbridgeReinvite(ext, "call-speakers-emg", task.ConfbridgeID)
-		}
-		//task.Running = true
-		priority.RegistryTask.UpdateStatus("EMG", true)
-		time.Sleep(time.Millisecond * 200) //等待通道建立
-		priority.TaskCreating = ""
-		alstatus.PaStatus("", "EMG", "start")
-	} else if priority.TaskCreating != "" {
-		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , other PA ready to go , return !")
-		return
-	} else {
-		priority.TaskCreating = "EMG"
-		for _, ext := range Speakers {
-			ConfbridgeReinvite(ext, "call-speakers-emg", task.ConfbridgeID)
-		}
-		//task.Running = true
-		priority.RegistryTask.UpdateStatus("EMG", true)
-		time.Sleep(time.Millisecond * 200) //等待通道建立
-		priority.TaskCreating = ""
-		alstatus.PaStatus("", "EMG", "start")
-	}
-}
-
 func ConfbridgeList(confnum string) (chans []string, err error) {
 
 	action := map[string]string{
@@ -888,159 +132,22 @@ func ConfbridgeReinvite(src, context, confID string) {
 	lfshook.NewLogger().Info(res)
 }
 
-func ICPConfbridgeReinvite(confID, paType string) {
-
-	if priority.CABInterrupt == 1 || priority.CABInterrupt == 1 {
-		utils.LoggerDebug.Printf("ICPConfbridgeReinvite, Get PA/CABCAB Interrupt resume %s faild .", paType)
-		return
-	}
-
-	switch paType {
-	case "PAD-OCC":
-		go DialICP("8", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("8", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "CPA":
-		go DialICP("2", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("2", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "EMG":
-		go DialICP("3", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("3", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "SPC":
-		go DialICP("6", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("6", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "STN":
-		go DialICP("4", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("4", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "DCS":
-		go DialICP("5", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("5", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "CHK":
-		go DialICP("10", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("10", "2381", "confbridge-join", confID, "8") //ICP8---call
-	case "VOL":
-		go DialICP("11", "2311", "confbridge-join", confID, "1") //ICP1---call
-		go DialICP("11", "2381", "confbridge-join", confID, "8") //ICP8---call
-
-	}
-}
-
-var waitMutex sync.Mutex
-
-// 设置全局变量控制任务创建过程,避免被其他任务打乱任务创建过程
-func WaitTaskCreate(task string, args ...string) { //arg1(task chan)
-	utils.LoggerDebug.Printf("%s check task creating ..... ,TaskCreating = %s", task, priority.TaskCreating)
-
-	waitMutex.Lock()
-	defer waitMutex.Unlock()
-
-	switch priority.TaskCreating {
-	case "C2C":
-		if /*task == "PA" ||*/ task == "CPA" {
-			//获取正在创建的任务的优先级
-			//priorityC2C := priority.GetPriorityByKey("C2C")
-			//获取将要创建的任务的优先级
-			//priorityTask := priority.GetPriorityByKey(task)
-			//比较优先级,确定是否终止正在创建的任务
-
-			/*if priorityC2C < priorityTask {
-				utils.LoggerDebug.Printf("%s check task C2C creating , hangup CPA %s ", task, args[0])
-
-				//结束task(CPA)
-				if len(args) > 0 {
-					Hangup(args[0])
-					goto DELAY
-				}
-			} else {
-				//结束C2C,PA 则不需要挂断ICP(由ICP自行处理优先级)
-				utils.LoggerDebug.Printf("%s check task C2C creating , hangup C2C ICPs ", task)
-				HangupICP()
-				goto DELAY
-			}*/
-		} else {
-			goto DEFAULT
-		}
-
-		return
-	case "CPA":
-		if task == "PA" /*|| task == "C2C"*/ {
-			//获取正在创建的任务的优先级
-			priorityCPA := priority.GetPriorityByKey("CPA")
-			//获取将要创建的任务的优先级
-			priorityTask := priority.GetPriorityByKey(task)
-			//比较优先级,确定是否终止正在创建的任务
-
-			if priorityCPA < priorityTask {
-				utils.LoggerDebug.Printf("%s check task CPA creating , hangup %s %s", task, task, args[0])
-				//结束task(PA,CPA)
-				if len(args) > 0 {
-					Hangup(args[0])
-					goto DELAY
-				}
-			} else {
-				//结束CPA,获取CPA通道
-				if active.ActivedCab == "1" {
-					utils.LoggerDebug.Printf("%s check task  creating , hangup CPA %s ", task, args[0])
-					Hangup("1481")
-					goto DELAY
-				} else if active.ActivedCab == "8" {
-					utils.LoggerDebug.Printf("%s check task C2C creating , hangup CPA %s ", task, args[0])
-					Hangup("1411")
-					goto DELAY
-				}
-			}
-		} else {
-			goto DEFAULT
-		}
-		return
-	case "PA":
-		if task == "CPA" /*|| task == "C2C"*/ {
-			//获取正在创建的任务的优先级
-			priorityPA := priority.GetPriorityByKey("PA")
-			//获取将要创建的任务的优先级
-			priorityTask := priority.GetPriorityByKey(task)
-
-			//比较优先级,确定是否终止正在创建的任务
-			if priorityPA < priorityTask {
-				utils.LoggerDebug.Printf("%s check task PA creating , hangup CPA %s ", task, args[0])
-				//结束task(CPA)
-				if len(args) > 0 {
-					Hangup(args[0])
-					goto DELAY
-				}
-			} else {
-				//结束PA,获取PA通道
-				if active.ActivedCab == "1" {
-					utils.LoggerDebug.Printf("%s check task PA creating , hangup PA %s ", task, "2311")
-					Hangup("2311")
-					goto DELAY
-				} else if active.ActivedCab == "8" {
-					utils.LoggerDebug.Printf("%s check task PA creating , hangup PA %s ", task, "2381")
-					Hangup("2381")
-					goto DELAY
-				}
-			}
-		} else {
-			goto DEFAULT
-		}
-		return
+// Dial 拨打号码
+func Dial(src, dst, dialrule, callerID, callerName string) {
+	chanel := fmt.Sprintf("%s/%s@default", "Local", src)
+	action := map[string]string{
+		"Action":   "Originate",
+		"Channel":  chanel,
+		"Exten":    dst,
+		"Context":  dialrule,
+		"CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
+		"Priority": "1",
+		"async":    "true",
 	}
-
-DEFAULT:
-	//utils.LoggerDebug.Printf("%s waiting trd=============previous task:%s creating ..... ", task, priority.TaskCreating)
-
-	for i := 0; i < 20; i++ {
-		if priority.TaskCreating != "" {
-			utils.LoggerDebug.Printf("%s waiting previous task:%s creating ..... ", task, priority.TaskCreating)
-			time.Sleep(time.Millisecond * 100)
-		} else {
-			utils.LoggerDebug.Printf("TaskCreating is nill, Set TaskCreating=%s", task)
-			priority.TaskCreating = task
-			return
-		}
+	lfshook.NewLogger().Infof("dial action %+v", action)
+	res, _, err := AminInstance.Send(action)
+	if err != nil {
+		lfshook.NewLogger().Errorf("%+v", err)
 	}
-	priority.TaskCreating = task
-	utils.LoggerDebug.Printf("%s waiting previous task:%s creating timeout ! Set TaskCreating=%s", task, priority.TaskCreating, task)
-
-DELAY:
-	time.Sleep(100 * time.Millisecond)
+	lfshook.NewLogger().Info(res)
 }

+ 0 - 122
internal/app/ami/action/channel.go

@@ -1,122 +0,0 @@
-package action
-
-import (
-	"errors"
-	"pbx-api-gin/api/model"
-	"pbx-api-gin/pkg/lfshook"
-	"pbx-api-gin/pkg/utils"
-)
-
-// CoreShowChannels 获取通话通道
-func CoreShowChannels() (result []model.CoreShowChannelResVO, err error) {
-	// 通过 src 查询对应通道
-	_, events, err := AminInstance.Send(map[string]string{
-		"Action": "CoreShowChannels",
-	})
-	if err != nil {
-		lfshook.NewLogger().Errorf("core show channels error %+v", err)
-		return nil, err
-	}
-
-	lfshook.NewLogger().Infof("events %+v", events)
-	result = make([]model.CoreShowChannelResVO, 0)
-	for _, event := range events {
-		if event.Data["Event"] == "CoreShowChannel" {
-			channel := model.CoreShowChannelResVO{
-				CallerIDName:      event.Data["CallerIDName"],
-				CallerIDNum:       event.Data["CallerIDNum"],
-				ConnectedLineName: event.Data["ConnectedLineName"],
-				ConnectedLineNum:  event.Data["ConnectedLineNum"],
-				Channel:           event.Data["Channel"],
-				Duration:          event.Data["Duration"],
-				DurationSecond:    utils.TimeStringToSecond(event.Data["Duration"]),
-				ChannelStateDesc:  event.Data["ChannelStateDesc"],
-			}
-			result = append(result, channel)
-		}
-	}
-	lfshook.NewLogger().Infof("channels %+v", result)
-	return result, nil
-}
-
-// GetChannelByExten  通过 exten 查询对应通道
-func GetChannelByExten(exten string) (channel string, err error) {
-	lfshook.NewLogger().Infof("GetChannelByExten %s", exten)
-	_, events, err := AminInstance.Send(map[string]string{
-		"Action": "CoreShowChannels",
-	})
-	if err != nil {
-		lfshook.NewLogger().Errorf("core show channels error %+v", err)
-		return "", err
-	}
-
-	for _, event := range events {
-		lfshook.NewLogger().Infof("CoreShowChannels event Data %+v", event.Data)
-		if event.Data["Event"] == "CoreShowChannel" && event.Data["ConnectedLineNum"] == exten && event.Data["CallerIDNum"] != exten {
-			channel = event.Data["Channel"]
-			lfshook.NewLogger().Infof("GetChannelByExten get channel %s", channel)
-			break
-		}
-	}
-	if channel == "" {
-		lfshook.NewLogger().Errorf("not found channel %s", exten)
-		return "", errors.New("not found channel")
-	}
-
-	return channel, nil
-}
-
-// GetChannelByExten  通过 exten 查询对应通道
-func GetChannelByExtenNotBridged(exten string) (channel string, err error) {
-	lfshook.NewLogger().Infof("GetChannelByExten %s", exten)
-	_, events, err := AminInstance.Send(map[string]string{
-		"Action": "CoreShowChannels",
-	})
-
-	if err != nil {
-		lfshook.NewLogger().Errorf("core show channels error %+v", err)
-		return "", err
-	}
-
-	for _, event := range events {
-		//lfshook.NewLogger().Infof("CoreShowChannels event Data %+v", event.Data)
-		if event.Data["Event"] == "CoreShowChannel" && event.Data["CallerIDNum"] == exten {
-			channel = event.Data["Channel"]
-			lfshook.NewLogger().Infof("GetChannelByExten get channel %s", channel)
-			break
-		}
-	}
-	if channel == "" {
-		lfshook.NewLogger().Errorf("not found channel %s", exten)
-		return "", errors.New("not found channel")
-	}
-
-	return channel, nil
-}
-
-// GetBridgedChan  通过 exten 查询对应通道
-func GetExtenChan(exten string) (channel string, err error) {
-	lfshook.NewLogger().Infof("GetExtenChan %s", exten)
-	_, events, err := AminInstance.Send(map[string]string{
-		"Action": "CoreShowChannels",
-	})
-	if err != nil {
-		lfshook.NewLogger().Errorf("core show channels error %+v", err)
-		return "", err
-	}
-
-	for _, event := range events {
-		//	lfshook.NewLogger().Infof("CoreShowChannels event Data %+v", event.Data)
-		if event.Data["Event"] == "CoreShowChannel" && event.Data["ConnectedLineNum"] != exten && event.Data["CallerIDNum"] == exten {
-			channel = event.Data["Channel"]
-			lfshook.NewLogger().Infof("GetChannelByExten get channel %s", channel)
-			break
-		}
-	}
-	if channel == "" {
-		lfshook.NewLogger().Errorf("not found channel %s", exten)
-		return "", errors.New("not found channel")
-	}
-
-	return channel, nil
-}

Diferenças do arquivo suprimidas por serem muito extensas
+ 128 - 1398
internal/app/ami/action/index.go


+ 4 - 8
internal/app/ami/action/playback.go

@@ -14,18 +14,14 @@ func PlaybackPacu(filename string, count int, delay int, PaType string) (err err
 	Chan := ""
 
 	switch PaType {
-	case "STN":
+	case "DSN": //开关门提示
 		Chan = "Local/0503" //spa-rule
-	case "SPC":
+	case "STNA": //自动报站
 		Chan = "Local/0505" //spc-rule
-	case "DCS":
+	case "STNS": //手动报站
 		Chan = "Local/0504" //dc-rule
-	case "CHK":
-		Chan = "Local/0510" //paging pacu
-	case "EMG":
+	case "SVM": //服务消息
 		Chan = "Local/0502" //emg-rule
-	case "VOL":
-		Chan = "Local/0513" //emg-rule
 	}
 
 	action := map[string]string{

+ 0 - 36
internal/app/ami/model/cdr.go

@@ -1,36 +0,0 @@
-package model
-
-// Cdr 通话记录
-type Cdr struct {
-	AnswerTime         string `xorm:"AnswerTime"`
-	BillableSeconds    string `xorm:"BillableSeconds"`
-	CallerID           string `xorm:"CallerID"`
-	Channel            string `xorm:"Channel"`
-	Destination        string `xorm:"Destination"`
-	DestinationChannel string `xorm:"DestinationChannel"`
-	DestinationContext string `xorm:"DestinationContext"`
-	Disposition        string `xorm:"Disposition"`
-	Duration           string `xorm:"Duration"`
-	EndTime            string `xorm:"EndTime"`
-	Event              string `xorm:"Event"`
-	LastApplication    string `xorm:"LastApplication"`
-	LastData           string `xorm:"LastData"`
-	Privilege          string `xorm:"Privilege"`
-	RecordFile         string `xorm:"RecordFile"`
-	Source             string `xorm:"Source"`
-	StartTime          string `xorm:"StartTime"`
-	Timestamp          string `xorm:"Timestamp"`
-	UniqueID           string `xorm:"UniqueID"`
-}
-
-type RcdConf struct {
-	PadRcdEnable      string `json:"padRcdEnable"`
-	PadRcdStorageDays string `json:"padRcdStorageDays"`
-	PaRcdStorageDays  string `json:"paRcdStorageDays"`
-	CpaRcdStorageDays string `json:"cpaRcdStorageDays"`
-	OpaRcdStorageDays string `json:"opaRcdStorageDays"`
-	PadRcdDelDays     string `json:"pad_rcd_del_days"`
-	PaRcdDelDays      string `json:"pa_rcd_del_days"`
-	CpaRcdDelDays     string `json:"cpa_rcd_del_days"`
-	OpaRcdDelDays     string `json:"opa_rcd_del_days"`
-}

+ 0 - 40
internal/app/ami/model/dial.go

@@ -1,40 +0,0 @@
-package model
-
-type Dial struct {
-	Event                 string `json:"event"`
-	Channel               string `json:"channel"`
-	ChannelState          string `json:"channelState"`
-	ChannelStateDesc      string `json:"channelStateDesc"`
-	CallerIDNum           string `json:"callerIDNum"`
-	CallerIDName          string `json:"callerIDName"`
-	ConnectedLineNum      string `json:"connectedLineNum"`
-	ConnectedLineName     string `json:"connectedLineName"`
-	AccountCode           string `json:"accountCode"`
-	Context               string `json:"context"`
-	Exten                 string `json:"exten"`
-	Priority              string `json:"priority"`
-	Uniqueid              string `json:"uniqueid"`
-	Linkedid              string `json:"linkedid"`
-	DestChannel           string `json:"destChannel"`
-	DestChannelState      string `json:"destChannelState"`
-	DestChannelStateDesc  string `json:"destChannelStateDesc"`
-	DestCallerIDNum       string `json:"destCallerIDNum"`
-	DestCallerIDName      string `json:"destCallerIDName"`
-	DestConnectedLineNum  string `json:"destConnectedLineNum"`
-	DestConnectedLineName string `json:"destConnectedLineName"`
-	DestLanguage          string `json:"destLanguage"`
-	DestAccountCode       string `json:"destAccountCode"`
-	DestContext           string `json:"destContext"`
-	DestExten             string `json:"destExten"`
-	DestPriority          string `json:"destPriority"`
-	DestUniqueid          string `json:"destUniqueid"`
-	DestLinkedid          string `json:"destLinkedid"`
-	DialString            string `json:"dialString"`
-	Forward               string `json:"forward"`
-}
-
-type DialBeign Dial
-
-type DialEnd Dial
-
-type DialState Dial

+ 0 - 84
internal/app/ami/model/event.go

@@ -1,84 +0,0 @@
-package model
-
-import "strings"
-
-type PresenceStateChange struct {
-	Event      string `json:"event"`
-	Status     string `json:"status"`
-	Message    string `json:"message"`
-	Presentity string `json:"presentity"`
-	Extension  string `json:"extension"`
-	DndStatus  string `json:"dndStatus"`
-}
-
-type Hangup struct {
-	AccountCode       string `json:"accountCode"`
-	CallerIDName      string `json:"callerIDName"`
-	CallerIDNum       string `json:"callerIDNumber"`
-	Cause             string `json:"cause"`
-	Causetxt          string `json:"causetxt"`
-	Channel           string `json:"channel"`
-	ChannelState      string `json:"channelState"`
-	ChannelStateDesc  string `json:"channelStateDesc"`
-	ConnectedLineName string `json:"connectedLineName"`
-	ConnectedLineNum  string `json:"connectedLineNumber"`
-	Context           string `json:"context"`
-	Event             string `json:"event"`
-	Exten             string `json:"exten"`
-	Linkedid          string `json:"linkedid"`
-	Priority          string `json:"priority"`
-	Privilege         string `json:"privilege"`
-	Timestamp         string `json:"timestamp"`
-	Uniqueid          string `json:"uniqueid"`
-}
-
-type Newstate struct {
-	AccountCode       string `json:"accountCode"`
-	CallerIDName      string `json:"callerIDName"`
-	CallerIDNum       string `json:"callerIDNumber"`
-	Channel           string `json:"channel"`
-	ChannelState      string `json:"channelState"`
-	ChannelStateDesc  string `json:"channelStateDesc"`
-	ConnectedLineName string `json:"connectedLineName"`
-	ConnectedLineNum  string `json:"connectedLineNumber"`
-	Context           string `json:"context"`
-	Event             string `json:"event"`
-	Exten             string `json:"exten"`
-	Language          string `json:"language"`
-	Linkedid          string `json:"linkedid"`
-	Priority          string `json:"priority"`
-	Privilege         string `json:"privilege"`
-	Timestamp         string `json:"timestamp"`
-	Uniqueid          string `json:"uniqueid"`
-}
-
-type SuccessfulAuth struct {
-	Event         string `json:"event"`
-	AccountID     string `json:"accountID"`
-	RemoteAddress string `json:"remoteAddress"`
-	Address       string `json:"address"`
-}
-
-func (event *SuccessfulAuth) GetAddress() {
-	data := strings.Split(event.RemoteAddress, "/")
-	if len(data) == 4 {
-		event.Address = data[2]
-	} else {
-		event.Address = event.RemoteAddress
-	}
-}
-
-type MessageWaiting struct {
-	Event     string `json:"event"`
-	Extension string `json:"extension"`
-	New       string `json:"new"`
-	Old       string `json:"old"`
-	Mailbox   string `json:"mainbox"`
-}
-
-func (event *MessageWaiting) GetExtension() {
-	data := strings.Split(event.Mailbox, "@")
-	if len(data) == 2 {
-		event.Extension = data[0]
-	}
-}

+ 2 - 2
internal/app/ami/model/queue.go

@@ -1,6 +1,6 @@
 package model
 
-//QueueParams 队列参数
+// QueueParams 队列参数
 type QueueParams struct {
 	Queue            string         `json:"queue"`
 	Max              string         `json:"max"`
@@ -17,7 +17,7 @@ type QueueParams struct {
 	Entrys           []*QueueEntry  `json:"entrys"`
 }
 
-//QueueMember 队列成员
+// QueueMember 队列成员
 type QueueMember struct {
 	Queue          string `json:"queue"`
 	Name           string `json:"name"`

+ 1 - 1
internal/app/index.go

@@ -47,7 +47,7 @@ func StartApp() {
 	go stc.StartStcConnection(socket.Conn, "1")
 
 	// 启动带有重连机制的连接管理协程MC8
-	go stc.StartStcConnection(socket.Conn8, "8")
+	go stc.StartStcConnection(socket.Conn6, "6")
 
 	//启动连接到Master服务器,检查Master是否在线
 	//if active.CabNum == "1" {

+ 41 - 10
internal/app/stc/active/index.go

@@ -10,18 +10,12 @@ import (
 )
 
 // var ActiveCab string
-var CabNum string
-var ActivedCab = "1"
-var PADTimeout = 30
 var Master = false
-
-var ActivedCabDelay = "1"
-
-var TrainDevide = 0
-var RadioFault1 = 0
-var RadioFault8 = 0
-
+var CabNum = ""
 var TrainInfoMap = make(map[string]map[int]string)
+var TrainUnionID = 0
+var TrainUnionMaster = 0
+var TrainUnionMode = 0x00
 
 // 初始化所有列车号
 var TrainNumGr = []string{"TS1", "TS2", "TS3", "TS4", "TS5", "TS6", "TS7", "TS8", "TS9", "TS10", "TS11", "TS12", "TS13"}
@@ -155,3 +149,40 @@ func InitTrainInfoMap() {
 		}
 	}
 }
+
+func CheckReunoinMode() bool {
+	if TrainUnionMode == 1 && TrainUnionMaster == 1 { //尾--头,重联主车,6车服务器停用
+		if CabNum == "6" {
+			return false
+		}
+	} else if TrainUnionMode == 1 && TrainUnionMaster == 2 { //尾--头,重联从车,1车服务器停用
+		if CabNum == "1" {
+			return false
+		}
+	} else if TrainUnionMode == 2 && TrainUnionMaster == 1 { //尾--尾,重联主车,6车服务器停用
+		if CabNum == "6" {
+			return false
+		}
+	} else if TrainUnionMode == 2 && TrainUnionMaster == 2 { //尾--尾,重联从车,6车服务器停用
+		if CabNum == "6" {
+			return false
+		}
+	} else if TrainUnionMode == 3 && TrainUnionMaster == 1 { //头--头,重联主车,1车服务器停用
+		if CabNum == "1" {
+			return false
+		}
+	} else if TrainUnionMode == 3 && TrainUnionMaster == 2 { //头--头,重联从车,1车服务器停用
+		if CabNum == "1" {
+			return false
+		}
+	} else if TrainUnionMode == 4 && TrainUnionMaster == 1 { //头--尾,重联主车,1车服务器停用
+		if CabNum == "1" {
+			return false
+		}
+	} else if TrainUnionMode == 4 && TrainUnionMaster == 2 { //头--尾,重联从车,6车服务器停用
+		if CabNum == "6" {
+			return false
+		}
+	}
+	return true
+}

+ 130 - 754
internal/app/stc/broadcast/stc-broadcast.go

@@ -3,21 +3,16 @@ package broadcast
 import (
 	"bytes"
 	"context"
-	"encoding/binary"
 	"fmt"
 	"io"
 	"net"
-	"os/exec"
 	"pbx-api-gin/internal/app/ami/action"
 	"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"
 	"pbx-api-gin/pkg/utils"
 	"strconv"
-	"sync"
-	"syscall"
 	"time"
 )
 
@@ -63,80 +58,6 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
 	}
 }
 
-// get train info and pacu info from heartbeat
-func getInfofromSTC(info []byte) {
-	//dataCount := info[0]
-	//Get train info
-	value := binary.BigEndian.Uint16(info[2:4]) //info[2] +  info[3] 列车号数据
-	//value := 3
-	active.TrainNum = "TS" + strconv.Itoa(int(value))
-
-	lfshook.NewLogger().Logger.Infof("TrainNum: %s", active.TrainNum)
-
-	//Get ICP volume
-	icpBit8 := info[9] & 0xF
-	icpBit1 := (info[9] >> 4) & 0xF
-	icpVol1 := 0
-	icpVol8 := 0
-
-	if icpBit1 == 0xe {
-		icpVol1 = 100
-	} else {
-		icpVol1 = int(icpBit1) * 7
-	}
-
-	if icpBit8 == 0xe {
-		icpVol8 = 100
-	} else {
-		icpVol8 = int(icpBit8) * 7
-	}
-
-	active.DeviceEndpoint.ICPInfo[0].Volume = fmt.Sprintf("%d", icpVol1)
-	active.DeviceEndpoint.ICPInfo[0].ID = "1"
-	active.DeviceEndpoint.ICPInfo[1].Volume = fmt.Sprintf("%d", icpVol8)
-	active.DeviceEndpoint.ICPInfo[1].ID = "8"
-
-	//Get Pacu info
-	eidsStat := info[1] //PACU mute
-	pacuStat := info[4] //PACU status
-
-	pacuVolume := binary.BigEndian.Uint32(info[5:9]) //info[5]-info[8]
-
-	//lfshook.NewLogger().Logger.Infof("=====pacuVolume====info[5:9]=======%x", info[5:9])
-	//lfshook.NewLogger().Logger.Infof("=====pacuStatus====info[4]=======%x", info[4])
-	for i := 0; i < 8; i++ {
-		eidsBit := (eidsStat >> i) & 0x01 // 右移 i 位,再与 1 取最低位
-		//fmt.Printf("eidsBit bit %d = %d\n", i, eidsBit) // bit 0 是 LSB(最低位,最右)
-
-		//get 1 bit every time
-		pacuStatBit := (pacuStat >> i) & 0x01
-		//fmt.Printf("pacuStatBit bit %d = %d\n", i, pacuStatBit)
-
-		//get 4 bit every time
-		//var pacuVolBit byte
-		pacuVolBit := (pacuVolume >> (i * 4)) & 0x0000000F
-		//fmt.Printf("pacuVolBit bit %d = %x\n", i, pacuVolBit)
-
-		active.DeviceEndpoint.PacuInfo[i].ID = strconv.Itoa(i + 1)
-		if eidsBit == 1 {
-			active.DeviceEndpoint.PacuInfo[i].Mute = true
-		} else {
-			active.DeviceEndpoint.PacuInfo[i].Mute = false
-		}
-		if pacuStatBit == 0 {
-			active.DeviceEndpoint.PacuInfo[i].Status = "normal"
-		} else {
-			active.DeviceEndpoint.PacuInfo[i].Status = "abnormal"
-		}
-		if int(pacuVolBit) == 14 {
-			active.DeviceEndpoint.PacuInfo[i].Volume = "100"
-		} else {
-			active.DeviceEndpoint.PacuInfo[i].Volume = strconv.Itoa(int(pacuVolBit) * 7)
-		}
-		//lfshook.NewLogger().Logger.Infof("PACU INFO===ID:%s===Mute:%+v===Stat:%s===Vol:%s", active.DeviceEndpoint.PacuInfo[i].ID, active.DeviceEndpoint.PacuInfo[i].Mute, active.DeviceEndpoint.PacuInfo[i].Status, active.DeviceEndpoint.PacuInfo[i].Volume)
-	}
-}
-
 // 处理单个数据包(原 switch 逻辑迁移过来)
 func processPacket(packet []byte) {
 
@@ -146,14 +67,53 @@ func processPacket(packet []byte) {
 	}
 
 	//for recv data log debug
-	if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
+	if packet[5] != 0x0b && packet[5] != 0x09 {
 		utils.LoggerDebug.Printf("Get data from STC:%x", packet)
 	}
 
-	//check if the cmd type is avtive
-	if packet[5] == 0x03 { // ACTIVE
-		Active([3]byte{packet[8], packet[9], packet[10]})
-		return
+	//重联模式判断
+	if packet[5] == 0x0b {
+		active.TrainUnionID = int(packet[8])
+		active.TrainUnionMaster = int(packet[9])
+		active.TrainUnionMode = int(packet[10])
+
+		if active.TrainUnionID != 0 {
+			utils.LoggerDebug.Printf("active.TrainUnionID:%x  active.TrainUnionMaster:%x  active.TrainUnionMode:%x ", active.TrainUnionID, active.TrainUnionMaster, active.TrainUnionMode)
+		}
+
+		if active.TrainUnionMode == 1 && active.TrainUnionMaster == 1 { //尾--头,重联主车,6车服务器停用
+			if active.CabNum == "6" {
+				return
+			}
+		} else if active.TrainUnionMode == 1 && active.TrainUnionMaster == 2 { //尾--头,重联从车,1车服务器停用
+			if active.CabNum == "1" {
+				return
+			}
+		} else if active.TrainUnionMode == 2 && active.TrainUnionMaster == 1 { //尾--尾,重联主车,6车服务器停用
+			if active.CabNum == "6" {
+				return
+			}
+		} else if active.TrainUnionMode == 2 && active.TrainUnionMaster == 2 { //尾--尾,重联从车,6车服务器停用
+			if active.CabNum == "6" {
+				return
+			}
+		} else if active.TrainUnionMode == 3 && active.TrainUnionMaster == 1 { //头--头,重联主车,1车服务器停用
+			if active.CabNum == "1" {
+				return
+			}
+		} else if active.TrainUnionMode == 3 && active.TrainUnionMaster == 2 { //头--头,重联从车,1车服务器停用
+			if active.CabNum == "1" {
+				return
+			}
+		} else if active.TrainUnionMode == 4 && active.TrainUnionMaster == 1 { //头--尾,重联主车,1车服务器停用
+			if active.CabNum == "1" {
+				return
+			}
+		} else if active.TrainUnionMode == 4 && active.TrainUnionMaster == 2 { //头--尾,重联从车,6车服务器停用
+			if active.CabNum == "6" {
+				return
+			}
+		}
 	}
 
 	//check if Master role
@@ -167,499 +127,116 @@ func processPacket(packet []byte) {
 	tagLog = 0
 
 	switch packet[5] {
-	case 0x01: //heartbeat
+	case 0x01: //心跳
 		return
 
-	case 0x02: // STN
-		if active.ActivedCab != "" {
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("STN")
-
-			if priority.CheckPriority("STN") {
-
-				runningTaskName := action.InterruptRunningTask("STN") //STN interrupt other
-				if runningTaskName != "" {
-					time.Sleep(time.Millisecond * 100) //wait endpoint release
-				}
-				StationAnn(packet)
-			} else {
-				if priority.TaskCreating == "STN" {
-					utils.LoggerDebug.Printf("STN : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "STN", "refuse")
-			}
-		}
-
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "STN" {
-			utils.LoggerDebug.Printf("STN : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
-		}
-
-	case 0x05: // SPC
-		if active.ActivedCab != "" {
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("SPC")
-
-			if priority.CheckPriority("SPC") {
-
-				runningTaskName := action.InterruptRunningTask("SPC") //SPC interrupt other
-				if runningTaskName != "" {
-					time.Sleep(time.Millisecond * 100) //wait endpoint release
-				}
-				SpecialAnn(packet)
-			} else {
-				if priority.TaskCreating == "SPC" {
-					utils.LoggerDebug.Printf("SPC : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "SPC", "refuse")
-			}
-		}
+	case 0x02: // 自动报站
 
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "SPC" {
-			utils.LoggerDebug.Printf("SPC : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
+		if priority.CheckPriority("STNA") {
+			action.HangupTask()
+			StationAnnAuto(packet[8:])
+		} else {
+			alstatus.PaStatus("", "STNA", "refuse")
 		}
 
-	case 0x06: // EMG
-
-		if active.ActivedCab != "" {
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("EMG")
-
-			if priority.CheckPriority("EMG") {
-
-				runningTaskName := action.InterruptRunningTask("EMG") //EMG interrupt other
-				if runningTaskName != "" {
-					time.Sleep(time.Millisecond * 100) //wait endpoint release
-				}
-				EmgMsg(packet)
-			} else {
-				if priority.TaskCreating == "EMG" {
-					utils.LoggerDebug.Printf("EMG : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "EMG", "refuse")
-			}
+	case 0x03: // 手动报站
+		if priority.CheckPriority("STNS") {
+			action.HangupTask()
+			StationAnnAuto(packet[8:])
+		} else {
+			alstatus.PaStatus("", "STNS", "refuse")
 		}
 
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "EMG" {
-			utils.LoggerDebug.Printf("EMG : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
+	case 0x04: // 手动服务消息、紧急广播
+		if priority.CheckPriority("SVM") {
+			action.HangupTask()
+			EmgMsg(packet[8:])
+		} else {
+			alstatus.PaStatus("", "SVM", "refuse")
 		}
 
-	case 0x07: // STOP
+	case 0x05: // STOP
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
 
-	case 0x08: // DCS
-
-		if active.ActivedCab != "" {
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("DCS")
-
-			if priority.CheckPriority("DCS") {
-
-				runningTaskName := action.InterruptRunningTask("DCS") //DCS interrupt other
-				if runningTaskName != "" {
-					time.Sleep(time.Millisecond * 100) //wait endpoint release
-				}
-				DcsAnn(packet)
-			} else {
-				if priority.TaskCreating == "DCS" {
-					utils.LoggerDebug.Printf("DCS : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "DCS", "refuse")
-			}
-
-			time.Sleep(1 * time.Second)
-			if priority.TaskCreating == "DCS" {
-				utils.LoggerDebug.Printf("DCS : Clean priority.TaskCreating = '' !")
-				priority.TaskCreating = ""
-			}
-		}
-
-	case 0x09: // SELF CHECK
-
-		if active.ActivedCab != "" {
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("CHK")
-
-			if priority.CheckPriority("CHK") {
-
-				runningTaskName := action.InterruptRunningTask("CHK") //CHK interrupt other
-				if runningTaskName != "" {
-					time.Sleep(time.Millisecond * 100) //wait endpoint release
-				}
-				SelfCheck(packet)
-			} else {
-				if priority.TaskCreating == "CHK" {
-					utils.LoggerDebug.Printf("CHK : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "CHK", "refuse")
-			}
-		}
-
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "CHK" {
-			utils.LoggerDebug.Printf("CHK : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
-		}
-
-	case 0x0a: // Tone-test
-		if active.ActivedCab != "" {
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("VOL")
-
-			if priority.CheckPriority("VOL") {
-
-				runningTaskName := action.InterruptRunningTask("VOL") //VOL interrupt other
-				if runningTaskName != "" {
-					time.Sleep(time.Millisecond * 100) //wait endpoint release
-				}
-				ToneTest(packet)
-			} else {
-				if priority.TaskCreating == "VOL" {
-					utils.LoggerDebug.Printf("VOL : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "VOL", "refuse")
-			}
-		}
-
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "VOL" {
-			utils.LoggerDebug.Printf("VOL : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
-		}
-
-	case 0x0e: //TMS answer PAD
-
-		handler := packet[8]
-
-		//Drop other handler in 2 sec
-		//PACUs---call---->ICP1
-		//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
-		if handler == 0x01 { //answer PAD
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("PAD-TMS")
-
-			//if packet[8] == 0x01 { //answer PAD
-			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
-				}
-				//}
-
-				if active.QueueTimer != nil {
-					if active.QueueTimer.Stop() {
-						utils.LoggerDebug.Printf("Stop PAD timer true !")
-					} else {
-						utils.LoggerDebug.Printf("Stop PAD timer false !")
-					}
-				}
-
-				AlarmHandleTMS(packet)
-			} else {
-				if priority.TaskCreating == "PAD-TMS" {
-					utils.LoggerDebug.Printf("PAD-TMS : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "PAD-TMS", "refuse")
-			}
-		} else { //hangup + hold
-			AlarmHandleTMS(packet)
-		}
-
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "PAD-TMS" {
-			utils.LoggerDebug.Printf("PAD-TMS : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
-		}
-
-	case 0x0b: // reset all PAD
-		AlarmHoldResetAll(packet[8]) // reset all pad
-
-	case 0x0c: // Set PAD timeout
-		//lfshook.NewLogger().Logger.Infof("==type PADTimeout 0x0c===Get data from STC ====%x", packet)
-		PadTimeOutSetting(packet[8:]) // timeout setting
-
-		getInfofromSTC(packet[8:])
+	//case 0x06: // 关门提示(预留)
+	//DoorStatusNotice(packet[8:])
+	//case 0x07: // 司机室位置(预留)
 
-	case 0x0d: // ICP answer PAD
+	case 0x08: // EED报警
+		EEDAlarm(packet[8:])
+		//case 0x09: // 列车运行模式(预留)
+		//	RuningStatus(packet[8:])
 
-		handler := packet[8]
+		//case 0x0a:(预留)
 
-		//Drop other handler in 2 sec
-		//PACUs---call---->ICP1
-		//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
-		if handler == 0x01 {
-
-			//检查是否有任务正在创建
-			action.WaitTaskCreate("PAD-ICP")
-
-			//if packet[8] == 0x01 { //answer PAD
-			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
-				}
-				//}
-
-				if active.QueueTimer != nil {
-					utils.LoggerDebug.Printf("PAD Timeout timer != nil !")
-					if active.QueueTimer.Stop() {
-						utils.LoggerDebug.Printf("Stop PAD timer true !")
-					} else {
-						utils.LoggerDebug.Printf("Stop PAD timer false !")
-					}
-				}
-
-				AlarmHandleICP(packet)
-			} else {
-				if priority.TaskCreating == "PAD-ICP" {
-					utils.LoggerDebug.Printf("PAD-ICP : Clean priority.TaskCreating = '' !")
-					priority.TaskCreating = ""
-				}
-				alstatus.PaStatus("", "PAD-ICP", "refuse")
-			}
-		} else { //hangup + hold
-			AlarmHandleICP(packet)
-		}
-
-		time.Sleep(1 * time.Second)
-		if priority.TaskCreating == "PAD-ICP" {
-			utils.LoggerDebug.Printf("PAD-ICP : Clean priority.TaskCreating = '' !")
-			priority.TaskCreating = ""
-		}
-
-		/*case 0x11: //Set remote master
-		if packet[8] == 1 {
-			utils.LoggerDebug.Printf("TMS respond, Stop PAD timeout %d sec .", active.PADTimeout)
-			if active.QueueTimer != nil {
-				if active.QueueTimer.Stop() {
-					utils.LoggerDebug.Printf("Stop PAD timer true !")
-				} else {
-					utils.LoggerDebug.Printf("Stop PAD timer false !")
-				}
-			}
-		} else {
-			utils.LoggerDebug.Printf("TMS respond canceled, set PAD timeout %d sec .", active.PADTimeout)
-			active.QueueTimer = time.AfterFunc(time.Duration(active.PADTimeout)*time.Second, func() { // check the PAD 30s timeout
-
-				res, err := action.QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
-				if err != nil {
-					lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
-					return
-				}
-				if res == nil {
-					return
-				}
-
-				if res.Calls == "0" { // OCC queue empty
-					priority.ICPAnswer = 0
-					for _, ret := range alstatus.PadQueues {
-						//order by pos
-						action.RedirectInQueue(ret.Exten, "0301", "queues-occ", ret.Exten) // redirect All ICP-PAD redirect to OCC queue
-						time.Sleep(time.Millisecond * 100)
-					}
-				}
-			})
-		}*/
-		//default:
-		//fmt.Printf("Unknown command: %x\n", packet[5])
+		//case 0x0b: // 重联方式
+		//	active.TrainUnionMode = int(packet[9])
 	}
 }
 
-func PadTimeOutSetting(data []byte) {
-
-	Seconds := data[0]
-	if Seconds != 0 {
-		active.PADTimeout = int(Seconds)
-		//lfshook.NewLogger().Logger.Infof("=========Set PAD Timeout seconds to %d ! ============", active.PADTimeout)
-	}
+// EED报警,激活报警器到队列
+func EEDAlarm(data []byte) {
+	cab := data[0]
+	pos := data[1]
 
+	alarm := fmt.Sprintf("7%02d%d", cab, pos)
+	//utils.LoggerDebug.Printf("Type:STN	FileName:%x	Count:%x	SpecialVoice:%+v	Interval:%+v", filename, cycleCount, specialVoice, delay)
+	action.Dial(alarm, "0300", "queues", "", "")
 }
 
-// STN , 自动报站广播
-func StationAnn(data []byte) (err error) {
-
-	specialVoice := int(data[8])
-	delay := data[9]
-	cycleCount := data[10]
-	datalen := int(data[11])
+// DSN ,开关门提示
+func DoorStatusNotice(data []byte) (err error) {
 
-	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
+	delay := data[0]
+	cycleCount := data[1]
+	FileLen := int(data[2])
+	filename := msgdata.SubstrByRune(string(data[3:]), 0, int(FileLen)-4)
 
-	//set spc voice tag
-	priority.SpecialVoice = specialVoice
+	//utils.LoggerDebug.Printf("Type:STN	FileName:%x	Count:%x	SpecialVoice:%+v	Interval:%+v", filename, cycleCount, specialVoice, delay)
 
-	utils.LoggerDebug.Printf("Type:STN	FileName:%x	Count:%x	SpecialVoice:%+v	Interval:%+v", filename, cycleCount, specialVoice, delay)
-
-	action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "STN")
+	action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
 	return nil
 }
 
-// 激活信号
-func Active(data [3]byte) {
-
-	//var info model.Sysinfo
-	Signal := int(data[0])
-	master := int(data[1])
-	TrainInfo := int(data[2])
+// APA , 自动报站广播
+func StationAnnAuto(data []byte) (err error) {
 
-	lfshook.NewLogger().Logger.Infof("=====active:%x======cab=%s Master=%d=====data:%x======ActivedCabDelay:%x", Signal, active.CabNum, master, data, active.ActivedCabDelay)
+	//StationStatus := int(data[0])
+	filelen := data[1]
+	filename := msgdata.SubstrByRune(string(data[2:]), 0, int(filelen)-4)
 
-	//Set Master
-	if master == 1 && active.CabNum == "1" {
-
-		active.Master = true
-		if !utils.CheckAsterisk() {
-			lfshook.NewLogger().Infof("Check asterisk , if not running , run cmd service asterisk start !")
-			cmd := exec.Command("service", "asterisk", "start")
-			cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
-			err := cmd.Run()
-			if err != nil {
-				lfshook.NewLogger().Infof("Failed to start asterisk: %v", err)
-				return
-			}
-		}
-	} else if master == 8 && active.CabNum == "8" {
-
-		active.Master = true
-		if !utils.CheckAsterisk() {
-			lfshook.NewLogger().Infof("Check asterisk , if not running , run cmd service asterisk start !")
-			cmd := exec.Command("service", "asterisk", "start")
-			cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
-			err := cmd.Run()
-			if err != nil {
-				lfshook.NewLogger().Infof("Failed to start asterisk: %v", err)
-				return
-			}
-		}
-	} else if master == 8 && active.CabNum == "1" {
-
-		if utils.CheckAsterisk() {
-			lfshook.NewLogger().Infof("Check asterisk , if running slave, run cmd service asterisk stop !")
-			cmd := exec.Command("service", "asterisk", "stop")
-			cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
-			err := cmd.Run()
-			if err != nil {
-				lfshook.NewLogger().Infof("Failed to stop asterisk: %v", err)
-				return
-			}
-		}
-	} else if master == 1 && active.CabNum == "8" {
-		active.Master = false
-	}
-
-	//Set train info
-	if TrainInfo != 0 {
-		//Get train devide info
-		DevideInfo := TrainInfo & 0x20
-		if DevideInfo == 0x20 {
-			active.TrainDevide = 1
-
-			active.Master = true //列车断开,设置两边都Master
-			if !utils.CheckAsterisk() {
-				lfshook.NewLogger().Infof("Check asterisk , if not running , run cmd service asterisk start !")
-				cmd := exec.Command("service", "asterisk", "start")
-				cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
-				err := cmd.Run()
-				if err != nil {
-					lfshook.NewLogger().Infof("Failed to start asterisk: %v", err)
-					return
-				}
-			}
-		} else {
-			active.TrainDevide = 0
-		}
-
-		//Radio fault
-		active.RadioFault1 = TrainInfo & 0x03
-		active.RadioFault8 = TrainInfo & 0x0c
-		//if RadioFault1 == 2 || RadioFault8 == 2 {
-		//	active.RadioFault = 1
-		//} else {
-		//	active.RadioFault = 0
-		//}
-		//utils.LoggerDebug.Printf("RadioFault1:%x 	RadioFault8:%x		DevideInfo:%x", active.RadioFault1, active.RadioFault8, DevideInfo)
-
-	}
-
-	switch Signal {
-	case 0:
-
-		if active.ActivedCab != "" {
-			active.ActivedCab = ""
-			action.InActiveHangup()
-		}
-
-	case 1:
-		//active signal from 8 to 1
-		if active.ActivedCab == "8" || active.ActivedCab == "" {
-			active.ActivedCab = "1"
-			active.ActivedCabDelay = "1"
-
-			action.InActiveHangup()
-		}
+	//utils.LoggerDebug.Printf("Type:STN	FileName:%x	Count:%x	SpecialVoice:%+v	Interval:%+v", filename, cycleCount, specialVoice, delay)
 
-	case 8:
-		//active signal from 1 to 8
-		if active.ActivedCab == "1" || active.ActivedCab == "" {
-			active.ActivedCab = "8"
-			active.ActivedCabDelay = "8"
-
-			action.InActiveHangup()
-		}
-
-	}
+	action.PlaybackPacu(strconv.Quote(filename), 1, 0, "STNA")
+	return nil
 }
 
-// SPC ,特殊服务消息广播
-func SpecialAnn(data []byte) {
+// SPA , 手动报站广播
+func StationAnnManu(data []byte) (err error) {
 
-	delay := data[8]
-	cycleCount := data[9]
-	datalen := int(data[10])
+	//StationStatus := int(data[0])
+	filelen := data[1]
+	filename := msgdata.SubstrByRune(string(data[2:]), 0, int(filelen)-4)
 
-	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
+	//utils.LoggerDebug.Printf("Type:STN	FileName:%x	Count:%x	SpecialVoice:%+v	Interval:%+v", filename, cycleCount, specialVoice, delay)
 
-	utils.LoggerDebug.Printf("Type:SPC	FileName:%x	Count:%x	Interval:%+v", filename, cycleCount, delay)
-	if int(cycleCount) == 255 {
-		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
-	} else {
-		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SPC")
-	}
+	action.PlaybackPacu(strconv.Quote(filename), 1, 0, "STNS")
+	return nil
 }
 
 // EMG ,紧急服务消息广播
 func EmgMsg(data []byte) {
-	delay := data[8]
-	cycleCount := data[9]
-	datalen := int(data[10])
+	delay := data[0]
+	cycleCount := data[1]
+	filelen := int(data[2])
 
-	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
+	filename := msgdata.SubstrByRune(string(data[3:]), 0, filelen-4)
 
 	utils.LoggerDebug.Printf("Type:EMG	FileName:%x	Count:%x	Interval:%+v", filename, cycleCount, delay)
 	if int(cycleCount) == 255 {
-		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
+		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SVM")
 	} else {
-		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
+		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SVM")
 	}
 }
 
@@ -667,232 +244,31 @@ func EmgMsg(data []byte) {
 func AnnStop(data [4]byte) {
 
 	//lfshook.NewLogger().Logger.Infof("=========AnnStop Type  %x", data[0])
-	utils.LoggerDebug.Printf("Stop PA Type:%x (DCS=3,EMG=4,SPC=7,STN=8,SelfCheck=9,ToneTest=10)", data[0])
+	utils.LoggerDebug.Printf("Stop PA Type:%x (自动报站=1,手动报站=2,服务信息=3)", data[0])
 
 	switch data[0] {
-	case 0x03:
-
-		action.HangupTask("DCS")           //STOP DCS
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	case 0x04:
-
-		action.HangupTask("EMG")           //STOP EMG
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	case 0x07:
-
-		action.HangupTask("SPC")           //STOP SPC
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	case 0x08:
-
-		action.HangupTask("STN")           //STOP STN
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	case 0x09:
-
-		action.HangupTask("CHK")           //STOP CHK
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	case 0x0a:
-
-		action.HangupTask("VOL")           //STOP VOL
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	default:
-		action.InterruptRunningTask("")
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-	}
-}
-
-// DCS 语音
-func DcsAnn(data []byte) {
-	delay := data[8]
-	cycleCount := data[9]
-	datalen := int(data[10])
-
-	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
-
-	utils.LoggerDebug.Printf("Type:DCS	FileName:%x	Count:%x	Interval:%+v", filename, cycleCount, delay)
-	if int(cycleCount) == 255 {
-		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
-	} else {
-		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
-	}
-}
-
-// tone-test广播
-func ToneTest(data []byte) {
-
-	check := data[8]
-	delay := data[9]
-	cycleCount := data[10]
-	datalen := int(data[11])
-
-	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
-
-	utils.LoggerDebug.Printf("Type:ToneTest	FileName:%x	 Count:%x	Interval:%+v	Action:%x (0x01=start/0x02=stop)", filename, cycleCount, delay, check)
-	switch check {
-	case 0x01: //start
-		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
-
-	case 0x02: //stop
-		action.HangupAllExcept("")
-	}
-}
-
-// 自检广播
-func SelfCheck(data []byte) {
-
-	check := data[8]
-	delay := data[9]
-	cycleCount := data[10]
-	//cycleCount := 0x32
-	datalen := int(data[11])
-
-	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
-
-	utils.LoggerDebug.Printf("Type:SelfCehck	FileName:%x	 Count:%x	Interval:%+v	Action:%x (0x01=start/0x02=stop)", filename, cycleCount, delay, check)
-	switch check {
-	case 0x01: //start
-
-		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
-	case 0x02: //stop
-		action.HangupAllExcept("")
-	}
-}
-
-// 全局变量:记录正在抑制的 exten
-var (
-	suppressedExts = sync.Map{} // map[string]struct{},值存在即表示被抑制
-	//suppressionMu  sync.Mutex   // 保护初始化和清理操作(可选)
-)
-
-// suppressKey 生成用于抑制的 key(可以根据需求扩展)
-func suppressKey(exten string, handler byte) string {
-	return fmt.Sprintf("%s_h%x", exten, handler)
-}
-
-// ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
-func AlarmHandleICP(data []byte) {
-	handler := data[8]
-	carr := data[12]
-	pos := data[13]
-	exten := fmt.Sprintf("24%c%c", carr, pos)
-
-	utils.LoggerDebug.Printf("ICP Handle PAD:%s	Action:%x (answer=1,hold=2,hangup=3)", exten, handler)
-	switch handler {
-	case 0x01: //answer(ICP+Alarm+PACU)
-		//NotifyPaiu(exten, "answer")
-		priority.ICPAnswer = 1
-		//if priority.PADStart == 0 {
-		//alstatus.PaStatus("", "PAD", "start")
-		priority.InterruptedPad = ""
-		//	priority.PADStart = 1
-		//}
-		utils.LoggerDebug.Printf("ICP Answer PAD:%s .", exten)
-
-		if active.ActivedCab == "1" {
-			action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
-			//goto ami event ConfbridgeJoin, ICP answer PAD
-		} else if active.ActivedCab == "8" {
-			action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
-			//goto ami event ConfbridgeJoin, ICP answer PAD
-		} else if active.ActivedCab == "" { // No cab occupied
-			if active.ActivedCabDelay == "1" {
-				action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
-			} else if active.ActivedCabDelay == "8" {
-				action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
-			} else {
-				action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
-			}
-		}
-
-	case 0x02: //hold  重新放回队列里面
-		utils.LoggerDebug.Printf("ICP Hold PAD-ICP PAD:%s !", exten)
-		active.NotifyPaiu(exten, "hold")
-		err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
-		if err != nil {
-			utils.LoggerDebug.Printf("RedirectInQueue err:%+v", err)
+	case 0x01: //停止自动广播(自动报站)
+		taskInfo, ok := priority.RegistryTask.Get("STNA")
+		if ok {
+			action.ConfbridgeKick(taskInfo.ConfbridgeID, "all")
+			action.Hangup(taskInfo.RunChannel)
 		}
-		action.InterruptRunningTask("")
-		time.Sleep(time.Millisecond * 100) //wait endpoint release
-		//action.HangupICP()
-
-	case 0x03: //hangup
-		//NotifyPaiu(exten, "hangup")
-		utils.LoggerDebug.Printf("STC Hangup PAD-ICP !")
-		action.Hangup(exten) //Pad
-		//action.HangupICP()
-
-		action.HangupTask("PAD-ICP")
-
-	}
-}
+		time.Sleep(time.Millisecond * 100)
 
-// TMS操作乘客报警(根据激活信息判断转到1车还是8车================)
-func AlarmHandleTMS(data []byte) {
-	handler := data[8]
-	//extlen := data[9]
-	carr := data[12]
-	pos := data[13]
-	exten := fmt.Sprintf("24%c%c", carr, pos)
-	PacuNum := fmt.Sprintf("21%c1", carr)
-
-	utils.LoggerDebug.Printf("TMS Handle PAD:%s	PACU:%s	Action:%x (answer=1,hold=2,hangup=3)", exten, PacuNum, handler)
-
-	switch handler {
-	case 0x01: //answer(ICP+Alarm+PACU)
-		//PACU---call---->ICP1
-		//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
-		//if priority.PADStart == 0 {
-		//alstatus.PaStatus("", "PAD", "start")
-		priority.InterruptedPad = ""
-		//priority.PADStart = 1
-		//}
-		priority.ICPAnswer = 1
-		utils.LoggerDebug.Printf("TMS Answer PAD:%s 	PACU:%s", exten, PacuNum)
-
-		if action.ExtenStatus(PacuNum) == "Idle" {
-			if active.ActivedCab == "1" {
-				action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "1") // PACU dial ICP1
-				//goto ami event BridgeEnter, ICP8 whisper ICP1
-			} else if active.ActivedCab == "8" {
-				action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "8") // PACU dial ICP8
-				//goto ami event BridgeEnter, ICP1 whisper ICP8
-			} else if active.ActivedCab == "" { // No cab occupied
-				if active.ActivedCabDelay == "1" {
-					action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "1") // PACU dial ICP1
-				} else if active.ActivedCabDelay == "8" {
-					action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "8") // PACU dial ICP8
-				} else {
-					action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "1") // PACU dial ICP1
-				}
-			}
-		} else {
-			action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
+	case 0x02: //停止半自动广播(手动报站)
+		taskInfo, ok := priority.RegistryTask.Get("STNS")
+		if ok {
+			action.ConfbridgeKick(taskInfo.ConfbridgeID, "all")
+			action.Hangup(taskInfo.RunChannel)
 		}
+		time.Sleep(time.Millisecond * 100)
 
-	case 0x02: //hold  重新放回队列里面
-		utils.LoggerDebug.Printf("ICP Hold PAD-TMS PAD:%s !", exten)
-		active.NotifyPaiu(exten, "hold")
-		err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
-		if err != nil {
-			utils.LoggerDebug.Printf("RedirectInQueue err:%+v", err)
+	case 0x03: //停止服务信息广播(紧急广播)
+		taskInfo, ok := priority.RegistryTask.Get("SVM")
+		if ok {
+			action.ConfbridgeKick(taskInfo.ConfbridgeID, "all")
+			action.Hangup(taskInfo.RunChannel)
 		}
-		action.HangupAllLocalChan()
-
-	case 0x03: //hangup
-		//NotifyPaiu(exten, "hangup")
-		utils.LoggerDebug.Printf("STC Hangup PAD-TMS !")
-		action.Hangup(exten) //Pad
-		action.HangupTask("PAD-TMS")
-		//action.HangupTask("PAD-ICP")
+		time.Sleep(time.Millisecond * 100)
 	}
 }
-
-// 挂断所有报警器
-func AlarmHoldResetAll(handler byte) {
-	utils.LoggerDebug.Printf("Alarm Hold/Reset All !")
-	//hangup all actived PAD
-	action.HangupAllPAD()
-
-	//hangup running task
-	action.InterruptRunningTask("AlarmHoldResetAll") //Reset PAD ALL
-	time.Sleep(time.Millisecond * 100)               //wait endpoint release
-}

+ 79 - 28
internal/app/stc/index.go

@@ -33,7 +33,7 @@ func StartStcConnection(conn net.Conn, cab string) {
 		}
 
 		//set connection log
-		trainInfo := fmt.Sprintf("CabNumber %s", active.ActivedCab)
+		trainInfo := fmt.Sprintf("CabNumber")
 		if logTag == 0 {
 			utils.Logger.Printf("Train Information: %s, Message: Connection to Cab%s STC is up !", trainInfo, cab)
 			utils.LoggerDebug.Printf("Connection to Cab%s STC1 is up !", cab)
@@ -45,7 +45,7 @@ func StartStcConnection(conn net.Conn, cab string) {
 		if cab == "1" {
 			socket.Conn = conn1
 		} else {
-			socket.Conn8 = conn1
+			socket.Conn6 = conn1
 		}
 		connMux.Unlock()
 
@@ -102,7 +102,7 @@ func CreateConnection(RemoteCab string) (net.Conn, error) {
 			dialer := &net.Dialer{
 				LocalAddr: &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: socket.LocalPort}, // 固定本地端口
 				Control:   controlTCPConn,
-				Timeout:   5 * time.Second,
+				Timeout:   2 * time.Second,
 			}
 
 			DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr, socket.RemotePort)
@@ -115,55 +115,106 @@ func CreateConnection(RemoteCab string) (net.Conn, error) {
 			return conn, nil
 		} else { //in cab 8
 			dialer := &net.Dialer{
-				LocalAddr: &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: socket.LocalPort8}, // 固定本地端口
+				LocalAddr: &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: socket.LocalPort6}, // 固定本地端口
 				Control:   controlTCPConn,
-				Timeout:   5 * time.Second,
+				Timeout:   2 * time.Second,
 			}
 
-			DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr, socket.RemotePort)
-			conn, err := dialer.Dial("tcp", DialAddr)
-			if err != nil {
-				//lfshook.NewLogger().Logger.Infof("========Connect server err :%+v", err)
-				return nil, err
+			//6车socket链接1车,单列+重联1+重联2
+			if active.TrainUnionID == 0 { //单列模式下
+
+				DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr, socket.RemotePort)
+				conn, err := dialer.Dial("tcp", DialAddr)
+				if err != nil {
+					utils.LoggerDebug.Printf("Connect to Cab1 Local faild  ! ")
+					return nil, err
+				}
+				utils.LoggerDebug.Printf("Connect success PIS1:%s:%d from Cab6 !", socket.RemoteAddr, socket.RemotePort)
+				return conn, nil
+
+			} else if active.TrainUnionID == 1 { //重联模式ETBN=1
+
+				DialAddr := fmt.Sprintf("%s:%d", socket.Re1RemoteAddr, socket.RemotePort)
+				conn, err := dialer.Dial("tcp", DialAddr)
+				if err != nil {
+					utils.LoggerDebug.Printf("Connect to Cab1 Mode ETBN=1 faild  ! ")
+					return nil, err
+				}
+				utils.LoggerDebug.Printf("Connect success PIS1:%s:%d from Cab6 !", socket.Re1RemoteAddr, socket.RemotePort)
+				return conn, nil
+
+			} else if active.TrainUnionID == 2 { //重联模式ETBN=2
+				DialAddr := fmt.Sprintf("%s:%d", socket.Re2RemoteAddr, socket.RemotePort)
+				conn, err := dialer.Dial("tcp", DialAddr)
+				if err != nil {
+					utils.LoggerDebug.Printf("Connect to Cab1 Mode ETBN=2 faild  ! ")
+					return nil, err
+				}
+				utils.LoggerDebug.Printf("Connect success PIS1:%s:%d from Cab6 !", socket.Re2RemoteAddr, socket.RemotePort)
+				return conn, nil
 			}
-			utils.LoggerDebug.Printf("Connect success STC1:%s:%d from Cab8 !", socket.RemoteAddr, socket.RemotePort)
-			return conn, nil
 		}
 	} else { // connect to MC8
-		//lfshook.NewLogger().Logger.Infof("========Connect server MC8 IP:%s  :Port:%d", socket.RemoteAddr8, socket.RemotePort)
+		//lfshook.NewLogger().Logger.Infof("========Connect server MC8 IP:%s  :Port:%d", socket.RemoteAddr6, socket.RemotePort)
 		// 创建 Dialer
-		if active.CabNum == "1" { //in cab1
+		if active.CabNum == "1" { //6车连1车
 			dialer := &net.Dialer{
 				LocalAddr: &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: socket.LocalPort}, // 固定本地端口
 				Control:   controlTCPConn,
-				Timeout:   5 * time.Second,
+				Timeout:   2 * time.Second,
 			}
 
-			DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr8, socket.RemotePort)
-			conn, err := dialer.Dial("tcp", DialAddr)
-			if err != nil {
-				//lfshook.NewLogger().Logger.Infof("========Connect server err :%+v", err)
-				return nil, err
+			if active.TrainUnionID == 0 { //单列模式下
+
+				DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr6, socket.RemotePort)
+				conn, err := dialer.Dial("tcp", DialAddr)
+				if err != nil {
+					utils.LoggerDebug.Printf("Connect to Cab1 Local faild  ! ")
+					return nil, err
+				}
+				utils.LoggerDebug.Printf("Connect success PIS1:%s:%d from Cab6 !", socket.RemoteAddr6, socket.RemotePort)
+				return conn, nil
+
+			} else if active.TrainUnionID == 1 { //重联模式ETBN=1
+
+				DialAddr := fmt.Sprintf("%s:%d", socket.Re1RemoteAddr6, socket.RemotePort)
+				conn, err := dialer.Dial("tcp", DialAddr)
+				if err != nil {
+					utils.LoggerDebug.Printf("Connect to Cab1 Mode ETBN=1 faild  ! ")
+					return nil, err
+				}
+				utils.LoggerDebug.Printf("Connect success PIS1:%s:%d from Cab6 !", socket.Re1RemoteAddr6, socket.RemotePort)
+				return conn, nil
+
+			} else if active.TrainUnionID == 2 { //重联模式ETBN=2
+				DialAddr := fmt.Sprintf("%s:%d", socket.Re2RemoteAddr6, socket.RemotePort)
+				conn, err := dialer.Dial("tcp", DialAddr)
+				if err != nil {
+					utils.LoggerDebug.Printf("Connect to Cab1 Mode ETBN=2 faild  ! ")
+					return nil, err
+				}
+				utils.LoggerDebug.Printf("Connect success PIS1:%s:%d from Cab6 !", socket.Re2RemoteAddr6, socket.RemotePort)
+				return conn, nil
 			}
-			utils.LoggerDebug.Printf("Connect success STC8:%s:%d from Cab1 !", socket.RemoteAddr8, socket.RemotePort)
-			return conn, nil
-		} else { //in cab 8
+
+		} else { //本地连本地
 			dialer := &net.Dialer{
-				LocalAddr: &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: socket.LocalPort8}, // 固定本地端口
+				LocalAddr: &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: socket.LocalPort6}, // 固定本地端口
 				Control:   controlTCPConn,
-				Timeout:   5 * time.Second,
+				Timeout:   2 * time.Second,
 			}
 
-			DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr8, socket.RemotePort)
+			DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr6, socket.RemotePort)
 			conn, err := dialer.Dial("tcp", DialAddr)
 			if err != nil {
 				//lfshook.NewLogger().Logger.Infof("========Connect server err :%+v", err)
 				return nil, err
 			}
-			utils.LoggerDebug.Printf("Connect success STC8:%s:%d from Cab8 !", socket.RemoteAddr8, socket.RemotePort)
+			utils.LoggerDebug.Printf("Connect success STC8:%s:%d from Cab8 !", socket.RemoteAddr6, socket.RemotePort)
 			return conn, nil
 		}
 	}
+	return nil, nil
 }
 
 /*
@@ -228,7 +279,7 @@ func CreateConnectionSipServer() (net.Conn, error) {
 		Timeout:   5 * time.Second,
 	}
 
-	DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr8, socket.LocalServerPort) // Connect to Cab8 Sip server
+	DialAddr := fmt.Sprintf("%s:%d", socket.RemoteAddr6, socket.LocalServerPort) // Connect to Cab8 Sip server
 	conn, err := dialer.Dial("tcp", DialAddr)
 	if err != nil {
 		//lfshook.NewLogger().Logger.Infof("========Connect SIP server err :%+v", err)

+ 32 - 114
internal/app/stc/priority/index.go

@@ -9,30 +9,9 @@ import (
 	"gopkg.in/ini.v1"
 )
 
-// PAD 是否接通
-var ICPAnswer = 0
-var OCCAnswer = 0
-
-var SpecialVoice = 0
-
-// PAD是否发起
-// var PADStart = 0
-// var PADTMSStart = 0
-var PADOccStart = 0
-
 // 是否有任务正在创建
 var TaskCreating = ""
 
-// 被打断的PAD类型
-var InterruptedPad = ""
-
-// 是否有CABCAB/PA打断其他(DTMF #/*)
-var CABInterrupt = 0
-var PAInterrupt = 0
-
-// 是否有CPA激活
-var CPAActived = 0
-
 var filePath = "/etc/asterisk/priority.conf"
 
 type TaskInfo struct {
@@ -51,16 +30,16 @@ type TaskPriority struct {
 type Tasks struct {
 	PA     TaskPriority `json:"pa"`
 	C2C    TaskPriority `json:"c2c"`
+	C2P    TaskPriority `json:"c2p"`
 	PADICP TaskPriority `json:"padicp"`
 	PADTMS TaskPriority `json:"padtms"`
 	PADOCC TaskPriority `json:"padocc"`
-	CPA    TaskPriority `json:"cpa"`
-	EMG    TaskPriority `json:"emg"`
-	SPC    TaskPriority `json:"spc"`
+	PMC    TaskPriority `json:"pmc"`
+	SVM    TaskPriority `json:"svm"`
+	SVA    TaskPriority `json:"sva"`
 	DCS    TaskPriority `json:"dcs"`
-	STN    TaskPriority `json:"stn"`
-	CHK    TaskPriority `json:"chk"`
-	VOL    TaskPriority `json:"vol"`
+	STNA   TaskPriority `json:"stna"`
+	STNS   TaskPriority `json:"stns"`
 }
 
 var AllTasks Tasks
@@ -78,48 +57,45 @@ func GetPriority() {
 		utils.LoggerDebug.Printf("GetPriority err :%+v", err)
 		return
 	}
-
-	AllTasks.CHK.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("CHK").Value())
-	AllTasks.STN.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("STN").Value())
+	AllTasks.STNA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("STNA").Value())
+	AllTasks.STNS.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("STNS").Value())
 	AllTasks.DCS.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("DCS").Value())
-	AllTasks.SPC.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("SPC").Value())
-	AllTasks.EMG.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("EMG").Value())
-	AllTasks.CPA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("CPA").Value())
+	AllTasks.SVA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("SVA").Value())
+	AllTasks.SVM.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("SVM").Value())
+	AllTasks.PMC.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PMC").Value())
 	AllTasks.PADOCC.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PAD-OCC").Value())
 	AllTasks.PADTMS.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PAD-TMS").Value())
 	AllTasks.PADICP.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PAD-ICP").Value())
-	AllTasks.C2C.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("CabCab").Value())
-	AllTasks.PA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("ManuPa").Value())
-	AllTasks.VOL.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("VOL").Value())
+	AllTasks.C2C.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("C2C").Value())
+	AllTasks.PA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PA").Value())
+	AllTasks.C2P.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("C2P").Value())
 
 }
 
 func GetPriorityByKey(key string) int {
 
 	switch key {
-	case "VOL":
-		return AllTasks.VOL.Priority
-	case "CHK":
-		return AllTasks.CHK.Priority
-	case "STN":
-		return AllTasks.STN.Priority
+	case "STNS":
+		return AllTasks.STNS.Priority
+	case "STNA":
+		return AllTasks.STNA.Priority
 	case "DCS":
 		return AllTasks.DCS.Priority
-	case "SPC":
-		return AllTasks.SPC.Priority
-	case "EMG":
-		return AllTasks.EMG.Priority
-	case "CPA":
-		return AllTasks.CPA.Priority
+	case "SVA":
+		return AllTasks.SVA.Priority
+	case "SVM":
+		return AllTasks.SVM.Priority
+	case "PMC":
+		return AllTasks.PMC.Priority
 	case "PAD-OCC":
 		return AllTasks.PADOCC.Priority
 	case "PAD-TMS":
 		return AllTasks.PADTMS.Priority
 	case "PAD-ICP":
 		return AllTasks.PADICP.Priority
-	case "CabCab":
+	case "C2C":
 		return AllTasks.C2C.Priority
-	case "ManuPa":
+	case "PA":
 		return AllTasks.PA.Priority
 	default:
 		return 0
@@ -130,85 +106,27 @@ var checkMutex sync.Mutex
 
 // check priority , if the running priority is lowwer than the to run priority
 func CheckPriority(runType string) bool {
-	utils.LoggerDebug.Printf("CheckPriority  TorunType:%s 	SpecialVoice:%d", runType, SpecialVoice)
+	utils.LoggerDebug.Printf("CheckPriority  TorunType:%s", runType)
 	checkMutex.Lock()
 	defer checkMutex.Unlock()
 
 	var taskRuning TaskInfo
-	var runingtaskName string
+	//var runingtaskName string
 	var ok bool
 
-	//Check special voice can not interrupt
-	if SpecialVoice == 1 {
-		return false
-	}
-
 	//Get the to run priority number in the config file
 	toRunpriority := GetPriorityByKey(runType)
 
 	//获取当前优先级最高的任务信息
-	if runType != "PA" && runType != "PAD-ICP" && runType != "PAD-TMS" { // ignore C2C
-		runingtaskName, taskRuning, ok = RegistryTask.HighestPriorityRunningTask1()
-		if !ok {
-			return true
-		}
+	_, taskRuning, ok = RegistryTask.HighestPriorityRunningTask()
+	if !ok { //无其他任务正在执行
+		return true
 	} else {
-		runingtaskName, taskRuning, ok = RegistryTask.HighestPriorityRunningTask()
-		if !ok {
-			return true
-		}
-	}
-
-	if ok {
-		utils.LoggerDebug.Printf("CheckPriority  TorunType:%s 	SpecialVoice:%d 	toRunpriority:%d 	runingpriority:%d ", runType, SpecialVoice, toRunpriority, taskRuning.Priority)
+		utils.LoggerDebug.Printf("CheckPriority  TorunType:%s 	 	toRunpriority:%d 	runingpriority:%d ", runType, toRunpriority, taskRuning.Priority)
 		//if the running task priority is lowwer
 		if toRunpriority < taskRuning.Priority && toRunpriority != 0 {
 			return true
-
-		} else if toRunpriority == taskRuning.Priority {
-
-			switch runType {
-			case "PAD-ICP":
-				return true
-			case "PAD-TMS":
-				return true
-			case "EMG":
-				return true
-			case "SPC":
-				return true
-			case "DCS":
-				if taskRuning.RunType == "STN" {
-					return false
-				} else {
-					return true
-				}
-
-			case "STN":
-				if taskRuning.RunType == "DCS" {
-					return false
-				} else {
-					return true
-				}
-			case "CHK":
-				return true
-			case "VOL":
-				return true
-			}
 		}
-
-		if runingtaskName == "C2C" {
-			if runType != "PA" && runType != "PAD-ICP" && runType != "PAD-TMS" && runType != "C2C" {
-				return true
-			}
-		} else if runType == "C2C" {
-			if runingtaskName != "PA" && runingtaskName != "PAD-ICP" && runingtaskName != "PAD-TMS" && runingtaskName != "C2C" {
-				return true
-			}
-		}
-
-	} else {
-		//No any runing task now
-		return true
 	}
 
 	return false

+ 127 - 117
internal/app/stc/sendstatus/status.go

@@ -5,62 +5,65 @@ import (
 	"net"
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
-	"pbx-api-gin/internal/app/stc/priority"
 	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/pkg/utils"
 	"time"
 )
 
-type PADQueue struct {
-	Exten      string    `json:"exten"`
-	ActiveTime time.Time `json:"activeTime"`
-}
-
-var PadQueues []PADQueue
+func SendToStc(conn net.Conn, data []byte) {
 
-// 删除某个报警器
-func removeAllByExten(queues []PADQueue, target string) []PADQueue {
-	result := make([]PADQueue, 0, len(queues))
-	for _, q := range queues {
-		if q.Exten != target {
-			result = append(result, q)
-		}
+	_, err := conn.Write(data)
+	if err != nil {
+		utils.LoggerDebug.Printf("Send To STC msg err:%+v", err)
+		conn.Close()
 	}
-	return result
+	//lfshook.NewLogger().Logger.Infof("SendToStc data:%x", data)
 }
 
-// 添加报警器
-func addExtenToQueue(queues []PADQueue, target string) []PADQueue {
+// report alarm status to STC
+func SendQueueStatus(pads string, count int) {
 
-	var padInfo = PADQueue{Exten: target, ActiveTime: time.Now()}
+	if !active.CheckReunoinMode() {
+		return
+	}
 
-	for _, q := range queues {
-		if q.Exten == target {
-			return queues
-		}
+	//Not Master role , ignore
+	if !active.Master {
+		return
 	}
-	queues = append(queues, padInfo)
-	return queues
-}
 
-// 初始化pad队列
-func init() {
-	PadQueues = make([]PADQueue, 0)
-}
+	DataLen := len(pads) + 2
 
-func SendToStc(conn net.Conn, data []byte) {
+	protocol := msgdata.NewProtocol()
+	protocol.MessageID = 0x29
+	protocol.DataLength = uint16(DataLen)
+	protocol.Data = make([]byte, DataLen)
+	protocol.Data[0] = byte(count) //排队数量
 
-	_, err := conn.Write(data)
-	if err != nil {
-		utils.LoggerDebug.Printf("Send To STC msg err:%+v", err)
-		conn.Close()
+	copy(protocol.Data[1:], []byte(pads))
+
+	encoded, errEn := protocol.Encode()
+	if errEn != nil {
+		fmt.Println("Encode error:", errEn)
+		return
 	}
-	//lfshook.NewLogger().Logger.Infof("SendToStc data:%x", data)
+	//check if actived
+	utils.LoggerDebug.Printf("PADs number:%s		count:%d 	", protocol.Data[1:], protocol.Data[0])
+	if socket.Conn != nil {
+		SendToStc(socket.Conn, encoded)
+	}
+
+	if socket.Conn6 != nil {
+		SendToStc(socket.Conn6, encoded)
+	}
+
 }
 
 // report alarm status to STC
 func AlarmStatus(exten string, status string) {
-
+	if !active.CheckReunoinMode() {
+		return
+	}
 	//Not Master role , ignore
 	if !active.Master {
 		return
@@ -73,8 +76,8 @@ func AlarmStatus(exten string, status string) {
 
 	protocol := msgdata.NewProtocol()
 	protocol.MessageID = 0x26
-	protocol.DataLength = 0x04
-	protocol.Data = make([]byte, 4)
+	protocol.DataLength = 0x1E
+	protocol.Data = make([]byte, 30)
 
 	protocol.Data[0] = exten[2] - '0' //车厢号
 	protocol.Data[1] = exten[3] - '0' //位置号
@@ -110,13 +113,66 @@ func AlarmStatus(exten string, status string) {
 		protocol.Data[2] = 0
 	}
 
-	//将pad存储到队列中
-	if protocol.Data[2] == 0x03 { //排队状态
-		PadQueues = addExtenToQueue(PadQueues, exten)
-		utils.LoggerDebug.Printf("PAD:%s add to queue", exten)
-	} else if protocol.Data[2] == 0x01 { //空闲状态
-		utils.LoggerDebug.Printf("PAD:%s del from queue", exten)
-		PadQueues = removeAllByExten(PadQueues, exten)
+	//填充时间
+	now := time.Now()
+	ntm := now.Format("2006-01-02 15:04:05")
+	//fmt.Println(s)
+	copy(protocol.Data[3:], []byte(ntm))
+
+	encoded, errEn := protocol.Encode()
+	if errEn != nil {
+		fmt.Println("Encode error:", errEn)
+		return
+	}
+	//check if actived
+	utils.LoggerDebug.Printf("PAD number:%s		CarNum:%x 	 Pos:%x 	Status:%x(0=Offline,1=Idle,2=calling,3=Hold,4=Connected)", exten, protocol.Data[0], protocol.Data[1], protocol.Data[2])
+
+	if socket.Conn != nil {
+		SendToStc(socket.Conn, encoded)
+	}
+
+	if socket.Conn6 != nil {
+		SendToStc(socket.Conn6, encoded)
+	}
+
+}
+
+// report alarm status to STC
+func SendICPStatus(exten string, status string) {
+	if !active.CheckReunoinMode() {
+		return
+	}
+	//Not Master role , ignore
+	if !active.Master {
+		return
+	}
+
+	//check exten if it is a alarm exten
+	if !utils.IsPAIU(exten) { // if not alarm device , return
+		return
+	}
+
+	protocol := msgdata.NewProtocol()
+	protocol.MessageID = 0x25
+	protocol.DataLength = 0x04
+	protocol.Data = make([]byte, 4)
+
+	protocol.Data[0] = exten[2] - '0' //车厢号
+	protocol.Data[1] = exten[3] - '0' //位置号
+
+	//报警器工作状态
+	switch status {
+	case "unavailable", "Unavailable": //offline
+		protocol.Data[2] = 0x00
+
+	case "idle", "Idle": //idle
+		protocol.Data[2] = 0x01
+
+	case "dial": //dial
+		protocol.Data[2] = 0x02
+		return
+	case "connect": //PAD alarm
+		protocol.Data[2] = 0x03
 	}
 
 	encoded, errEn := protocol.Encode()
@@ -131,27 +187,29 @@ func AlarmStatus(exten string, status string) {
 		SendToStc(socket.Conn, encoded)
 	}
 
-	if socket.Conn8 != nil {
-		SendToStc(socket.Conn8, encoded)
+	if socket.Conn6 != nil {
+		SendToStc(socket.Conn6, encoded)
 	}
 
 }
 
 // report broadcast status to STC
 func PaStatus(src string, patype string, operation string) {
-
+	if !active.CheckReunoinMode() {
+		return
+	}
 	//Not Master role , ignore
 	if !active.Master {
 		return
 	}
 
 	//过滤掉非EMG运行模式下的continue状态发送
-	if operation == "continue" {
-		taskName, _, _ := priority.RegistryTask.HighestPriorityRunningTask()
-		if taskName != "EMG" {
-			return
-		}
-	}
+	//if operation == "continue" {
+	//	taskName, _, _ := priority.RegistryTask.HighestPriorityRunningTask()
+	//	if taskName != "EMG" {
+	//		return
+	//	}
+	//}
 
 	utils.LoggerDebug.Printf("PA Status Src:%s 		Type:%s		Status:%s", src, patype, operation)
 	protocol := msgdata.NewProtocol()
@@ -161,40 +219,30 @@ func PaStatus(src string, patype string, operation string) {
 
 	//广播发起方
 	switch src {
-	case "2311": //mc1
+	case "1211", "2111": //mc1
 		protocol.Data[0] = 0x01
-	case "2381": //mc8
-		protocol.Data[0] = 0x08
-	/*case "1411": //mc8
+	case "1261": //mc8
 		protocol.Data[0] = 0x08
-	case "1481": //mc8
-		protocol.Data[0] = 0x08*/
 	default: //
 		protocol.Data[0] = 0x00
 	}
 
 	//广播类型
 	switch patype {
-	case "C2C": //司机对讲---ami
-		protocol.Data[1] = 0x01
 	case "PA": //人工广播---ami
+		protocol.Data[1] = 0x01
+	case "STNA": //自动报站
 		protocol.Data[1] = 0x02
-	case "DCS": //开关门提示音
+	case "STNS": //手动报站
 		protocol.Data[1] = 0x03
-	case "EMG": //紧急广播
+	case "SVM": //服务消息
 		protocol.Data[1] = 0x04
-	case "PAD": //报警
+	case "PMC": //远程广播
 		protocol.Data[1] = 0x05
-	case "CPA": //地面广播---ami
+	case "SVA": //服务音频
 		protocol.Data[1] = 0x06
-	case "SPC": //特殊
+	case "DCS": //开关门提示
 		protocol.Data[1] = 0x07
-	case "STN": //报站
-		protocol.Data[1] = 0x08
-	case "CHK": //自检
-		protocol.Data[1] = 0x09
-	case "VOL": //音调条件
-		protocol.Data[1] = 0x0a
 	}
 
 	//操作类型
@@ -221,55 +269,17 @@ func PaStatus(src string, patype string, operation string) {
 		SendToStc(socket.Conn, encoded)
 	}
 
-	if socket.Conn8 != nil {
-		SendToStc(socket.Conn8, encoded)
+	if socket.Conn6 != nil {
+		SendToStc(socket.Conn6, encoded)
 	}
 
 }
 
 // report broadcast status to STC
-func OccPad(operation string) {
-
-	//Not Master role , ignore
-	if !active.Master {
-		return
-	}
-
-	utils.LoggerDebug.Printf("OCC-PAD status:%s", operation)
-	protocol := msgdata.NewProtocol()
-	protocol.MessageID = 0x2A
-	protocol.DataLength = 0x04
-	protocol.Data = make([]byte, 4)
-
-	//广播发起方
-	switch operation {
-	case "start": //mc1
-		protocol.Data[0] = 0x01
-	case "end": //mc8
-		protocol.Data[0] = 0x02
-	case "": //
-		protocol.Data[0] = 0x00
-	}
-
-	encoded, errEn := protocol.Encode()
-	if errEn != nil {
-		utils.LoggerDebug.Printf("Encode error:%+v", errEn)
+func SendRecordFile(filename, rcdtype string) {
+	if !active.CheckReunoinMode() {
 		return
 	}
-
-	if socket.Conn != nil {
-		SendToStc(socket.Conn, encoded)
-	}
-
-	if socket.Conn8 != nil {
-		SendToStc(socket.Conn8, encoded)
-	}
-
-}
-
-// report broadcast status to STC
-func SendRecordFile(filename, rcdtype string) {
-
 	//time.Sleep(5 * time.Second)
 	/*
 		if !utils.FileExists(filename) {
@@ -315,7 +325,7 @@ func SendRecordFile(filename, rcdtype string) {
 		SendToStc(socket.Conn, encoded)
 	}
 
-	if socket.Conn8 != nil {
-		SendToStc(socket.Conn8, encoded)
+	if socket.Conn6 != nil {
+		SendToStc(socket.Conn6, encoded)
 	}
 }

+ 19 - 11
internal/app/stc/socket/index.go

@@ -9,19 +9,27 @@ import (
 )
 
 var Conn net.Conn
-var Conn8 net.Conn
+var Conn6 net.Conn
 
 var ConnToSlave net.Conn
 
 const RemotePort = 10100
 const LocalPort = 10201
-const LocalPort8 = 10202
+const LocalPort6 = 10202
 
 const LocalServerPort = 10000
 
-const RemoteAddr = "10.0.11.11"
+// 单列
+const RemoteAddr = "10.0.0.101"
+const RemoteAddr6 = "10.0.0.106"
 
-const RemoteAddr8 = "10.0.11.81"
+// 重联ETBN=1
+const Re1RemoteAddr = "10.128.64.101"
+const Re1RemoteAddr6 = "10.128.64.106"
+
+// 重联ETBN=2
+const Re2RemoteAddr = "10.128.128.101"
+const Re2RemoteAddr6 = "10.128.128.106"
 
 func IsIPExists(targetIP string) (bool, error) {
 	// 解析目标 IP
@@ -62,9 +70,9 @@ func SetMasterCabNum() {
 getIP:
 
 	utils.LoggerDebug.Printf("Checking system IP  ....")
-	ext1, err := IsIPExists("10.0.11.11")
+	ext1, err := IsIPExists("10.0.0.101")
 	if err != nil {
-		utils.LoggerDebug.Printf("Check IP 10.0.11.11 err :%+v", err)
+		utils.LoggerDebug.Printf("Check IP 10.0.0.101 err :%+v", err)
 	}
 	// Init cab1 number and master role
 	if ext1 {
@@ -73,18 +81,18 @@ getIP:
 		return
 	}
 
-	ext8, err := IsIPExists("10.0.11.81")
+	ext6, err := IsIPExists("10.0.0.106")
 	if err != nil {
-		utils.LoggerDebug.Printf("Check IP 10.0.11.81 err:%+v", err)
+		utils.LoggerDebug.Printf("Check IP 10.0.0.101 err:%+v", err)
 	}
 	// Init cab8 number and master role
-	if ext8 {
-		active.CabNum = "8"
+	if ext6 {
+		active.CabNum = "6"
 		active.Master = false
 		return
 	}
 
-	if !(ext1 || ext8) {
+	if !(ext1 || ext6) {
 		if count < 5 {
 			count++
 			time.Sleep(time.Second * 2)

+ 4 - 4
pkg/utils/utils.go

@@ -113,7 +113,7 @@ func IsChannel(input string) bool {
 // 判断是否是广播分机
 func IsPAIU(input string) bool {
 	if len(input) == 4 {
-		return input[:2] == "24"
+		return input[:2] == "22"
 	}
 	return false
 }
@@ -121,7 +121,7 @@ func IsPAIU(input string) bool {
 // 判断是否是广播分机
 func IsPACU(input string) bool {
 	if len(input) == 4 {
-		return input[:2] == "21"
+		return input[:2] == "13"
 	}
 	return false
 }
@@ -130,7 +130,7 @@ func IsPACU(input string) bool {
 func IsIO(input string) bool {
 
 	if len(input) == 4 {
-		return input[:2] == "14"
+		return input[:2] == "12"
 	}
 	return false
 }
@@ -139,7 +139,7 @@ func IsIO(input string) bool {
 func IsICP(input string) bool {
 
 	if len(input) == 4 {
-		return input[:2] == "23"
+		return input[:2] == "21"
 	}
 	return false
 }