|
@@ -1,15 +1,18 @@
|
|
|
package broadcast
|
|
|
|
|
|
import (
|
|
|
- "bytes"
|
|
|
"fmt"
|
|
|
"net"
|
|
|
"pbx-api-gin/internal/app/ami/action"
|
|
|
"pbx-api-gin/internal/app/ami/model"
|
|
|
"pbx-api-gin/internal/app/mysql"
|
|
|
+ msgdata "pbx-api-gin/internal/app/stc/data"
|
|
|
"pbx-api-gin/pkg/lfshook"
|
|
|
)
|
|
|
|
|
|
+var BroadcastExtens = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
|
|
|
+var AlarmExtens = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
|
|
|
+
|
|
|
func HandleStcCmd(conn net.Conn) {
|
|
|
|
|
|
for {
|
|
@@ -25,61 +28,60 @@ func HandleStcCmd(conn net.Conn) {
|
|
|
case 0x01: //heartbeat
|
|
|
|
|
|
case 0x02: //STN
|
|
|
- StationAnn([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ StationAnn(buffer)
|
|
|
|
|
|
case 0x03: //ACTIVE
|
|
|
Active([1]byte{buffer[8]})
|
|
|
|
|
|
case 0x05: //SPC
|
|
|
- SpecialAnn([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ SpecialAnn(buffer)
|
|
|
|
|
|
case 0x06: //EMG
|
|
|
- EmgMsg([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ EmgMsg(buffer)
|
|
|
+
|
|
|
case 0x07: //STOP
|
|
|
AnnStop([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+
|
|
|
case 0x08: //DCS
|
|
|
- DcsAnn([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ DcsAnn(buffer)
|
|
|
+
|
|
|
case 0x09: //SELF CHECK
|
|
|
- SelfCheck([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ SelfCheck(buffer)
|
|
|
+
|
|
|
case 0x0a: //
|
|
|
- AlarmHandle([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ AlarmHandle(buffer[10:])
|
|
|
+
|
|
|
case 0x0b: //
|
|
|
- AlarmResetAll([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ AlarmResetAll()
|
|
|
+
|
|
|
case 0x0c: //
|
|
|
- RecordStorageConf([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
|
|
|
+ RecordStorageConf(buffer[8:])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- func SendToStc(conn net.Conn, buff []byte) {
|
|
|
- _, err := conn.Write(buff)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("send msg err:", err)
|
|
|
- }
|
|
|
- }
|
|
|
-*/
|
|
|
+// STN , 自动报站广播
|
|
|
+func StationAnn(data []byte) (err error) {
|
|
|
|
|
|
-func StationAnn(data [4]byte) (err error) {
|
|
|
- specialVoice := int(data[0])
|
|
|
- Exten := "2411"
|
|
|
- delay := data[1]
|
|
|
- cycleCount := data[2]
|
|
|
- timeLen := data[3]
|
|
|
+ specialVoice := int(data[8])
|
|
|
+ delay := data[9]
|
|
|
+ cycleCount := data[10]
|
|
|
+ datalen := int(data[11])
|
|
|
|
|
|
- filename := "welcome"
|
|
|
+ filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
|
|
|
|
|
|
//update special voice
|
|
|
- _, er := mysql.DBOrmInstance.Where("exten = ?", Exten).Update(&model.Extension{Special: specialVoice})
|
|
|
+ _, er := mysql.DBOrmInstance.In("exten", BroadcastExtens).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
|
|
|
}
|
|
|
|
|
|
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
|
|
|
+ action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// 激活信号
|
|
|
func Active(data [1]byte) {
|
|
|
|
|
|
Num := int(data[0])
|
|
@@ -93,105 +95,173 @@ func Active(data [1]byte) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func SpecialAnn(data [4]byte) {
|
|
|
- //specialVoice := int(data[0])
|
|
|
- Exten := "2411"
|
|
|
- delay := data[0]
|
|
|
- cycleCount := data[1]
|
|
|
- timeLen := data[2]
|
|
|
+// SPC ,特殊服务消息广播
|
|
|
+func SpecialAnn(data []byte) {
|
|
|
+
|
|
|
+ delay := data[8]
|
|
|
+ cycleCount := data[9]
|
|
|
+ datalen := int(data[10])
|
|
|
|
|
|
- filename := "welcome"
|
|
|
+ filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
|
|
|
+
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.In("exten", BroadcastExtens).Update(&model.Extension{PaType: "SPC"})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ }
|
|
|
|
|
|
if int(cycleCount) == 255 {
|
|
|
- action.Playback(filename, 9999999, Exten, int(timeLen), int(delay))
|
|
|
+ action.PlaybackPacu(filename, 9999999, int(delay), "SPC")
|
|
|
} else {
|
|
|
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
|
|
|
+ action.PlaybackPacu(filename, int(cycleCount), int(delay), "SPC")
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-func EmgMsg(data [4]byte) {
|
|
|
- //specialVoice := int(data[0])
|
|
|
- Exten := "2411"
|
|
|
- delay := data[0]
|
|
|
- cycleCount := data[1]
|
|
|
- timeLen := data[2]
|
|
|
+// EMG ,紧急服务消息广播
|
|
|
+func EmgMsg(data []byte) {
|
|
|
+ delay := data[8]
|
|
|
+ cycleCount := data[9]
|
|
|
+ datalen := int(data[10])
|
|
|
|
|
|
- filename := "welcome"
|
|
|
+ filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
|
|
|
+
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.In("exten", BroadcastExtens).Update(&model.Extension{PaType: "EMG"})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ }
|
|
|
|
|
|
if int(cycleCount) == 255 {
|
|
|
- action.Playback(filename, 9999999, Exten, int(timeLen), int(delay))
|
|
|
+ action.PlaybackPacu(filename, 9999999, int(delay), "EMG")
|
|
|
} else {
|
|
|
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
|
|
|
+ action.PlaybackPacu(filename, int(cycleCount), int(delay), "EMG")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 停止指定类型广播
|
|
|
func AnnStop(data [4]byte) {
|
|
|
- if data[0] == 0x03 {
|
|
|
- //asterisk.Hangup("2412")
|
|
|
- } else if data[0] == 0x04 {
|
|
|
- //asterisk.Hangup("2412")
|
|
|
- } else if data[0] == 0x07 {
|
|
|
- //asterisk.Hangup("2412")
|
|
|
- } else if data[0] == 0x08 {
|
|
|
- //asterisk.Hangup("2412")
|
|
|
- } else if data[0] == 0x09 {
|
|
|
- //asterisk.Hangup("2412")
|
|
|
+ switch data[0] {
|
|
|
+ case 0x03:
|
|
|
+
|
|
|
+ case 0x04:
|
|
|
+
|
|
|
+ case 0x07:
|
|
|
+
|
|
|
+ case 0x08:
|
|
|
+
|
|
|
+ case 0x09:
|
|
|
+
|
|
|
+ }
|
|
|
+ for _, ext := range BroadcastExtens {
|
|
|
+ action.Hangup(ext)
|
|
|
+ }
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.Cols("patype").In("exten", BroadcastExtens).Update(&model.Extension{PaType: ""})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func DcsAnn(data [4]byte) {
|
|
|
- Exten := "2411"
|
|
|
- delay := data[0]
|
|
|
- cycleCount := data[1]
|
|
|
- timeLen := data[2]
|
|
|
+// DCS 语音
|
|
|
+func DcsAnn(data []byte) {
|
|
|
+ delay := data[8]
|
|
|
+ cycleCount := data[9]
|
|
|
+ datalen := int(data[10])
|
|
|
|
|
|
- filename := "welcome"
|
|
|
+ filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
|
|
|
|
|
|
- if cycleCount == 255 {
|
|
|
- action.Playback(filename, 9999999, Exten, int(timeLen), int(delay))
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.In("exten", BroadcastExtens).Update(&model.Extension{PaType: "DCS"})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ if int(cycleCount) == 255 {
|
|
|
+ action.PlaybackPacu(filename, 9999999, int(delay), "DCS")
|
|
|
} else {
|
|
|
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
|
|
|
+ action.PlaybackPacu(filename, int(cycleCount), int(delay), "DCS")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func SelfCheck(data [4]byte) {
|
|
|
- check := data[0]
|
|
|
- delay := data[1]
|
|
|
- cycleCount := data[2]
|
|
|
- timeLen := data[3]
|
|
|
- filename := "welcome"
|
|
|
- Exten := ""
|
|
|
-
|
|
|
- if check == 0x01 {
|
|
|
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
|
|
|
- } else if check == 0x02 {
|
|
|
+// 自检广播
|
|
|
+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)
|
|
|
+
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.In("exten", BroadcastExtens).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")
|
|
|
+ case 0x02:
|
|
|
//asterisk.Hangup(Exten)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func AlarmHandle(data [4]byte) {
|
|
|
- handler := data[0]
|
|
|
- //len := data[1]
|
|
|
- //src := data[2]
|
|
|
+// ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
|
|
|
+func AlarmHandle(data []byte) {
|
|
|
+ handler := data[8]
|
|
|
+ extlen := data[9]
|
|
|
+ exten := msgdata.SubstrByRune(string(data[10:]), 0, int(extlen))
|
|
|
|
|
|
switch handler {
|
|
|
- case 0x01: //answer
|
|
|
+ case 0x01: //answer(ICP+Alarm+PACU==============================)
|
|
|
|
|
|
- case 0x02: //hold
|
|
|
+ err := action.Redirect(exten, "2311", "default") // 1车接听
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Info(err)
|
|
|
+ }
|
|
|
+ //invite PACU join in
|
|
|
+ //action.Hangup("PACU")
|
|
|
+ //action.ChanSpy("PACU", exten, false, true)
|
|
|
|
|
|
- case 0x03: //hangup
|
|
|
+ case 0x02: //hold 重新放回队列里面
|
|
|
+ err := action.Redirect(exten, "0300", "default")
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Info(err)
|
|
|
+ }
|
|
|
|
|
|
+ case 0x03: //hangup
|
|
|
+ action.Hangup(exten)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func AlarmResetAll(data [4]byte) {
|
|
|
+// 挂断所有报警器
|
|
|
+func AlarmResetAll() {
|
|
|
|
|
|
- if bytes.Equal(data[:], make([]byte, len(data))) {
|
|
|
- //reset all the alarm
|
|
|
+ var AlarmExts []model.Extension
|
|
|
+
|
|
|
+ er := mysql.DBOrmInstance.Where("exttype = ?", "PAIU").Find(&AlarmExts)
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-func RecordStorageConf(data [4]byte) {
|
|
|
+ for _, ext := range AlarmExts {
|
|
|
+ action.Hangup(ext.Extension)
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+func RecordStorageConf(data []byte) {
|
|
|
+ /*padRcd := data[0]
|
|
|
+ padRcdStorage := data[1]
|
|
|
+ paRcdStorage := data[2]
|
|
|
+ cpaRcdStorage := data[3]
|
|
|
+ padRcdDel := data[4]
|
|
|
+ PaRcdDel := data[5]
|
|
|
+ cpaRcdDel := data[6]
|
|
|
+
|
|
|
+ //update pa type
|
|
|
+ _, er := mysql.DBOrmInstance.In("exten", BroadcastExtens).Update(&model.Extension{PaType: "CHK"})
|
|
|
+ if er != nil {
|
|
|
+ lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
|
|
|
+ }
|
|
|
+ */
|
|
|
}
|