stc-broadcast.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. package broadcast
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/binary"
  6. "fmt"
  7. "io"
  8. "log"
  9. "net"
  10. "pbx-api-gin/internal/app/ami/action"
  11. "pbx-api-gin/internal/app/stc/active"
  12. msgdata "pbx-api-gin/internal/app/stc/data"
  13. "pbx-api-gin/internal/app/stc/priority"
  14. alstatus "pbx-api-gin/internal/app/stc/sendstatus"
  15. "pbx-api-gin/pkg/lfshook"
  16. "pbx-api-gin/pkg/utils"
  17. "strconv"
  18. "sync"
  19. "time"
  20. )
  21. var tagLog = 0
  22. func HandleStcCmd(ctx context.Context, conn net.Conn) {
  23. for {
  24. select {
  25. case <-ctx.Done():
  26. return
  27. default:
  28. var buf bytes.Buffer
  29. tmp := make([]byte, 1024)
  30. if conn != nil {
  31. n, err := conn.Read(tmp)
  32. if err != nil {
  33. if err != io.EOF {
  34. conn.Close()
  35. }
  36. return
  37. }
  38. buf.Write(tmp[:n])
  39. }
  40. /*for {
  41. packet, err := msgdata.ExtractPacket(&buf)
  42. if err != nil {
  43. lfshook.NewLogger().Logger.Infof("ExtractPacket:%+v", err)
  44. break
  45. }
  46. go processPacket(packet)
  47. }*/
  48. //lfshook.NewLogger().Logger.Infof("buf:%x==============================", buf.Bytes())
  49. for {
  50. packet, err := msgdata.ExtractPacket(&buf)
  51. if err != nil {
  52. log.Printf("parse error: %v, resetting buffer", err)
  53. buf.Reset() // 解析失败,清空避免污染
  54. break
  55. }
  56. if packet == nil {
  57. break // 当前无完整包,等待下次 ReadFrom
  58. }
  59. //处理 packet...
  60. go processPacket(packet)
  61. }
  62. }
  63. }
  64. }
  65. // get train info and pacu info from heartbeat
  66. func processHeartbeat(info []byte) {
  67. //dataCount := info[0]
  68. //Get train info
  69. value := binary.BigEndian.Uint16(info[2:4]) //info[2] + info[3]
  70. active.TrainNum = "TS" + strconv.Itoa(int(value))
  71. //lfshook.NewLogger().Logger.Infof("TrainNum: %s", active.TrainNum)
  72. //Get ICP volume
  73. icpBit8 := info[9] & 0xF
  74. icpBit1 := (info[9] >> 4) & 0xF
  75. active.DeviceEndpoint.ICPInfo[0].Volume = fmt.Sprintf("%d", icpBit1)
  76. active.DeviceEndpoint.ICPInfo[0].ID = "1"
  77. active.DeviceEndpoint.ICPInfo[1].Volume = fmt.Sprintf("%d", icpBit8)
  78. active.DeviceEndpoint.ICPInfo[1].ID = "8"
  79. //Get Pacu info
  80. eidsStat := info[1] //PACU mute
  81. pacuStat := info[4] //PACU status
  82. pacuVolume := binary.BigEndian.Uint32(info[5:9]) //info[5]-info[8]
  83. //lfshook.NewLogger().Logger.Infof("=eidsStat:%x=======pacuStat:%x=====", eidsStat, pacuStat)
  84. for i := 0; i < 8; i++ {
  85. eidsBit := (eidsStat >> i) & 0x01 // 右移 i 位,再与 1 取最低位
  86. //fmt.Printf("eidsBit bit %d = %d\n", i, eidsBit) // bit 0 是 LSB(最低位,最右)
  87. //get 1 bit every time
  88. pacuStatBit := (pacuStat >> i) & 0x01
  89. //fmt.Printf("pacuStatBit bit %d = %d\n", i, pacuStatBit)
  90. //get 4 bit every time
  91. var pacuVolBit int8
  92. pacuVolBit = int8((pacuVolume >> i) & 0xF)
  93. //fmt.Printf("pacuVolBit bit %d = %x\n", i, pacuVolBit)
  94. active.DeviceEndpoint.PacuInfo[i].ID = strconv.Itoa(i + 1)
  95. if eidsBit == 1 {
  96. active.DeviceEndpoint.PacuInfo[i].Mute = true
  97. } else {
  98. active.DeviceEndpoint.PacuInfo[i].Mute = false
  99. }
  100. if pacuStatBit == 0 {
  101. active.DeviceEndpoint.PacuInfo[i].Status = "normal"
  102. } else {
  103. active.DeviceEndpoint.PacuInfo[i].Status = "abnormal"
  104. }
  105. active.DeviceEndpoint.PacuInfo[i].Volume = strconv.Itoa(int(pacuVolBit))
  106. //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)
  107. }
  108. }
  109. // 处理单个数据包(原 switch 逻辑迁移过来)
  110. func processPacket(packet []byte) {
  111. if len(packet) < 6 {
  112. lfshook.NewLogger().Logger.Infof("Get data wrong length from STC !")
  113. return
  114. }
  115. //for recv data log debug
  116. if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
  117. lfshook.NewLogger().Logger.Infof("Get data from STC:%x", packet)
  118. }
  119. //check if the cmd type is avtive
  120. if packet[5] == 0x03 { // ACTIVE
  121. Active([3]byte{packet[8], packet[9], packet[10]})
  122. return
  123. }
  124. //check if Master role
  125. if !active.Master {
  126. if tagLog == 0 {
  127. lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data !=============")
  128. tagLog = 1
  129. }
  130. return
  131. }
  132. tagLog = 0
  133. switch packet[5] {
  134. case 0x01: //heartbeat
  135. dataLen := binary.BigEndian.Uint16(packet[6:8])
  136. if dataLen == 10 {
  137. processHeartbeat(packet[8:])
  138. } else {
  139. //lfshook.NewLogger().Logger.Infof("=========Heartbeat data err !====len < 10=========")
  140. }
  141. case 0x02: // STN
  142. if active.ActivedCab != "" {
  143. if priority.CheckPriority("STN") {
  144. action.InterruptRunningTask("STN") //STN interrupt other
  145. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  146. StationAnn(packet)
  147. } else {
  148. alstatus.PaStatus("", "STN", "refuse")
  149. }
  150. }
  151. case 0x05: // SPC
  152. if active.ActivedCab != "" {
  153. if priority.CheckPriority("SPC") {
  154. action.InterruptRunningTask("SPC") //SPC interrupt other
  155. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  156. SpecialAnn(packet)
  157. } else {
  158. alstatus.PaStatus("", "SPC", "refuse")
  159. }
  160. }
  161. case 0x06: // EMG
  162. if active.ActivedCab != "" {
  163. if priority.CheckPriority("EMG") {
  164. action.InterruptRunningTask("EMG") //EMG interrupt other
  165. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  166. EmgMsg(packet)
  167. } else {
  168. alstatus.PaStatus("", "EMG", "refuse")
  169. }
  170. }
  171. case 0x07: // STOP
  172. AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
  173. case 0x08: // DCS
  174. if active.ActivedCab != "" {
  175. if priority.CheckPriority("DCS") {
  176. action.InterruptRunningTask("DCS") //DCS interrupt other
  177. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  178. DcsAnn(packet)
  179. } else {
  180. alstatus.PaStatus("", "DCS", "refuse")
  181. }
  182. }
  183. case 0x09: // SELF CHECK
  184. if active.ActivedCab != "" {
  185. if priority.CheckPriority("CHK") {
  186. action.InterruptRunningTask("CHK") //CHK interrupt other
  187. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  188. SelfCheck(packet)
  189. } else {
  190. alstatus.PaStatus("", "CHK", "refuse")
  191. }
  192. }
  193. case 0x0a: // Tone-test
  194. if active.ActivedCab != "" {
  195. if priority.CheckPriority("VOL") {
  196. action.InterruptRunningTask("VOL") //VOL interrupt other
  197. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  198. ToneTest(packet)
  199. } else {
  200. alstatus.PaStatus("", "VOL", "refuse")
  201. }
  202. }
  203. case 0x0e: //TMS answer PAD
  204. if priority.CheckPriority("PAD-TMS") {
  205. //Before Answer PAD
  206. if packet[8] == 0x01 {
  207. action.InterruptRunningTask("PAD-TMS") //PAD-ICP interrupt other
  208. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  209. }
  210. AlarmHandleTMS(packet)
  211. if active.QueueTimer != nil {
  212. if active.QueueTimer.Stop() {
  213. lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  214. } else {
  215. lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  216. }
  217. }
  218. } else {
  219. alstatus.PaStatus("", "PAD-TMS", "refuse")
  220. }
  221. case 0x0b: // reset all PAD
  222. AlarmHoldResetAll(packet[8]) // reset all pad
  223. case 0x0c: // Set PAD time oute
  224. PadTimeOutSetting(packet[8:]) // timeout setting
  225. case 0x0d: // ICP answer PAD
  226. if priority.CheckPriority("PAD-ICP") {
  227. //Before Answer PAD
  228. if packet[8] == 0x01 {
  229. action.InterruptRunningTask("PAD-ICP") //PAD-ICP interrupt other
  230. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  231. }
  232. if active.QueueTimer != nil {
  233. if active.QueueTimer.Stop() {
  234. lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  235. } else {
  236. lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  237. }
  238. }
  239. AlarmHandleICP(packet)
  240. } else {
  241. alstatus.PaStatus("", "PAD-ICP", "refuse")
  242. }
  243. case 0xf1: //Set remote master
  244. //default:
  245. //fmt.Printf("Unknown command: %x\n", packet[5])
  246. }
  247. }
  248. func PadTimeOutSetting(data []byte) {
  249. Seconds := data[7]
  250. if Seconds != 0 {
  251. active.PADTimeout = int(Seconds)
  252. //lfshook.NewLogger().Logger.Infof("=========Set PAD Timeout seconds to %d ! ============", active.PADTimeout)
  253. }
  254. }
  255. // STN , 自动报站广播
  256. func StationAnn(data []byte) (err error) {
  257. specialVoice := int(data[8])
  258. delay := data[9]
  259. cycleCount := data[10]
  260. datalen := int(data[11])
  261. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  262. //set spc voice tag
  263. priority.SpecialVoice = specialVoice
  264. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "STN")
  265. return nil
  266. }
  267. // 激活信号
  268. func Active(data [3]byte) {
  269. //check asterisk available
  270. if active.Master { // master true
  271. if !utils.CheckAsterisk() { //check asterisk not available and set master false
  272. if active.MasterTag > 2 {
  273. active.Master = false
  274. active.MasterTag = 0
  275. } else {
  276. active.MasterTag++
  277. }
  278. //utils.ExecCmd("/etc/init.d/asterisk", "stop", "PBX")
  279. } else {
  280. active.MasterTag = 0
  281. }
  282. } else { // master false, check and start asterisk
  283. //Master == false
  284. if !utils.CheckAsterisk() {
  285. if active.CabNum == "8" {
  286. //utils.ExecCmd("/etc/init.d/asterisk", "start", "PBX")
  287. utils.ExecCmd("/usr/sbin/asterisk")
  288. }
  289. }
  290. //Master == false cab == 1
  291. //if active.CabNum == "1" {
  292. // if utils.CheckAsterisk() {
  293. // utils.ExecCmd("/etc/init.d/asterisk", "stop", "PBX")
  294. // }
  295. //}
  296. }
  297. //var info model.Sysinfo
  298. Signal := int(data[0])
  299. TrainInfo := int(data[2])
  300. if TrainInfo != 0 {
  301. //Get train devide info
  302. DevideInfo := TrainInfo & 0x10
  303. if DevideInfo == 1 {
  304. active.TrainDevide = 1
  305. active.Master = true //列车断开,设置两边都Master
  306. if !utils.CheckAsterisk() {
  307. utils.ExecCmd("/usr/sbin/asterisk")
  308. }
  309. } else {
  310. active.TrainDevide = 0
  311. }
  312. //Radio fault
  313. RadioFault1 := TrainInfo & 0x03
  314. RadioFault8 := TrainInfo & 0x0c
  315. if RadioFault1 == 0 && RadioFault8 == 1 {
  316. active.RadioFault = 1
  317. } else {
  318. active.RadioFault = 0
  319. }
  320. }
  321. switch Signal {
  322. case 0:
  323. if active.ActivedCab != "" {
  324. active.ActivedCab = ""
  325. action.InActiveHangup()
  326. }
  327. case 1:
  328. //active signal from 8 to 1
  329. if active.ActivedCab == "8" || active.ActivedCab == "" {
  330. active.ActivedCab = "1"
  331. action.InActiveHangup()
  332. }
  333. case 8:
  334. //active signal from 1 to 8
  335. if active.ActivedCab == "1" || active.ActivedCab == "" {
  336. active.ActivedCab = "8"
  337. action.InActiveHangup()
  338. }
  339. }
  340. }
  341. // SPC ,特殊服务消息广播
  342. func SpecialAnn(data []byte) {
  343. delay := data[8]
  344. cycleCount := data[9]
  345. datalen := int(data[10])
  346. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  347. if int(cycleCount) == 255 {
  348. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
  349. } else {
  350. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SPC")
  351. }
  352. }
  353. // EMG ,紧急服务消息广播
  354. func EmgMsg(data []byte) {
  355. delay := data[8]
  356. cycleCount := data[9]
  357. datalen := int(data[10])
  358. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  359. if int(cycleCount) == 255 {
  360. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
  361. } else {
  362. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
  363. }
  364. }
  365. // 停止指定类型广播
  366. func AnnStop(data [4]byte) {
  367. //lfshook.NewLogger().Logger.Infof("=========AnnStop Type %x", data[0])
  368. switch data[0] {
  369. case 0x03:
  370. action.HangupTask("DCS") //STOP DCS
  371. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  372. case 0x04:
  373. action.HangupTask("EMG") //STOP EMG
  374. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  375. case 0x07:
  376. action.HangupTask("SPC") //STOP SPC
  377. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  378. case 0x08:
  379. action.HangupTask("STN") //STOP STN
  380. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  381. case 0x09:
  382. action.HangupTask("CHK") //STOP CHK
  383. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  384. case 0x0a:
  385. action.HangupTask("VOL") //STOP VOL
  386. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  387. default:
  388. action.InterruptRunningTask("")
  389. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  390. }
  391. }
  392. // DCS 语音
  393. func DcsAnn(data []byte) {
  394. delay := data[8]
  395. cycleCount := data[9]
  396. datalen := int(data[10])
  397. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  398. if int(cycleCount) == 255 {
  399. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
  400. } else {
  401. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
  402. }
  403. }
  404. // tone-test广播
  405. func ToneTest(data []byte) {
  406. check := data[8]
  407. delay := data[9]
  408. cycleCount := data[10]
  409. datalen := int(data[11])
  410. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  411. switch check {
  412. case 0x01: //start
  413. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
  414. case 0x02: //stop
  415. action.HangupAllExcept("")
  416. }
  417. }
  418. // 自检广播
  419. func SelfCheck(data []byte) {
  420. check := data[8]
  421. delay := data[9]
  422. cycleCount := data[10]
  423. //cycleCount := 0x32
  424. datalen := int(data[11])
  425. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  426. switch check {
  427. case 0x01: //start
  428. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
  429. case 0x02: //stop
  430. action.HangupAllExcept("")
  431. }
  432. }
  433. // 全局变量:记录正在抑制的 exten
  434. var (
  435. suppressedExts = sync.Map{} // map[string]struct{},值存在即表示被抑制
  436. //suppressionMu sync.Mutex // 保护初始化和清理操作(可选)
  437. )
  438. // suppressKey 生成用于抑制的 key(可以根据需求扩展)
  439. func suppressKey(exten string, handler byte) string {
  440. return fmt.Sprintf("%s_h%x", exten, handler)
  441. }
  442. // ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
  443. func AlarmHandleICP(data []byte) {
  444. handler := data[8]
  445. carr := data[12]
  446. pos := data[13]
  447. exten := fmt.Sprintf("24%c%c", carr, pos)
  448. key := suppressKey(exten, handler)
  449. //Drop other handler in 2 sec
  450. //PACUs---call---->ICP1
  451. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  452. if handler == 0x01 {
  453. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  454. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  455. return
  456. }
  457. time.AfterFunc(4*time.Second, func() {
  458. suppressedExts.Delete(key)
  459. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  460. })
  461. }
  462. switch handler {
  463. case 0x01: //answer(ICP+Alarm+PACU)
  464. //NotifyPaiu(exten, "answer")
  465. priority.ICPAnswer = 1
  466. if priority.PADStart == 0 {
  467. alstatus.PaStatus("", "PAD", "start")
  468. priority.PADStart = 1
  469. }
  470. lfshook.NewLogger().Logger.Infof("================ ICP Answer PAD ================:%s ", exten)
  471. if active.ActivedCab == "1" {
  472. action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
  473. //goto ami event ConfbridgeJoin, ICP answer PAD
  474. } else if active.ActivedCab == "8" {
  475. action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
  476. //goto ami event ConfbridgeJoin, ICP answer PAD
  477. } else if active.ActivedCab == "" { // No cab occupied
  478. action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
  479. }
  480. case 0x02: //hold 重新放回队列里面
  481. active.NotifyPaiu(exten, "hold")
  482. err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
  483. if err != nil {
  484. lfshook.NewLogger().Info(err)
  485. }
  486. action.InterruptRunningTask("")
  487. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  488. //action.HangupICP()
  489. case 0x03: //hangup
  490. //NotifyPaiu(exten, "hangup")
  491. lfshook.NewLogger().Logger.Infof("============ Hangup PAD-ICP =============== ")
  492. action.Hangup(exten) //Pad
  493. //action.HangupICP()
  494. action.HangupTask("PAD-ICP")
  495. }
  496. }
  497. // TMS操作乘客报警(根据激活信息判断转到1车还是8车================)
  498. func AlarmHandleTMS(data []byte) {
  499. handler := data[8]
  500. //extlen := data[9]
  501. carr := data[12]
  502. pos := data[13]
  503. exten := fmt.Sprintf("24%c%c", carr, pos)
  504. PacuNum := fmt.Sprintf("21%c%c", carr, pos)
  505. key := suppressKey(exten, handler)
  506. //Drop other handler in 2 sec
  507. // 只对 handler == 0x01 做 2 秒去重
  508. if handler == 0x01 {
  509. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  510. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  511. return // 已存在,说明在2秒窗口期内,直接丢弃
  512. }
  513. // 设置4秒后删除该 key,允许下次通过
  514. time.AfterFunc(4*time.Second, func() {
  515. suppressedExts.Delete(key)
  516. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  517. })
  518. }
  519. switch handler {
  520. case 0x01: //answer(ICP+Alarm+PACU)
  521. //PACU---call---->ICP1
  522. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  523. if priority.PADStart == 0 {
  524. alstatus.PaStatus("", "PAD", "start")
  525. priority.PADStart = 1
  526. }
  527. priority.ICPAnswer = 1
  528. lfshook.NewLogger().Logger.Infof("==============TMS Answer PAD Exten:%s PACU:%s==========", exten, PacuNum)
  529. if action.ExtenStatus(PacuNum) == "Idle" {
  530. if active.ActivedCab == "1" {
  531. action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
  532. //goto ami event BridgeEnter, ICP8 whisper ICP1
  533. } else if active.ActivedCab == "8" {
  534. action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
  535. //goto ami event BridgeEnter, ICP1 whisper ICP8
  536. } else if active.ActivedCab == "" { // No cab occupied
  537. action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
  538. }
  539. } else {
  540. action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
  541. }
  542. case 0x02: //hold 重新放回队列里面
  543. active.NotifyPaiu(exten, "hold")
  544. err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
  545. if err != nil {
  546. lfshook.NewLogger().Info(err)
  547. }
  548. action.HangupAllLocalChan()
  549. case 0x03: //hangup
  550. //NotifyPaiu(exten, "hangup")
  551. action.Hangup(exten) //Pad
  552. action.HangupTask("PAD-TMS")
  553. //action.HangupTask("PAD-ICP")
  554. }
  555. }
  556. // 挂断所有报警器
  557. func AlarmHoldResetAll(handler byte) {
  558. //hangup all actived PAD
  559. action.HangupAllPAD()
  560. //hangup running task
  561. action.InterruptRunningTask("AlarmHoldResetAll") //Reset PAD ALL
  562. time.Sleep(time.Millisecond * 100) //wait endpoimt release
  563. }