dujunchen 1 hete
szülő
commit
85088850d3

+ 59 - 17
internal/app/ami/action/index.go

@@ -1,6 +1,7 @@
 package action
 
 import (
+	"net"
 	"pbx-api-gin/internal/app/ami/model"
 	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/stc/active"
@@ -27,7 +28,12 @@ func HandleAMI(event map[string]string) {
 	}
 
 	// MC1 conn or MC8 conn
-	conn := socket.Conn
+	var conn net.Conn
+	if active.CabNum == "1" && active.Actived {
+		conn = socket.Conn
+	} else if active.CabNum == "8" && active.Actived {
+		conn = socket.Conn8
+	}
 
 	if conn == nil {
 		lfshook.NewLogger().Infof("===HandleAMI===conn==nil=")
@@ -35,29 +41,64 @@ func HandleAMI(event map[string]string) {
 	}
 
 	switch event["Event"] {
-	case "DialBegin":
-		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["DestCallerIDNum"]) {
-
-			alstatus.AlarmStatus(event["CallerIDNum"], "dial", conn) // Alarm dial ICP start
-		}
+	/*case "DialBegin":
+	lfshook.NewLogger().Infof("=========%s", event["Event"])
+	if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["DestCallerIDNum"]) {
+		alstatus.AlarmStatus(event["CallerIDNum"], "dial", conn) // Alarm dial ICP start
+	}
+	*/
 	case "Newchannel":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0300" { // Alarm dial queue start
-
+		if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0300" { // Alarm dial queue start; PAD dialing
+			alstatus.PaStatus(event["CallerIDNum"], "PAD", "start", conn)
 			alstatus.AlarmStatus(event["CallerIDNum"], "dial", conn)
 		}
-	case "1111":
-		//case "DialEnd":
+
+	case "Hangup":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) {
-			alstatus.AlarmStatus(event["CallerIDNum"], "Idle", conn) // Alarm dial end
+		if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["Exten"]) { // Alarm dial queue start; PAD dialing
+			alstatus.PaStatus(event["CallerIDNum"], "PAD", "end", conn)
 		}
+
 	case "QueueCallerJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) { // Alarm join the queue
+		if utils.IsPAIU(event["CallerIDNum"]) { // Alarm join the queue, PAD in the queue
 			alstatus.AlarmStatus(event["CallerIDNum"], "queue", conn)
+		}
+
+	case "ConfbridgeJoin":
+		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
+			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
+			alstatus.PaStatus(event["CallerIDNum"], "PA", "start", conn)
+		}
+		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0500" { //CPA start
+			lfshook.NewLogger().Infof("====CPA status:%s=====", "start")
+			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start", conn)
+		}
+
+	case "ConfbridgeLeave":
+		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
+			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
+			alstatus.PaStatus(event["CallerIDNum"], "PA", "end", conn)
+		}
+		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0500" { //CPA end
+			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
+			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end", conn)
+		}
+
+	case "DialEnd":
+		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		//Cab Cab start
+		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
+			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start", conn)
+		}
 
+	case "BridgeLeave":
+		//Cab Cab end
+		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
+			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end", conn)
 		}
 
 	case "ExtensionStatus":
@@ -73,11 +114,12 @@ func HandleAMI(event map[string]string) {
 		}
 		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
 			if len(event["Exten"]) > 3 {
-				alstatus.AlarmStatus(event["Exten"], event["StatusText"], conn) // Alarm idle + unavailable
+				alstatus.AlarmStatus(event["Exten"], event["StatusText"], conn) // PAD idle + unavailable
 			}
 		}
-	case "BridgeEnter":
 
+	case "BridgeEnter":
+		//ICP and PAD connected
 		if utils.IsPACU(event["CallerIDNum"]) {
 			if utils.IsPAIU(event["CallerIDName"]) { //relate to PACU Dial ICP caller name in AlarmHandle
 				lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s   Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
@@ -88,8 +130,8 @@ func HandleAMI(event map[string]string) {
 			lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s   Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
 			alstatus.AlarmStatus(event["CallerIDName"], "connect", conn) // Alarm connected
 		}
-
 	}
+
 }
 
 func StartAMI(connectOKCallBack func(), handleEvents []func(event map[string]string)) {

+ 69 - 4
internal/app/stc/broadcast/stc-broadcast.go

@@ -13,6 +13,8 @@ import (
 	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
+	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
+	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/pkg/lfshook"
 	"sync"
 	"time"
@@ -132,6 +134,14 @@ func StationAnn(data []byte) (err error) {
 		return er
 	}
 
+	//Pa status report
+	if active.Actived && active.CabNum == "1" {
+		alstatus.PaStatus("", "STN", "start", socket.Conn)
+	}
+	if active.Actived && active.CabNum == "8" {
+		alstatus.PaStatus("", "STN", "start", socket.Conn8)
+	}
+
 	action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
 	return nil
 }
@@ -213,6 +223,14 @@ func SpecialAnn(data []byte) {
 		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
 	}
 
+	//Pa status report
+	if active.Actived && active.CabNum == "1" {
+		alstatus.PaStatus("", "SPC", "start", socket.Conn)
+	}
+	if active.Actived && active.CabNum == "8" {
+		alstatus.PaStatus("", "SPC", "start", socket.Conn8)
+	}
+
 	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "SPC")
@@ -235,6 +253,14 @@ func EmgMsg(data []byte) {
 		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
 	}
 
+	//Pa status report
+	if active.Actived && active.CabNum == "1" {
+		alstatus.PaStatus("", "EMG", "start", socket.Conn)
+	}
+	if active.Actived && active.CabNum == "8" {
+		alstatus.PaStatus("", "EMG", "start", socket.Conn8)
+	}
+
 	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "EMG")
