|
|
@@ -7,14 +7,15 @@ import (
|
|
|
"io"
|
|
|
"net"
|
|
|
"net/http"
|
|
|
- "pbx-api-gin/api/panel/asterisk"
|
|
|
"pbx-api-gin/internal/app/ami/action"
|
|
|
"pbx-api-gin/internal/app/ami/model"
|
|
|
"pbx-api-gin/internal/app/mysql"
|
|
|
"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"
|
|
|
+ "strconv"
|
|
|
"sync"
|
|
|
"time"
|
|
|
)
|
|
|
@@ -79,26 +80,63 @@ func processPacket(packet []byte) {
|
|
|
}
|
|
|
|
|
|
switch packet[5] {
|
|
|
+ case 0x01:
|
|
|
+ break
|
|
|
+
|
|
|
case 0x02: // STN
|
|
|
- StationAnn(packet)
|
|
|
+ if priority.CheckPriority("STN") {
|
|
|
+ action.HangupAll()
|
|
|
+ StationAnn(packet)
|
|
|
+ }
|
|
|
+
|
|
|
case 0x05: // SPC
|
|
|
- SpecialAnn(packet)
|
|
|
+ if priority.CheckPriority("SPC-TMS") {
|
|
|
+ action.HangupAll()
|
|
|
+ SpecialAnn(packet)
|
|
|
+ }
|
|
|
+
|
|
|
case 0x06: // EMG
|
|
|
EmgMsg(packet)
|
|
|
+
|
|
|
case 0x07: // STOP
|
|
|
AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
|
|
|
+
|
|
|
case 0x08: // DCS
|
|
|
- DcsAnn(packet)
|
|
|
+ if priority.CheckPriority("DCS") {
|
|
|
+ action.HangupAll()
|
|
|
+ DcsAnn(packet)
|
|
|
+ }
|
|
|
+
|
|
|
case 0x09: // SELF CHECK
|
|
|
- SelfCheck(packet)
|
|
|
+ if priority.CheckPriority("CHK") {
|
|
|
+ action.HangupAll()
|
|
|
+ SelfCheck(packet)
|
|
|
+ }
|
|
|
+
|
|
|
+ case 0x10: // SELF CHECK
|
|
|
+ if priority.CheckPriority("CHK") {
|
|
|
+ action.HangupAll()
|
|
|
+ VolumeAdjust(packet)
|
|
|
+ }
|
|
|
+
|
|
|
case 0x0a:
|
|
|
- AlarmHandleTMS(packet)
|
|
|
+ if priority.CheckPriority("PAD-TMS") {
|
|
|
+ action.HangupAll()
|
|
|
+ AlarmHandleTMS(packet)
|
|
|
+ }
|
|
|
+
|
|
|
case 0x0b:
|
|
|
AlarmHoldResetAll(packet[8])
|
|
|
+
|
|
|
case 0x0c:
|
|
|
RecordStorageConf(packet[8:])
|
|
|
+
|
|
|
case 0x0d:
|
|
|
- AlarmHandleICP(packet)
|
|
|
+ if priority.CheckPriority("PAD-ICP") {
|
|
|
+ action.HangupAll()
|
|
|
+ AlarmHandleICP(packet)
|
|
|
+ }
|
|
|
+
|
|
|
default:
|
|
|
fmt.Printf("Unknown command: %x\n", packet[5])
|
|
|
}
|
|
|
@@ -114,14 +152,11 @@ func StationAnn(data []byte) (err error) {
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
|
|
|
|
- //update stn voice
|
|
|
- _, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{Special: specialVoice, PaType: "STN"})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
- return er
|
|
|
- }
|
|
|
+ //set spc voice tag
|
|
|
+ priority.SpecialVoice = specialVoice
|
|
|
|
|
|
//Pa status report
|
|
|
+ priority.RunningType, _ = strconv.Atoi(priority.Priority.STN)
|
|
|
alstatus.PaStatus("", "STN", "start")
|
|
|
|
|
|
action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
|
|
|
@@ -199,13 +234,8 @@ func SpecialAnn(data []byte) {
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
|
|
|
|
- //update pa type
|
|
|
- _, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "SPC"})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
- }
|
|
|
-
|
|
|
//Pa status report
|
|
|
+ priority.RunningType, _ = strconv.Atoi(priority.Priority.SPCTMS)
|
|
|
alstatus.PaStatus("", "SPC", "start")
|
|
|
|
|
|
if int(cycleCount) == 255 {
|
|
|
@@ -223,13 +253,8 @@ func EmgMsg(data []byte) {
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
|
|
|
|
- //update pa type
|
|
|
- _, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "EMG"})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
- }
|
|
|
-
|
|
|
//Pa status report
|
|
|
+ priority.RunningType, _ = strconv.Atoi(priority.Priority.EMGTMS)
|
|
|
alstatus.PaStatus("", "EMG", "start")
|
|
|
|
|
|
if int(cycleCount) == 255 {
|
|
|
@@ -242,32 +267,34 @@ func EmgMsg(data []byte) {
|
|
|
// 停止指定类型广播
|
|
|
func AnnStop(data [4]byte) {
|
|
|
|
|
|
- RunningType := ""
|
|
|
+ PaType := ""
|
|
|
|
|
|
switch data[0] {
|
|
|
case 0x03:
|
|
|
- RunningType = "DCS"
|
|
|
+ PaType = "DCS"
|
|
|
case 0x04:
|
|
|
- RunningType = "EMG"
|
|
|
+ PaType = "EMG"
|
|
|
case 0x07:
|
|
|
- RunningType = "SPC"
|
|
|
+ PaType = "SPC"
|
|
|
case 0x08:
|
|
|
- RunningType = "STN"
|
|
|
+ PaType = "STN"
|
|
|
case 0x09:
|
|
|
- RunningType = "CHK"
|
|
|
+ PaType = "CHK"
|
|
|
}
|
|
|
|
|
|
- alstatus.PaStatus("", RunningType, "end")
|
|
|
-
|
|
|
- for _, ext := range Pacus {
|
|
|
- action.Hangup(ext)
|
|
|
- }
|
|
|
-
|
|
|
- //update pa type
|
|
|
- _, er := mysql.DBOrmInstance.Cols("patype").Where("pa_type = ?", RunningType).Update(&model.Extension{PaType: ""})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
- }
|
|
|
+ priority.RunningType = 0
|
|
|
+ alstatus.PaStatus("", PaType, "end")
|
|
|
+ /*
|
|
|
+ for _, ext := range Pacus {
|
|
|
+ action.Hangup(ext)
|
|
|
+ }
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.Cols("patype").Where("pa_type = ?", RunningType).Update(&model.Extension{PaType: ""})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ }
|
|
|
+ */
|
|
|
+ action.HangupAll()
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -279,13 +306,8 @@ func DcsAnn(data []byte) {
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
|
|
|
|
- //update pa type
|
|
|
- _, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "DCS"})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
- }
|
|
|
-
|
|
|
//Pa status report
|
|
|
+ priority.RunningType, _ = strconv.Atoi(priority.Priority.DCS)
|
|
|
alstatus.PaStatus("", "DCS", "start")
|
|
|
|
|
|
if int(cycleCount) == 255 {
|
|
|
@@ -295,8 +317,8 @@ func DcsAnn(data []byte) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 自检广播
|
|
|
-func SelfCheck(data []byte) {
|
|
|
+// 调音广播
|
|
|
+func VolumeAdjust(data []byte) {
|
|
|
|
|
|
check := data[8]
|
|
|
delay := data[9]
|
|
|
@@ -305,28 +327,59 @@ func SelfCheck(data []byte) {
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
|
|
|
|
- //update pa type
|
|
|
- _, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "CHK"})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ switch check {
|
|
|
+ case 0x01: //start
|
|
|
+
|
|
|
+ //Pa status report
|
|
|
+ priority.RunningType, _ = strconv.Atoi(priority.Priority.CHK)
|
|
|
+ alstatus.PaStatus("", "VOL", "start")
|
|
|
+ action.PlaybackPacu(filename, int(cycleCount), int(delay), "VOL")
|
|
|
+ case 0x02: //stop
|
|
|
+
|
|
|
+ /* //Pa status report
|
|
|
+ priority.RunningType = 0
|
|
|
+ alstatus.PaStatus("", "VOL", "end")
|
|
|
+
|
|
|
+ for _, ext := range Pacus {
|
|
|
+ asterisk.Hangup(ext)
|
|
|
+ }
|
|
|
+ asterisk.Hangup("2311")
|
|
|
+ asterisk.Hangup("2381")
|
|
|
+ */
|
|
|
+ action.HangupAll()
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+// 自检广播
|
|
|
+func SelfCheck(data []byte) {
|
|
|
+
|
|
|
+ check := data[8]
|
|
|
+ delay := data[9]
|
|
|
+ cycleCount := data[10]
|
|
|
+ datalen := int(data[11])
|
|
|
+
|
|
|
+ filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
|
|
|
|
switch check {
|
|
|
case 0x01: //start
|
|
|
|
|
|
//Pa status report
|
|
|
+ priority.RunningType, _ = strconv.Atoi(priority.Priority.CHK)
|
|
|
alstatus.PaStatus("", "CHK", "start")
|
|
|
action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
|
|
|
case 0x02: //stop
|
|
|
|
|
|
//Pa status report
|
|
|
+ priority.RunningType = 0
|
|
|
alstatus.PaStatus("", "CHK", "end")
|
|
|
-
|
|
|
- for _, ext := range Pacus {
|
|
|
- asterisk.Hangup(ext)
|
|
|
- }
|
|
|
- asterisk.Hangup("2311")
|
|
|
- asterisk.Hangup("2381")
|
|
|
+ /*
|
|
|
+ for _, ext := range Pacus {
|
|
|
+ asterisk.Hangup(ext)
|
|
|
+ }
|
|
|
+ asterisk.Hangup("2311")
|
|
|
+ asterisk.Hangup("2381")
|
|
|
+ */
|
|
|
+ action.HangupAll()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -385,10 +438,11 @@ func AlarmHandleICP(data []byte) {
|
|
|
|
|
|
case 0x03: //hangup
|
|
|
//NotifyPaiu(exten, "hangup")
|
|
|
- action.Hangup(exten) //Pad
|
|
|
- action.Hangup("2311") //1 车接听
|
|
|
- action.Hangup("2381") //8 车接听
|
|
|
-
|
|
|
+ /* action.Hangup(exten) //Pad
|
|
|
+ action.Hangup("2311") //1 车接听
|
|
|
+ action.Hangup("2381") //8 车接听
|
|
|
+ */
|
|
|
+ action.HangupAll()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -446,9 +500,11 @@ func AlarmHandleTMS(data []byte) {
|
|
|
|
|
|
case 0x03: //hangup
|
|
|
//NotifyPaiu(exten, "hangup")
|
|
|
- action.Hangup(exten) //PAD
|
|
|
+ /*action.Hangup(exten) //PAD
|
|
|
action.Hangup("2311") //1 车接听
|
|
|
action.Hangup("2381") //8 车接听
|
|
|
+ */
|
|
|
+ action.HangupAll()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -495,6 +551,7 @@ func AlarmHoldResetAll(data byte) {
|
|
|
lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
}
|
|
|
|
|
|
+ //all hold
|
|
|
if data == 1 {
|
|
|
for _, ext := range AlarmExts {
|
|
|
err := action.RedirectInQueue(ext.Extension, "0300", "default", "1")
|
|
|
@@ -510,7 +567,7 @@ func AlarmHoldResetAll(data byte) {
|
|
|
action.Hangup("2381") //8 车接听
|
|
|
alstatus.AlarmStatus("0000", "allhold") // send all hold status
|
|
|
}
|
|
|
- } else if data == 2 {
|
|
|
+ } else if data == 2 { //all reset
|
|
|
for _, ext := range AlarmExts {
|
|
|
action.Hangup(ext.Extension)
|
|
|
}
|
|
|
@@ -537,8 +594,8 @@ func RecordStorageConf(data []byte) {
|
|
|
info.PadRcdDelDays = int(data[4])
|
|
|
info.PaRcdDelDays = int(data[5])
|
|
|
info.CpaRcdDelDays = int(data[6])
|
|
|
- info.OpaRcdStorageDays = int(data[7])
|
|
|
- info.OpaRcdDelDays = int(data[8])
|
|
|
+ //info.OpaRcdStorageDays = int(data[7])
|
|
|
+ //info.OpaRcdDelDays = int(data[8])
|
|
|
|
|
|
//lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
|
|
|
|