|
@@ -7,22 +7,15 @@ import (
|
|
|
"io"
|
|
"io"
|
|
|
"net"
|
|
"net"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
- "os"
|
|
|
|
|
"pbx-api-gin/internal/app/ami/action"
|
|
"pbx-api-gin/internal/app/ami/action"
|
|
|
- "pbx-api-gin/internal/app/ami/model"
|
|
|
|
|
"pbx-api-gin/internal/app/stc/active"
|
|
"pbx-api-gin/internal/app/stc/active"
|
|
|
msgdata "pbx-api-gin/internal/app/stc/data"
|
|
msgdata "pbx-api-gin/internal/app/stc/data"
|
|
|
"pbx-api-gin/internal/app/stc/priority"
|
|
"pbx-api-gin/internal/app/stc/priority"
|
|
|
alstatus "pbx-api-gin/internal/app/stc/sendstatus"
|
|
alstatus "pbx-api-gin/internal/app/stc/sendstatus"
|
|
|
"pbx-api-gin/pkg/lfshook"
|
|
"pbx-api-gin/pkg/lfshook"
|
|
|
- "sort"
|
|
|
|
|
"strconv"
|
|
"strconv"
|
|
|
- "strings"
|
|
|
|
|
"sync"
|
|
"sync"
|
|
|
"time"
|
|
"time"
|
|
|
-
|
|
|
|
|
- "github.com/sirupsen/logrus"
|
|
|
|
|
- "gopkg.in/ini.v1"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
@@ -61,12 +54,6 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
|
// 处理单个数据包(原 switch 逻辑迁移过来)
|
|
// 处理单个数据包(原 switch 逻辑迁移过来)
|
|
|
func processPacket(packet []byte) {
|
|
func processPacket(packet []byte) {
|
|
|
|
|
|
|
|
- //check if Master role
|
|
|
|
|
- if !active.Master {
|
|
|
|
|
- lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if len(packet) < 6 {
|
|
if len(packet) < 6 {
|
|
|
fmt.Println("Invalid packet length")
|
|
fmt.Println("Invalid packet length")
|
|
|
return
|
|
return
|
|
@@ -79,138 +66,152 @@ func processPacket(packet []byte) {
|
|
|
|
|
|
|
|
//check if the cmd type is avtive
|
|
//check if the cmd type is avtive
|
|
|
if packet[5] == 0x03 { // ACTIVE
|
|
if packet[5] == 0x03 { // ACTIVE
|
|
|
- Active([1]byte{packet[8]})
|
|
|
|
|
|
|
+ Active([2]byte{packet[8], packet[9]})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //check if Master role
|
|
|
|
|
+ if !active.Master {
|
|
|
|
|
+ lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
switch packet[5] {
|
|
switch packet[5] {
|
|
|
case 0x01: //heartbeat
|
|
case 0x01: //heartbeat
|
|
|
-
|
|
|
|
|
- //PAD-OCC异常情况处理
|
|
|
|
|
- if priority.OCCAnswer == 1 {
|
|
|
|
|
- //定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
|
|
|
|
|
- resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- if resCaller.Calls != "0" {
|
|
|
|
|
- sort.Slice(resCaller.Entrys, func(i, j int) bool {
|
|
|
|
|
- return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- for _, caller := range resCaller.Entrys {
|
|
|
|
|
- priority.ICPAnswer = 0
|
|
|
|
|
- lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
|
|
|
|
|
- //order by pos
|
|
|
|
|
- action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
|
|
|
|
|
- time.Sleep(time.Microsecond * 200) //200 ms delay
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ //PAD-OCC异常情况处理
|
|
|
|
|
+ if priority.OCCAnswer == 1 {
|
|
|
|
|
+ //定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
|
|
|
|
|
+ resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if resCaller.Calls != "0" {
|
|
|
|
|
+ sort.Slice(resCaller.Entrys, func(i, j int) bool {
|
|
|
|
|
+ return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ for _, caller := range resCaller.Entrys {
|
|
|
|
|
+ priority.ICPAnswer = 0
|
|
|
|
|
+ lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
|
|
|
|
|
+ //order by pos
|
|
|
|
|
+ action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
|
|
|
|
|
+ time.Sleep(time.Microsecond * 200) //200 ms delay
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- //定时监测OCC queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
|
|
|
|
|
- res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- if res.Calls != "0" { //OCC queue is not empty
|
|
|
|
|
- // HangupAllLocalChan()
|
|
|
|
|
- lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
|
|
|
|
|
- if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
|
|
|
|
|
- time.Sleep(time.Second)
|
|
|
|
|
- PADChan := ""
|
|
|
|
|
- for _, chanEntry := range res.Entrys {
|
|
|
|
|
- lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
|
|
|
|
|
- if chanEntry.Position == "1" {
|
|
|
|
|
- PADChan = chanEntry.Channel
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ //定时监测OCC queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
|
|
|
|
|
+ res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if res.Calls != "0" { //OCC queue is not empty
|
|
|
|
|
+ // HangupAllLocalChan()
|
|
|
|
|
+ lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
|
|
|
|
|
+ if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
+ PADChan := ""
|
|
|
|
|
+ for _, chanEntry := range res.Entrys {
|
|
|
|
|
+ lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
|
|
|
|
|
+ if chanEntry.Position == "1" {
|
|
|
|
|
+ PADChan = chanEntry.Channel
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if PADChan != "" {
|
|
|
|
|
- alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
|
|
|
|
|
- go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
|
|
|
|
|
|
|
+ if PADChan != "" {
|
|
|
|
|
+ alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
|
|
|
|
|
+ go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
|
|
|
|
|
|
|
|
- go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
|
|
|
|
|
- } else {
|
|
|
|
|
- lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
|
|
|
|
|
- }
|
|
|
|
|
- break
|
|
|
|
|
- } else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
|
|
|
|
|
- time.Sleep(time.Second)
|
|
|
|
|
- PADChan := ""
|
|
|
|
|
- for _, chanEntry := range res.Entrys {
|
|
|
|
|
- lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
|
|
|
|
|
- if chanEntry.Position == "1" {
|
|
|
|
|
- PADChan = chanEntry.Channel
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
|
|
|
|
|
+ }
|
|
|
|
|
+ break
|
|
|
|
|
+ } else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
+ PADChan := ""
|
|
|
|
|
+ for _, chanEntry := range res.Entrys {
|
|
|
|
|
+ lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
|
|
|
|
|
+ if chanEntry.Position == "1" {
|
|
|
|
|
+ PADChan = chanEntry.Channel
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if PADChan != "" {
|
|
|
|
|
- alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
|
|
|
|
|
- go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
|
|
|
|
|
|
|
+ if PADChan != "" {
|
|
|
|
|
+ alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
|
|
|
|
|
+ go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
|
|
|
|
|
|
|
|
- go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
|
|
|
|
|
- } else {
|
|
|
|
|
- lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
|
|
|
|
|
|
|
+ go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
|
|
|
|
|
+ }
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
- break
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ */
|
|
|
|
|
+ break
|
|
|
case 0x02: // STN
|
|
case 0x02: // STN
|
|
|
- if priority.CheckPriority("STN") {
|
|
|
|
|
- action.HangupRunningTask("STN") //STN interrupt other
|
|
|
|
|
- StationAnn(packet)
|
|
|
|
|
- } else {
|
|
|
|
|
- alstatus.PaStatus("", "STN", "refuse")
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ if priority.CheckPriority("STN") {
|
|
|
|
|
+ action.HangupRunningTask("STN") //STN interrupt other
|
|
|
|
|
+ StationAnn(packet)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alstatus.PaStatus("", "STN", "refuse")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
case 0x05: // SPC
|
|
case 0x05: // SPC
|
|
|
- if priority.CheckPriority("SPC") {
|
|
|
|
|
- action.HangupRunningTask("SPC") //SPC interrupt other
|
|
|
|
|
- SpecialAnn(packet)
|
|
|
|
|
- } else {
|
|
|
|
|
- alstatus.PaStatus("", "SPC", "refuse")
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ if priority.CheckPriority("SPC") {
|
|
|
|
|
+ action.HangupRunningTask("SPC") //SPC interrupt other
|
|
|
|
|
+ SpecialAnn(packet)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alstatus.PaStatus("", "SPC", "refuse")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
case 0x06: // EMG
|
|
case 0x06: // EMG
|
|
|
- if priority.CheckPriority("EMG") {
|
|
|
|
|
- action.HangupRunningTask("EMG") //EMG interrupt other
|
|
|
|
|
- EmgMsg(packet)
|
|
|
|
|
- } else {
|
|
|
|
|
- alstatus.PaStatus("", "EMG", "refuse")
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ if priority.CheckPriority("EMG") {
|
|
|
|
|
+ action.HangupRunningTask("EMG") //EMG interrupt other
|
|
|
|
|
+ EmgMsg(packet)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alstatus.PaStatus("", "EMG", "refuse")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
case 0x07: // STOP
|
|
case 0x07: // STOP
|
|
|
AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
|
|
AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
|
|
|
|
|
|
|
|
case 0x08: // DCS
|
|
case 0x08: // DCS
|
|
|
- if priority.CheckPriority("DCS") {
|
|
|
|
|
- action.HangupRunningTask("DCS") //DCS interrupt other
|
|
|
|
|
- DcsAnn(packet)
|
|
|
|
|
- } else {
|
|
|
|
|
- alstatus.PaStatus("", "DCS", "refuse")
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ if priority.CheckPriority("DCS") {
|
|
|
|
|
+ action.HangupRunningTask("DCS") //DCS interrupt other
|
|
|
|
|
+ DcsAnn(packet)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alstatus.PaStatus("", "DCS", "refuse")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
case 0x09: // SELF CHECK
|
|
case 0x09: // SELF CHECK
|
|
|
- if priority.CheckPriority("CHK") {
|
|
|
|
|
- action.HangupRunningTask("CHK") //CHK interrupt other
|
|
|
|
|
- SelfCheck(packet)
|
|
|
|
|
- } else {
|
|
|
|
|
- alstatus.PaStatus("", "CHK", "refuse")
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ if priority.CheckPriority("CHK") {
|
|
|
|
|
+ action.HangupRunningTask("CHK") //CHK interrupt other
|
|
|
|
|
+ SelfCheck(packet)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alstatus.PaStatus("", "CHK", "refuse")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
case 0x0a: // Tone-test
|
|
case 0x0a: // Tone-test
|
|
|
- if priority.CheckPriority("VOL") {
|
|
|
|
|
- action.HangupRunningTask("VOL") //VOL interrupt other
|
|
|
|
|
- ToneTest(packet)
|
|
|
|
|
- } else {
|
|
|
|
|
- alstatus.PaStatus("", "VOL", "refuse")
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ if priority.CheckPriority("VOL") {
|
|
|
|
|
+ action.HangupRunningTask("VOL") //VOL interrupt other
|
|
|
|
|
+ ToneTest(packet)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alstatus.PaStatus("", "VOL", "refuse")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
case 0x0e: //TMS answer PAD
|
|
case 0x0e: //TMS answer PAD
|
|
|
if priority.CheckPriority("PAD-TMS") {
|
|
if priority.CheckPriority("PAD-TMS") {
|
|
|
action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
|
|
action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
|
|
@@ -224,8 +225,8 @@ func processPacket(packet []byte) {
|
|
|
case 0x0b: // reset all PAD
|
|
case 0x0b: // reset all PAD
|
|
|
AlarmHoldResetAll(packet[8]) // reset all pad
|
|
AlarmHoldResetAll(packet[8]) // reset all pad
|
|
|
|
|
|
|
|
- case 0x0c: // recored config
|
|
|
|
|
- RecordStorageConf(packet[8:]) // RCD setting
|
|
|
|
|
|
|
+ //case 0x0c: // recored config
|
|
|
|
|
+ // RecordStorageConf(packet[8:]) // RCD setting
|
|
|
|
|
|
|
|
case 0x0d: // ICP answer PAD
|
|
case 0x0d: // ICP answer PAD
|
|
|
if priority.CheckPriority("PAD-ICP") {
|
|
if priority.CheckPriority("PAD-ICP") {
|
|
@@ -260,13 +261,24 @@ func StationAnn(data []byte) (err error) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 激活信号
|
|
// 激活信号
|
|
|
-func Active(data [1]byte) {
|
|
|
|
|
|
|
+func Active(data [2]byte) {
|
|
|
|
|
|
|
|
//var info model.Sysinfo
|
|
//var info model.Sysinfo
|
|
|
//active.Actived = true
|
|
//active.Actived = true
|
|
|
Signal := int(data[0])
|
|
Signal := int(data[0])
|
|
|
|
|
+ Master := int(data[1])
|
|
|
//lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
|
|
//lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
|
|
|
|
|
|
|
|
|
|
+ if !active.Master && active.CabNum == "8" { //slave role , check the Master data from STC
|
|
|
|
|
+ if Master == 8 {
|
|
|
|
|
+ active.Master = true
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if !active.Master && active.CabNum == "1" {
|
|
|
|
|
+ if Master == 1 {
|
|
|
|
|
+ active.Master = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
switch Signal {
|
|
switch Signal {
|
|
|
case 0:
|
|
case 0:
|
|
|
|
|
|
|
@@ -277,17 +289,11 @@ func Active(data [1]byte) {
|
|
|
case 1:
|
|
case 1:
|
|
|
active.ActivedCab = "1"
|
|
active.ActivedCab = "1"
|
|
|
//lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
|
|
//lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
|
|
|
- if active.CabNum == "8" { // local cab is MC1
|
|
|
|
|
- action.InActiveHangup()
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
case 8:
|
|
case 8:
|
|
|
|
|
|
|
|
active.ActivedCab = "8"
|
|
active.ActivedCab = "8"
|
|
|
//lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
|
|
//lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
|
|
|
- if active.CabNum == "1" { //Local cab is MC8
|
|
|
|
|
- action.InActiveHangup()
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -600,6 +606,7 @@ func AlarmHoldResetAll(handler byte) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
func RecordStorageConf(data []byte) {
|
|
func RecordStorageConf(data []byte) {
|
|
|
|
|
|
|
|
var info model.RcdConf
|
|
var info model.RcdConf
|
|
@@ -639,3 +646,4 @@ func RecordStorageConf(data []byte) {
|
|
|
iniFile.SaveTo(filePath)
|
|
iniFile.SaveTo(filePath)
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+*/
|