@@ -245,8 +271,16 @@ func EmgMsg(data []byte) {
 
 // 停止指定类型广播
 func AnnStop(data [4]byte) {
+
+	var conn net.Conn
 	RunningType := ""
 
+	if active.Actived && active.CabNum == "1" {
+		conn = socket.Conn
+	} else if active.Actived && active.CabNum == "8" {
+		conn = socket.Conn8
+	}
+
 	switch data[0] {
 	case 0x03:
 		RunningType = "DCS"
@@ -259,6 +293,9 @@ func AnnStop(data [4]byte) {
 	case 0x09:
 		RunningType = "CHK"
 	}
+
+	alstatus.PaStatus("", RunningType, "end", conn)
+
 	for _, ext := range Pacus {
 		action.Hangup(ext)
 	}
@@ -286,6 +323,14 @@ func DcsAnn(data []byte) {
 	}
 
 	//lfshook.NewLogger().Infof("======count:%x", cycleCount)
+	//Pa status report
+	if active.Actived && active.CabNum == "1" {
+		alstatus.PaStatus("", "DCS", "start", socket.Conn)
+	}
+	if active.Actived && active.CabNum == "8" {
+		alstatus.PaStatus("", "DCS", "start", socket.Conn8)
+	}
+
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "DCS")
 	} else {
@@ -309,9 +354,27 @@ func SelfCheck(data []byte) {
 	}
 
 	switch check {
-	case 0x01:
+	case 0x01: //start
+
+		//Pa status report
+		if active.Actived && active.CabNum == "1" {
+			alstatus.PaStatus("", "CHK", "start", socket.Conn)
+		}
+		if active.Actived && active.CabNum == "8" {
+			alstatus.PaStatus("", "CHK", "start", socket.Conn8)
+		}
+
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
-	case 0x02:
+	case 0x02: //stop
+
+		//Pa status report
+		if active.Actived && active.CabNum == "1" {
+			alstatus.PaStatus("", "CHK", "end", socket.Conn)
+		}
+		if active.Actived && active.CabNum == "8" {
+			alstatus.PaStatus("", "CHK", "end", socket.Conn8)
+		}
+
 		for _, ext := range Pacus {
 			asterisk.Hangup(ext)
 		}
@@ -453,9 +516,11 @@ func AlarmResetAll() {
 	}
 
 	if active.CabNum == "1" && active.Actived {
-		action.Hangup("2311") //1 车接听
+		action.Hangup("2311")                                 //1 车接听
+		alstatus.AlarmStatus("0000", "allreset", socket.Conn) //send all reset status
 	} else if active.CabNum == "8" && active.Actived {
-		action.Hangup("2381") //8 车接听
+		action.Hangup("2381")                                  //8 车接听
+		alstatus.AlarmStatus("0000", "allreset", socket.Conn8) // send all reset status
 	}
 }
 

+ 24 - 10
internal/app/stc/sendstatus/status.go

@@ -53,6 +53,19 @@ func AlarmStatus(exten string, status string, conn net.Conn) {
 
 	case "connect": //connect
 		protocol.Data[2] = 0x04
+
+	case "allreset": //allreset
+
+		protocol.MessageID = 0x29
+		protocol.Data[0] = 0x02 //all reset
+		protocol.Data[1] = 0
+		protocol.Data[2] = 0
+	case "allhold": //allhold
+
+		protocol.MessageID = 0x29
+		protocol.Data[0] = 0x01 //all hold
+		protocol.Data[1] = 0
+		protocol.Data[2] = 0
 	}
 
 	encoded, errEn := protocol.Encode()
@@ -73,36 +86,37 @@ func PaStatus(src string, patype string, operation string, conn net.Conn) {
 	protocol := msgdata.NewProtocol()
 	protocol.MessageID = 0x22
 	protocol.DataLength = 0x04
+	protocol.Data = make([]byte, 4)
 
 	//广播发起方
 	switch src {
-	case "2311": //offline
+	case "2311": //mc1
 		protocol.Data[0] = 0x01
-	case "2381": //idle
+	case "2381": //mc8
 		protocol.Data[0] = 0x08
-	case "": //idle
+	case "": //
 		protocol.Data[0] = 0x00
 	}
 
 	//广播类型
 	switch patype {
-	case "C2C": //司机对讲
+	case "C2C": //司机对讲---ami
 		protocol.Data[1] = 0x01
-	case "C2P": //人工广播
+	case "PA": //人工广播---ami
 		protocol.Data[1] = 0x02
-	case "DOR": //开关门提示音
+	case "DCS": //开关门提示音
 		protocol.Data[1] = 0x03
 	case "EMG": //紧急广播
 		protocol.Data[1] = 0x04
-	case "AlARM": //报警
+	case "PAD": //报警
 		protocol.Data[1] = 0x05
-	case "CPA": //地面广播
+	case "CPA": //地面广播---ami
 		protocol.Data[1] = 0x06
-	case "SPE": //特殊
+	case "SPC": //特殊
 		protocol.Data[1] = 0x07
 	case "STN": //报站
 		protocol.Data[1] = 0x08
-	case "CH": //自检
+	case "CHK": //自检
 		protocol.Data[1] = 0x09
 	}
 

+ 9 - 0
pkg/utils/utils.go

@@ -125,6 +125,15 @@ func IsPACU(input string) bool {
 	return false
 }
 
+// 判断是否是司机控制盒
+func IsIO(input string) bool {
+
+	if len(input) == 4 {
+		return input[:2] == "14"
+	}
+	return false
+}
+
 // 判断是否是司机控制盒
 func IsICP(input string) bool {