123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- 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"
- "pbx-api-gin/pkg/lfshook"
- )
- func HandleStcCmd(conn net.Conn) {
- for {
- buffer := make([]byte, 1024)
- n, err := conn.Read(buffer)
- if err != nil {
- fmt.Println("Error reading from server:", err)
- return
- }
- fmt.Println("Received from server:", string(buffer[:n]))
- switch buffer[5] {
- case 0x01: //heartbeat
- case 0x02: //STN
- StationAnn([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- case 0x03: //ACTIVE
- Active([1]byte{buffer[8]})
- case 0x05: //SPC
- SpecialAnn([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- case 0x06: //EMG
- EmgMsg([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- 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]})
- case 0x09: //SELF CHECK
- SelfCheck([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- case 0x0a: //
- AlarmHandle([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- case 0x0b: //
- AlarmResetAll([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- case 0x0c: //
- RecordStorageConf([4]byte{buffer[8], buffer[9], buffer[10], buffer[11]})
- }
- }
- }
- /*
- func SendToStc(conn net.Conn, buff []byte) {
- _, err := conn.Write(buff)
- if err != nil {
- fmt.Println("send msg err:", err)
- }
- }
- */
- func StationAnn(data [4]byte) (err error) {
- specialVoice := int(data[0])
- Exten := "2411"
- delay := data[1]
- cycleCount := data[2]
- timeLen := data[3]
- filename := "welcome"
- //update special voice
- _, er := mysql.DBOrmInstance.Where("exten = ?", Exten).Update(&model.Extension{Special: specialVoice})
- 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))
- return nil
- }
- func Active(data [1]byte) {
- Num := int(data[0])
- switch Num { // 设置全局的激活信号,并通过协议(待定)通知终端注册到对应的激活主机上
- case 0:
- case 1:
- case 8:
- case 9:
- }
- }
- func SpecialAnn(data [4]byte) {
- //specialVoice := int(data[0])
- Exten := "2411"
- delay := data[0]
- cycleCount := data[1]
- timeLen := data[2]
- filename := "welcome"
- if int(cycleCount) == 255 {
- action.Playback(filename, 9999999, Exten, int(timeLen), int(delay))
- } else {
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
- }
- }
- func EmgMsg(data [4]byte) {
- //specialVoice := int(data[0])
- Exten := "2411"
- delay := data[0]
- cycleCount := data[1]
- timeLen := data[2]
- filename := "welcome"
- if int(cycleCount) == 255 {
- action.Playback(filename, 9999999, Exten, int(timeLen), int(delay))
- } else {
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
- }
- }
- 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")
- }
- }
- func DcsAnn(data [4]byte) {
- Exten := "2411"
- delay := data[0]
- cycleCount := data[1]
- timeLen := data[2]
- filename := "welcome"
- if cycleCount == 255 {
- action.Playback(filename, 9999999, Exten, int(timeLen), int(delay))
- } else {
- action.Playback(filename, int(cycleCount), Exten, int(timeLen), int(delay))
- }
- }
- 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 {
- //asterisk.Hangup(Exten)
- }
- }
- func AlarmHandle(data [4]byte) {
- handler := data[0]
- //len := data[1]
- //src := data[2]
- switch handler {
- case 0x01: //answer
- case 0x02: //hold
- case 0x03: //hangup
- }
- }
- func AlarmResetAll(data [4]byte) {
- if bytes.Equal(data[:], make([]byte, len(data))) {
- //reset all the alarm
- }
- }
- func RecordStorageConf(data [4]byte) {
- }
|