|
@@ -3,20 +3,26 @@ package broadcast
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
"context"
|
|
"context"
|
|
|
|
|
+ "encoding/binary"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"io"
|
|
"io"
|
|
|
"net"
|
|
"net"
|
|
|
|
|
+ "os/exec"
|
|
|
"pbx-api-gin/internal/app/ami/action"
|
|
"pbx-api-gin/internal/app/ami/action"
|
|
|
"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"
|
|
|
|
|
+ "pbx-api-gin/pkg/utils"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
"sync"
|
|
"sync"
|
|
|
|
|
+ "syscall"
|
|
|
"time"
|
|
"time"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var tagLog = 0
|
|
|
|
|
+
|
|
|
func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
|
|
|
|
|
|
for {
|
|
for {
|
|
@@ -38,15 +44,96 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
|
}
|
|
}
|
|
|
buf.Write(tmp[:n])
|
|
buf.Write(tmp[:n])
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ //lfshook.NewLogger().Logger.Infof("buf:%x==============================", buf.Bytes())
|
|
|
for {
|
|
for {
|
|
|
packet, err := msgdata.ExtractPacket(&buf)
|
|
packet, err := msgdata.ExtractPacket(&buf)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
|
+ utils.LoggerDebug.Printf("Parse error: %v, resetting buffer", err)
|
|
|
|
|
+ buf.Reset() // 解析失败,清空避免污染
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
|
|
+ if packet == nil {
|
|
|
|
|
+ break // 当前无完整包,等待下次 ReadFrom
|
|
|
|
|
+ }
|
|
|
|
|
+ //处理 packet...
|
|
|
go processPacket(packet)
|
|
go processPacket(packet)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 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)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -54,194 +141,305 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
|
|
|
func processPacket(packet []byte) {
|
|
func processPacket(packet []byte) {
|
|
|
|
|
|
|
|
if len(packet) < 6 {
|
|
if len(packet) < 6 {
|
|
|
- fmt.Println("Invalid packet length")
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("Get data wrong length from STC ! Data:%x", packet)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//for recv data log debug
|
|
//for recv data log debug
|
|
|
if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
|
|
if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
|
|
|
- lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("Get data from STC:%x", packet)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//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([2]byte{packet[8], packet[9]})
|
|
|
|
|
|
|
+ Active([3]byte{packet[8], packet[9], packet[10]})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//check if Master role
|
|
//check if Master role
|
|
|
if !active.Master {
|
|
if !active.Master {
|
|
|
- lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
|
|
|
|
|
|
|
+ if tagLog == 0 {
|
|
|
|
|
+ utils.LoggerDebug.Printf("Not Master Role , Ignore all data from STC !")
|
|
|
|
|
+ tagLog = 1
|
|
|
|
|
+ }
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ tagLog = 0
|
|
|
|
|
|
|
|
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
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
- //定时监测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)
|
|
|
|
|
-
|
|
|
|
|
- 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)
|
|
|
|
|
-
|
|
|
|
|
- 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
|
|
|
|
|
case 0x02: // STN
|
|
case 0x02: // STN
|
|
|
if active.ActivedCab != "" {
|
|
if active.ActivedCab != "" {
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("STN")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("STN") {
|
|
if priority.CheckPriority("STN") {
|
|
|
- action.HangupRunningTask("STN") //STN interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ runningTaskName := action.InterruptRunningTask("STN") //STN interrupt other
|
|
|
|
|
+ if runningTaskName != "" {
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ }
|
|
|
StationAnn(packet)
|
|
StationAnn(packet)
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "STN", "refuse")
|
|
alstatus.PaStatus("", "STN", "refuse")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "STN" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case 0x05: // SPC
|
|
case 0x05: // SPC
|
|
|
if active.ActivedCab != "" {
|
|
if active.ActivedCab != "" {
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("SPC")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("SPC") {
|
|
if priority.CheckPriority("SPC") {
|
|
|
- action.HangupRunningTask("SPC") //SPC interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ runningTaskName := action.InterruptRunningTask("SPC") //SPC interrupt other
|
|
|
|
|
+ if runningTaskName != "" {
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ }
|
|
|
SpecialAnn(packet)
|
|
SpecialAnn(packet)
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "SPC", "refuse")
|
|
alstatus.PaStatus("", "SPC", "refuse")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "SPC" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case 0x06: // EMG
|
|
case 0x06: // EMG
|
|
|
|
|
+
|
|
|
if active.ActivedCab != "" {
|
|
if active.ActivedCab != "" {
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("EMG")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("EMG") {
|
|
if priority.CheckPriority("EMG") {
|
|
|
- action.HangupRunningTask("EMG") //EMG interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ runningTaskName := action.InterruptRunningTask("EMG") //EMG interrupt other
|
|
|
|
|
+ if runningTaskName != "" {
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ }
|
|
|
EmgMsg(packet)
|
|
EmgMsg(packet)
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "EMG", "refuse")
|
|
alstatus.PaStatus("", "EMG", "refuse")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "EMG" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
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 active.ActivedCab != "" {
|
|
if active.ActivedCab != "" {
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("DCS")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("DCS") {
|
|
if priority.CheckPriority("DCS") {
|
|
|
- action.HangupRunningTask("DCS") //DCS interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ runningTaskName := action.InterruptRunningTask("DCS") //DCS interrupt other
|
|
|
|
|
+ if runningTaskName != "" {
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ }
|
|
|
DcsAnn(packet)
|
|
DcsAnn(packet)
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "DCS", "refuse")
|
|
alstatus.PaStatus("", "DCS", "refuse")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "DCS" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case 0x09: // SELF CHECK
|
|
case 0x09: // SELF CHECK
|
|
|
|
|
+
|
|
|
if active.ActivedCab != "" {
|
|
if active.ActivedCab != "" {
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("CHK")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("CHK") {
|
|
if priority.CheckPriority("CHK") {
|
|
|
- action.HangupRunningTask("CHK") //CHK interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ runningTaskName := action.InterruptRunningTask("CHK") //CHK interrupt other
|
|
|
|
|
+ if runningTaskName != "" {
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ }
|
|
|
SelfCheck(packet)
|
|
SelfCheck(packet)
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "CHK", "refuse")
|
|
alstatus.PaStatus("", "CHK", "refuse")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "CHK" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case 0x0a: // Tone-test
|
|
case 0x0a: // Tone-test
|
|
|
if active.ActivedCab != "" {
|
|
if active.ActivedCab != "" {
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("VOL")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("VOL") {
|
|
if priority.CheckPriority("VOL") {
|
|
|
- action.HangupRunningTask("VOL") //VOL interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ runningTaskName := action.InterruptRunningTask("VOL") //VOL interrupt other
|
|
|
|
|
+ if runningTaskName != "" {
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ }
|
|
|
ToneTest(packet)
|
|
ToneTest(packet)
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "VOL", "refuse")
|
|
alstatus.PaStatus("", "VOL", "refuse")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "VOL" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case 0x0e: //TMS answer PAD
|
|
case 0x0e: //TMS answer PAD
|
|
|
|
|
+
|
|
|
|
|
+ handler := packet[8]
|
|
|
|
|
+ key := suppressKey("exten", handler)
|
|
|
|
|
+
|
|
|
|
|
+ //Drop other handler in 2 sec
|
|
|
|
|
+ //PACUs---call---->ICP1
|
|
|
|
|
+ //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
|
|
|
|
|
+ if handler == 0x01 {
|
|
|
|
|
+ if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
|
|
|
|
|
+ utils.LoggerDebug.Printf("Suppressed duplicate ICP Alarm (handler=0x01) for PAD: within 2 seconds")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ time.AfterFunc(2*time.Second, func() {
|
|
|
|
|
+ suppressedExts.Delete(key)
|
|
|
|
|
+ utils.LoggerDebug.Printf("Suppression released .")
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("PAD-TMS")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("PAD-TMS") {
|
|
if priority.CheckPriority("PAD-TMS") {
|
|
|
- action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //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
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
AlarmHandleTMS(packet)
|
|
AlarmHandleTMS(packet)
|
|
|
- active.QueueTimer.Stop()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if active.QueueTimer != nil {
|
|
|
|
|
+ if active.QueueTimer.Stop() {
|
|
|
|
|
+ utils.LoggerDebug.Printf("Stop PAD timer true !")
|
|
|
|
|
+ } else {
|
|
|
|
|
+ utils.LoggerDebug.Printf("Stop PAD timer false !")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
alstatus.PaStatus("", "PAD-TMS", "refuse")
|
|
alstatus.PaStatus("", "PAD-TMS", "refuse")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "PAD-TMS" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
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: // Set PAD timeout
|
|
|
|
|
+ //lfshook.NewLogger().Logger.Infof("==type 0x0c===Get data from STC ====%x", packet)
|
|
|
|
|
+ PadTimeOutSetting(packet[8:]) // timeout setting
|
|
|
|
|
+
|
|
|
|
|
+ getInfofromSTC(packet[8:])
|
|
|
|
|
|
|
|
case 0x0d: // ICP answer PAD
|
|
case 0x0d: // ICP answer PAD
|
|
|
|
|
+
|
|
|
|
|
+ handler := packet[8]
|
|
|
|
|
+ key := suppressKey("exten", handler)
|
|
|
|
|
+
|
|
|
|
|
+ //Drop other handler in 2 sec
|
|
|
|
|
+ //PACUs---call---->ICP1
|
|
|
|
|
+ //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
|
|
|
|
|
+ if handler == 0x01 {
|
|
|
|
|
+ if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
|
|
|
|
|
+ utils.LoggerDebug.Printf("Suppressed duplicate ICP Alarm (handler=0x01) for PAD: within 2 seconds")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ time.AfterFunc(2*time.Second, func() {
|
|
|
|
|
+ suppressedExts.Delete(key)
|
|
|
|
|
+ utils.LoggerDebug.Printf("Suppression released for key: %s", key)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //检查是否有任务正在创建
|
|
|
|
|
+ action.WaitTaskCreate("PAD-ICP")
|
|
|
|
|
+
|
|
|
if priority.CheckPriority("PAD-ICP") {
|
|
if priority.CheckPriority("PAD-ICP") {
|
|
|
|
|
|
|
|
- action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
|
|
|
|
|
- active.QueueTimer.Stop()
|
|
|
|
|
- AlarmHandleICP(packet) //
|
|
|
|
|
|
|
+ //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 {
|
|
} else {
|
|
|
alstatus.PaStatus("", "PAD-ICP", "refuse")
|
|
alstatus.PaStatus("", "PAD-ICP", "refuse")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
|
+ if priority.TaskCreating == "PAD-ICP" {
|
|
|
|
|
+ priority.TaskCreating = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //case 0xf1: //Set remote master
|
|
|
|
|
+
|
|
|
//default:
|
|
//default:
|
|
|
//fmt.Printf("Unknown command: %x\n", packet[5])
|
|
//fmt.Printf("Unknown command: %x\n", packet[5])
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func PadTimeOutSetting(data []byte) {
|
|
|
|
|
+
|
|
|
|
|
+ Seconds := data[7]
|
|
|
|
|
+ if Seconds != 0 {
|
|
|
|
|
+ active.PADTimeout = int(Seconds)
|
|
|
|
|
+ //lfshook.NewLogger().Logger.Infof("=========Set PAD Timeout seconds to %d ! ============", active.PADTimeout)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// STN , 自动报站广播
|
|
// STN , 自动报站广播
|
|
|
func StationAnn(data []byte) (err error) {
|
|
func StationAnn(data []byte) (err error) {
|
|
|
|
|
|
|
@@ -255,44 +453,121 @@ func StationAnn(data []byte) (err error) {
|
|
|
//set spc voice tag
|
|
//set spc voice tag
|
|
|
priority.SpecialVoice = specialVoice
|
|
priority.SpecialVoice = specialVoice
|
|
|
|
|
|
|
|
|
|
+ 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), "STN")
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 激活信号
|
|
// 激活信号
|
|
|
-func Active(data [2]byte) {
|
|
|
|
|
|
|
+func Active(data [3]byte) {
|
|
|
|
|
|
|
|
//var info model.Sysinfo
|
|
//var info model.Sysinfo
|
|
|
- //active.Actived = true
|
|
|
|
|
Signal := int(data[0])
|
|
Signal := int(data[0])
|
|
|
- Master := int(data[1])
|
|
|
|
|
- //lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
|
|
|
|
|
|
|
+ master := int(data[1])
|
|
|
|
|
+ TrainInfo := int(data[2])
|
|
|
|
|
+
|
|
|
|
|
+ lfshook.NewLogger().Logger.Infof("=====active:%x======cab=%s Master=%d=====data:%x======", Signal, active.CabNum, master, data)
|
|
|
|
|
+
|
|
|
|
|
+ //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
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if !active.Master && active.CabNum == "8" { //slave role , check the Master data from STC
|
|
|
|
|
- if Master == 8 {
|
|
|
|
|
- active.Master = true
|
|
|
|
|
|
|
+ //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
|
|
|
}
|
|
}
|
|
|
- } else if !active.Master && active.CabNum == "1" {
|
|
|
|
|
- if Master == 1 {
|
|
|
|
|
- active.Master = true
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //Radio fault
|
|
|
|
|
+ RadioFault1 := TrainInfo & 0x03
|
|
|
|
|
+ RadioFault8 := TrainInfo & 0x0c
|
|
|
|
|
+ if RadioFault1 == 0 && RadioFault8 == 1 {
|
|
|
|
|
+ active.RadioFault = 1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ active.RadioFault = 0
|
|
|
}
|
|
}
|
|
|
|
|
+ utils.LoggerDebug.Printf("RadioFault1:%x RadioFault1:%x DevideInfo:%x", RadioFault1, RadioFault8, DevideInfo)
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
switch Signal {
|
|
switch Signal {
|
|
|
case 0:
|
|
case 0:
|
|
|
|
|
|
|
|
- //lfshook.NewLogger().Logger.Infof("=================Inactive==================")
|
|
|
|
|
- active.ActivedCab = ""
|
|
|
|
|
- action.InActiveHangup()
|
|
|
|
|
|
|
+ if active.ActivedCab != "" {
|
|
|
|
|
+ active.ActivedCab = ""
|
|
|
|
|
+ action.InActiveHangup()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
case 1:
|
|
case 1:
|
|
|
- active.ActivedCab = "1"
|
|
|
|
|
- //lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
|
|
|
|
|
|
|
+ //active signal from 8 to 1
|
|
|
|
|
+ if active.ActivedCab == "8" || active.ActivedCab == "" {
|
|
|
|
|
+ active.ActivedCab = "1"
|
|
|
|
|
+ action.InActiveHangup()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
case 8:
|
|
case 8:
|
|
|
|
|
+ //active signal from 1 to 8
|
|
|
|
|
+ if active.ActivedCab == "1" || active.ActivedCab == "" {
|
|
|
|
|
+ active.ActivedCab = "8"
|
|
|
|
|
+ action.InActiveHangup()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- active.ActivedCab = "8"
|
|
|
|
|
- //lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -305,6 +580,7 @@ func SpecialAnn(data []byte) {
|
|
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
|
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("Type:SPC FileName:%x Count:%x Interval:%+v", filename, cycleCount, delay)
|
|
|
if int(cycleCount) == 255 {
|
|
if int(cycleCount) == 255 {
|
|
|
action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
|
|
action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
|
|
|
} else {
|
|
} else {
|
|
@@ -320,9 +596,9 @@ func EmgMsg(data []byte) {
|
|
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
|
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("Type:EMG FileName:%x Count:%x Interval:%+v", filename, cycleCount, delay)
|
|
|
if int(cycleCount) == 255 {
|
|
if int(cycleCount) == 255 {
|
|
|
action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
|
|
action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
|
|
|
- priority.ResumeEmgPara = priority.BroadcastResumeParas{FileName: filename, Count: 99999999, Delay: int(delay), BroadcastType: "EMG"}
|
|
|
|
|
} else {
|
|
} else {
|
|
|
action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
|
|
action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
|
|
|
}
|
|
}
|
|
@@ -331,35 +607,37 @@ func EmgMsg(data []byte) {
|
|
|
// 停止指定类型广播
|
|
// 停止指定类型广播
|
|
|
func AnnStop(data [4]byte) {
|
|
func AnnStop(data [4]byte) {
|
|
|
|
|
|
|
|
- //PaType := ""
|
|
|
|
|
- lfshook.NewLogger().Logger.Infof("=AnnStop Type %x", data[0])
|
|
|
|
|
|
|
+ //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])
|
|
|
|
|
+
|
|
|
switch data[0] {
|
|
switch data[0] {
|
|
|
case 0x03:
|
|
case 0x03:
|
|
|
- if priority.RunningType == "DCS" {
|
|
|
|
|
- action.HangupRunningTask("") //STOP DCS
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("DCS") //STOP DCS
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
case 0x04:
|
|
case 0x04:
|
|
|
- if priority.RunningType == "EMG" {
|
|
|
|
|
- action.HangupRunningTask("AnnStop") //STOP EMG
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("EMG") //STOP EMG
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
case 0x07:
|
|
case 0x07:
|
|
|
- if priority.RunningType == "SPC" {
|
|
|
|
|
- action.HangupRunningTask("AnnStop") //STOP SPC
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("SPC") //STOP SPC
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
case 0x08:
|
|
case 0x08:
|
|
|
- if priority.RunningType == "STN" {
|
|
|
|
|
- action.HangupRunningTask("AnnStop") //STOP STN
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("STN") //STOP STN
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
case 0x09:
|
|
case 0x09:
|
|
|
- if priority.RunningType == "CHK" {
|
|
|
|
|
- action.HangupRunningTask("AnnStop") //STOP CHK
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("CHK") //STOP CHK
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
case 0x0a:
|
|
case 0x0a:
|
|
|
- if priority.RunningType == "VOL" {
|
|
|
|
|
- action.HangupRunningTask("AnnStop") //STOP VOL
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("VOL") //STOP VOL
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
default:
|
|
default:
|
|
|
- action.HangupRunningTask("AnnStop")
|
|
|
|
|
|
|
+ action.InterruptRunningTask("")
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -371,6 +649,7 @@ func DcsAnn(data []byte) {
|
|
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
|
|
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 {
|
|
if int(cycleCount) == 255 {
|
|
|
action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
|
|
action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
|
|
|
} else {
|
|
} else {
|
|
@@ -388,6 +667,7 @@ func ToneTest(data []byte) {
|
|
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
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 {
|
|
switch check {
|
|
|
case 0x01: //start
|
|
case 0x01: //start
|
|
|
action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
|
|
action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
|
|
@@ -402,20 +682,18 @@ func SelfCheck(data []byte) {
|
|
|
|
|
|
|
|
check := data[8]
|
|
check := data[8]
|
|
|
delay := data[9]
|
|
delay := data[9]
|
|
|
- //cycleCount := data[10]
|
|
|
|
|
- cycleCount := 0x32
|
|
|
|
|
|
|
+ cycleCount := data[10]
|
|
|
|
|
+ //cycleCount := 0x32
|
|
|
datalen := int(data[11])
|
|
datalen := int(data[11])
|
|
|
|
|
|
|
|
filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
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 {
|
|
switch check {
|
|
|
case 0x01: //start
|
|
case 0x01: //start
|
|
|
|
|
|
|
|
action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
|
|
action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
|
|
|
case 0x02: //stop
|
|
case 0x02: //stop
|
|
|
-
|
|
|
|
|
- //Pa status report
|
|
|
|
|
- //priority.CleanPriorityTag()
|
|
|
|
|
action.HangupAllExcept("")
|
|
action.HangupAllExcept("")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -438,32 +716,17 @@ func AlarmHandleICP(data []byte) {
|
|
|
pos := data[13]
|
|
pos := data[13]
|
|
|
exten := fmt.Sprintf("24%c%c", carr, pos)
|
|
exten := fmt.Sprintf("24%c%c", carr, pos)
|
|
|
|
|
|
|
|
- key := suppressKey(exten, handler)
|
|
|
|
|
-
|
|
|
|
|
- //Drop other handler in 2 sec
|
|
|
|
|
- //PACUs---call---->ICP1
|
|
|
|
|
- //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
|
|
|
|
|
- if handler == 0x01 {
|
|
|
|
|
- if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
|
|
|
|
|
- lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- time.AfterFunc(4*time.Second, func() {
|
|
|
|
|
- suppressedExts.Delete(key)
|
|
|
|
|
- lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("ICP Handle PAD:%s Action:%x (answer=1,hold=2,hangup=3)", exten, handler)
|
|
|
switch handler {
|
|
switch handler {
|
|
|
case 0x01: //answer(ICP+Alarm+PACU)
|
|
case 0x01: //answer(ICP+Alarm+PACU)
|
|
|
//NotifyPaiu(exten, "answer")
|
|
//NotifyPaiu(exten, "answer")
|
|
|
priority.ICPAnswer = 1
|
|
priority.ICPAnswer = 1
|
|
|
if priority.PADStart == 0 {
|
|
if priority.PADStart == 0 {
|
|
|
- alstatus.PaStatus(exten, "PAD", "start")
|
|
|
|
|
|
|
+ alstatus.PaStatus("", "PAD", "start")
|
|
|
priority.PADStart = 1
|
|
priority.PADStart = 1
|
|
|
}
|
|
}
|
|
|
- lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("ICP Answer PAD:%s .", exten)
|
|
|
|
|
+
|
|
|
if active.ActivedCab == "1" {
|
|
if active.ActivedCab == "1" {
|
|
|
action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
|
|
action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
|
|
|
//goto ami event ConfbridgeJoin, ICP answer PAD
|
|
//goto ami event ConfbridgeJoin, ICP answer PAD
|
|
@@ -475,20 +738,24 @@ func AlarmHandleICP(data []byte) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
case 0x02: //hold 重新放回队列里面
|
|
case 0x02: //hold 重新放回队列里面
|
|
|
|
|
+ utils.LoggerDebug.Printf("ICP Hold PAD-ICP PAD:%s !", exten)
|
|
|
active.NotifyPaiu(exten, "hold")
|
|
active.NotifyPaiu(exten, "hold")
|
|
|
err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
|
|
err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- lfshook.NewLogger().Info(err)
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("RedirectInQueue err:%+v", err)
|
|
|
}
|
|
}
|
|
|
- action.HangupAllLocalChan()
|
|
|
|
|
|
|
+ action.InterruptRunningTask("")
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
|
|
+ //action.HangupICP()
|
|
|
|
|
|
|
|
case 0x03: //hangup
|
|
case 0x03: //hangup
|
|
|
//NotifyPaiu(exten, "hangup")
|
|
//NotifyPaiu(exten, "hangup")
|
|
|
- lfshook.NewLogger().Logger.Infof("=============STC== Hangup PAD=============== ")
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("STC Hangup PAD-ICP !")
|
|
|
action.Hangup(exten) //Pad
|
|
action.Hangup(exten) //Pad
|
|
|
- action.HangupAllLocalChan()
|
|
|
|
|
- action.HangupICP()
|
|
|
|
|
- priority.CleanPriorityTag()
|
|
|
|
|
|
|
+ //action.HangupICP()
|
|
|
|
|
+
|
|
|
|
|
+ action.HangupTask("PAD-ICP")
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -499,117 +766,60 @@ func AlarmHandleTMS(data []byte) {
|
|
|
carr := data[12]
|
|
carr := data[12]
|
|
|
pos := data[13]
|
|
pos := data[13]
|
|
|
exten := fmt.Sprintf("24%c%c", carr, pos)
|
|
exten := fmt.Sprintf("24%c%c", carr, pos)
|
|
|
- PacuNum := fmt.Sprintf("21%c%c", carr, pos)
|
|
|
|
|
-
|
|
|
|
|
- key := suppressKey(exten, handler)
|
|
|
|
|
-
|
|
|
|
|
- //Drop other handler in 2 sec
|
|
|
|
|
- // 只对 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 4 seconds", exten)
|
|
|
|
|
- return // 已存在,说明在2秒窗口期内,直接丢弃
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ PacuNum := fmt.Sprintf("21%c1", carr)
|
|
|
|
|
|
|
|
- // 设置4秒后删除该 key,允许下次通过
|
|
|
|
|
- time.AfterFunc(4*time.Second, func() {
|
|
|
|
|
- suppressedExts.Delete(key)
|
|
|
|
|
- lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("TMS Handle PAD:%s PACU:%s Action:%x (answer=1,hold=2,hangup=3)", exten, PacuNum, handler)
|
|
|
|
|
|
|
|
switch handler {
|
|
switch handler {
|
|
|
case 0x01: //answer(ICP+Alarm+PACU)
|
|
case 0x01: //answer(ICP+Alarm+PACU)
|
|
|
//PACU---call---->ICP1
|
|
//PACU---call---->ICP1
|
|
|
//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
|
|
//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
|
|
|
if priority.PADStart == 0 {
|
|
if priority.PADStart == 0 {
|
|
|
- alstatus.PaStatus(exten, "PAD", "start")
|
|
|
|
|
|
|
+ alstatus.PaStatus("", "PAD", "start")
|
|
|
priority.PADStart = 1
|
|
priority.PADStart = 1
|
|
|
}
|
|
}
|
|
|
priority.ICPAnswer = 1
|
|
priority.ICPAnswer = 1
|
|
|
- lfshook.NewLogger().Logger.Infof("================TMS Answer PAD:%s===PACU:%s==========", exten, PacuNum)
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("TMS Answer PAD:%s PACU:%s", exten, PacuNum)
|
|
|
|
|
+
|
|
|
if action.ExtenStatus(PacuNum) == "Idle" {
|
|
if action.ExtenStatus(PacuNum) == "Idle" {
|
|
|
if active.ActivedCab == "1" {
|
|
if active.ActivedCab == "1" {
|
|
|
- action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
|
|
|
|
|
|
|
+ action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "1") // PACU dial ICP1
|
|
|
//goto ami event BridgeEnter, ICP8 whisper ICP1
|
|
//goto ami event BridgeEnter, ICP8 whisper ICP1
|
|
|
} else if active.ActivedCab == "8" {
|
|
} else if active.ActivedCab == "8" {
|
|
|
- action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
|
|
|
|
|
|
|
+ action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "8") // PACU dial ICP8
|
|
|
//goto ami event BridgeEnter, ICP1 whisper ICP8
|
|
//goto ami event BridgeEnter, ICP1 whisper ICP8
|
|
|
|
|
+ } else if active.ActivedCab == "" { // No cab occupied
|
|
|
|
|
+ action.Dial("0403", PacuNum, "pad-tms-dial-pacu", PacuNum, exten, "1") // PACU dial ICP1
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
|
|
action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
case 0x02: //hold 重新放回队列里面
|
|
case 0x02: //hold 重新放回队列里面
|
|
|
|
|
+ utils.LoggerDebug.Printf("ICP Hold PAD-TMS PAD:%s !", exten)
|
|
|
active.NotifyPaiu(exten, "hold")
|
|
active.NotifyPaiu(exten, "hold")
|
|
|
err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
|
|
err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- lfshook.NewLogger().Info(err)
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("RedirectInQueue err:%+v", err)
|
|
|
}
|
|
}
|
|
|
action.HangupAllLocalChan()
|
|
action.HangupAllLocalChan()
|
|
|
|
|
|
|
|
case 0x03: //hangup
|
|
case 0x03: //hangup
|
|
|
//NotifyPaiu(exten, "hangup")
|
|
//NotifyPaiu(exten, "hangup")
|
|
|
|
|
+ utils.LoggerDebug.Printf("STC Hangup PAD-TMS !")
|
|
|
action.Hangup(exten) //Pad
|
|
action.Hangup(exten) //Pad
|
|
|
- action.HangupAllLocalChan()
|
|
|
|
|
- action.HangupICP()
|
|
|
|
|
- priority.CleanPriorityTag()
|
|
|
|
|
|
|
+ action.HangupTask("PAD-TMS")
|
|
|
|
|
+ //action.HangupTask("PAD-ICP")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 挂断所有报警器
|
|
// 挂断所有报警器
|
|
|
func AlarmHoldResetAll(handler byte) {
|
|
func AlarmHoldResetAll(handler byte) {
|
|
|
-
|
|
|
|
|
- //all hold
|
|
|
|
|
-
|
|
|
|
|
|
|
+ utils.LoggerDebug.Printf("Alarm Hold/Reset All !")
|
|
|
//hangup all actived PAD
|
|
//hangup all actived PAD
|
|
|
action.HangupAllPAD()
|
|
action.HangupAllPAD()
|
|
|
|
|
|
|
|
//hangup running task
|
|
//hangup running task
|
|
|
- if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-TMS" {
|
|
|
|
|
- action.HangupRunningTask("AlarmHoldResetAll") //Reset PAD ALL
|
|
|
|
|
- priority.CleanPriorityTag()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/*
|
|
|
|
|
-func RecordStorageConf(data []byte) {
|
|
|
|
|
-
|
|
|
|
|
- var info model.RcdConf
|
|
|
|
|
-
|
|
|
|
|
- info.PadRcdEnable = strconv.Itoa(int(data[0]))
|
|
|
|
|
- info.PadRcdStorageDays = strconv.Itoa(int(data[1]))
|
|
|
|
|
- info.PaRcdStorageDays = strconv.Itoa(int(data[2]))
|
|
|
|
|
- info.CpaRcdStorageDays = strconv.Itoa(int(data[3]))
|
|
|
|
|
-
|
|
|
|
|
- info.PadRcdDelDays = strconv.Itoa(int(data[4]))
|
|
|
|
|
- info.PaRcdDelDays = strconv.Itoa(int(data[5]))
|
|
|
|
|
- info.CpaRcdDelDays = strconv.Itoa(int(data[6]))
|
|
|
|
|
- //info.OpaRcdStorageDays = int(data[7])
|
|
|
|
|
- //info.OpaRcdDelDays = int(data[8])
|
|
|
|
|
-
|
|
|
|
|
- //lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
|
|
|
|
|
-
|
|
|
|
|
- filePath := "/etc/asterisk/recording.conf"
|
|
|
|
|
- _, err := os.Stat(filePath)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logrus.Error(err)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- iniFile, err := ini.Load(filePath)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logrus.Error(err)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- iniFile.Section("general").Key("PADRCD").SetValue(info.PadRcdEnable)
|
|
|
|
|
- iniFile.Section("general").Key("PADRCDDAYS").SetValue(info.PadRcdStorageDays)
|
|
|
|
|
- iniFile.Section("general").Key("PARCDDAYS").SetValue(info.PaRcdStorageDays)
|
|
|
|
|
- iniFile.Section("general").Key("CPARCDDAYS").SetValue(info.CpaRcdStorageDays)
|
|
|
|
|
- iniFile.Section("general").Key("PADRCDDELDAYS").SetValue(info.PadRcdDelDays)
|
|
|
|
|
- iniFile.Section("general").Key("PARCDDELDAYS").SetValue(info.PaRcdDelDays)
|
|
|
|
|
- iniFile.Section("general").Key("CPARCDDELDAYS").SetValue(info.CpaRcdDelDays)
|
|
|
|
|
- iniFile.SaveTo(filePath)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ action.InterruptRunningTask("AlarmHoldResetAll") //Reset PAD ALL
|
|
|
|
|
+ time.Sleep(time.Millisecond * 100) //wait endpoint release
|
|
|
}
|
|
}
|
|
|
-*/
|
|
|