|
|
@@ -12,7 +12,6 @@ import (
|
|
|
"pbx-api-gin/internal/app/mysql"
|
|
|
msgdata "pbx-api-gin/internal/app/stc/data"
|
|
|
"pbx-api-gin/pkg/lfshook"
|
|
|
- "strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
)
|
|
|
@@ -70,16 +69,21 @@ func processPacket(packet []byte) {
|
|
|
case 0x01: // heartbeat
|
|
|
// handle heartbeat
|
|
|
case 0x02: // STN
|
|
|
+ lfshook.NewLogger().Infof("=====STN=========")
|
|
|
StationAnn(packet)
|
|
|
case 0x03: // ACTIVE
|
|
|
+
|
|
|
Active([1]byte{packet[8]})
|
|
|
case 0x05: // SPC
|
|
|
+ lfshook.NewLogger().Infof("=====SPC=========")
|
|
|
SpecialAnn(packet)
|
|
|
case 0x06: // EMG
|
|
|
+ lfshook.NewLogger().Infof("=====EMG=========")
|
|
|
EmgMsg(packet)
|
|
|
case 0x07: // STOP
|
|
|
AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
|
|
|
case 0x08: // DCS
|
|
|
+ lfshook.NewLogger().Infof("=====DCS=========")
|
|
|
DcsAnn(packet)
|
|
|
case 0x09: // SELF CHECK
|
|
|
SelfCheck(packet)
|
|
|
@@ -103,7 +107,6 @@ func StationAnn(data []byte) (err error) {
|
|
|
datalen := int(data[11])
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
|
- filename = strings.Split(filename, ".")[0]
|
|
|
lfshook.NewLogger().Logger.Infof("=============Get filename : %v", filename)
|
|
|
/*
|
|
|
//update special voice
|
|
|
@@ -138,14 +141,15 @@ func SpecialAnn(data []byte) {
|
|
|
cycleCount := data[9]
|
|
|
datalen := int(data[10])
|
|
|
|
|
|
- filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
|
|
|
-
|
|
|
- //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())
|
|
|
- }
|
|
|
-
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ */
|
|
|
+ lfshook.NewLogger().Infof("======count:%x", cycleCount)
|
|
|
if int(cycleCount) == 255 {
|
|
|
action.PlaybackPacu(filename, 9999999, int(delay), "SPC")
|
|
|
} else {
|
|
|
@@ -159,14 +163,15 @@ func EmgMsg(data []byte) {
|
|
|
cycleCount := data[9]
|
|
|
datalen := int(data[10])
|
|
|
|
|
|
- filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
|
|
|
-
|
|
|
- //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())
|
|
|
- }
|
|
|
-
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ */
|
|
|
+ lfshook.NewLogger().Infof("======count:%x", cycleCount)
|
|
|
if int(cycleCount) == 255 {
|
|
|
action.PlaybackPacu(filename, 9999999, int(delay), "EMG")
|
|
|
} else {
|
|
|
@@ -191,11 +196,13 @@ func AnnStop(data [4]byte) {
|
|
|
for _, ext := range Pacus {
|
|
|
action.Hangup(ext)
|
|
|
}
|
|
|
- //update pa type
|
|
|
- _, er := mysql.DBOrmInstance.Cols("patype").In("exten", Pacus).Update(&model.Extension{PaType: ""})
|
|
|
- if er != nil {
|
|
|
- lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
- }
|
|
|
+ /*
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.Cols("patype").In("exten", Pacus).Update(&model.Extension{PaType: ""})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ }
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
// DCS 语音
|
|
|
@@ -204,14 +211,15 @@ func DcsAnn(data []byte) {
|
|
|
cycleCount := data[9]
|
|
|
datalen := int(data[10])
|
|
|
|
|
|
- filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
|
|
|
-
|
|
|
- //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())
|
|
|
- }
|
|
|
-
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ */
|
|
|
+ lfshook.NewLogger().Infof("======count:%x", cycleCount)
|
|
|
if int(cycleCount) == 255 {
|
|
|
action.PlaybackPacu(filename, 9999999, int(delay), "DCS")
|
|
|
} else {
|
|
|
@@ -227,13 +235,13 @@ func SelfCheck(data []byte) {
|
|
|
datalen := int(data[11])
|
|
|
|
|
|
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())
|
|
|
- }
|
|
|
-
|
|
|
+ /*
|
|
|
+ //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:
|
|
|
action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
|
|
|
@@ -267,28 +275,22 @@ func AlarmHandle(data []byte) {
|
|
|
// 只对 handler == 0x01 做 2 秒去重
|
|
|
if handler == 0x01 {
|
|
|
if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
|
|
|
- lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 2 seconds", exten)
|
|
|
+ lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
|
|
|
return // 已存在,说明在2秒窗口期内,直接丢弃
|
|
|
}
|
|
|
|
|
|
- // 设置2秒后删除该 key,允许下次通过
|
|
|
- time.AfterFunc(2*time.Second, func() {
|
|
|
+ // 设置4秒后删除该 key,允许下次通过
|
|
|
+ time.AfterFunc(4*time.Second, func() {
|
|
|
suppressedExts.Delete(key)
|
|
|
lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // 设置1秒后删除该 key,允许下次通过
|
|
|
- time.AfterFunc(1*time.Second, func() {
|
|
|
- suppressedExts.Delete(key)
|
|
|
- lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
|
|
|
- })
|
|
|
-
|
|
|
switch handler {
|
|
|
case 0x01: //answer(ICP+Alarm+PACU)
|
|
|
//NotifyPaiu(exten, "answer")
|
|
|
|
|
|
- action.Dial(PacuNum, "0402", "ani-rule", PacuNum, exten, "PJSIP") // PACU dial ICP
|
|
|
+ action.Dial("0402", PacuNum, "default", PacuNum, exten, "PJSIP") // PACU dial ICP
|
|
|
lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
|
|
|
//invite PACU join in
|
|
|
//action.Hangup("PACU")
|
|
|
@@ -303,16 +305,14 @@ func AlarmHandle(data []byte) {
|
|
|
lfshook.NewLogger().Logger.Infof("================OCC Answer PAD================:%s ", exten)
|
|
|
case 0x02: //hold 重新放回队列里面
|
|
|
NotifyPaiu(exten, "hold")
|
|
|
-
|
|
|
err := action.RedirectInQueue(exten, "0300", "default", "1")
|
|
|
if err != nil {
|
|
|
lfshook.NewLogger().Info(err)
|
|
|
}
|
|
|
-
|
|
|
+ action.Hangup("2311") //1 车接听
|
|
|
case 0x03: //hangup
|
|
|
//NotifyPaiu(exten, "hangup")
|
|
|
action.Hangup(exten)
|
|
|
-
|
|
|
action.Hangup("2311") //1 车接听
|
|
|
//action.Hangup("2381") //8 车接听
|
|
|
}
|
|
|
@@ -364,6 +364,8 @@ func AlarmResetAll() {
|
|
|
for _, ext := range AlarmExts {
|
|
|
action.Hangup(ext.Extension)
|
|
|
}
|
|
|
+
|
|
|
+ action.Hangup("2311")
|
|
|
}
|
|
|
|
|
|
func RecordStorageConf(data []byte) {
|