فهرست منبع

update reset all

dujunchen 1 هفته پیش
والد
کامیت
146e1060cb
1فایلهای تغییر یافته به همراه33 افزوده شده و 34 حذف شده
  1. 33 34
      internal/app/stc/broadcast/stc-broadcast.go

+ 33 - 34
internal/app/stc/broadcast/stc-broadcast.go

@@ -26,34 +26,29 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
 	for {
 		select {
 		case <-ctx.Done():
-			lfshook.NewLogger().Logger.Infof("HandleStcCmd===ctx==ret======")
 			return
 
 		default:
-			var buf bytes.Buffer // 用于累积未处理完的数据流
+			var buf bytes.Buffer
 			tmp := make([]byte, 1024)
 
 			if conn != nil {
 				n, err := conn.Read(tmp)
 				if err != nil {
 					if err != io.EOF {
-						fmt.Println("Error reading from server:", err)
 						conn.Close()
 					}
 					return
 				}
-
-				// 将新读取的数据追加到缓冲区
 				buf.Write(tmp[:n])
 			}
-			// 尝试从缓冲区中提取完整数据包
+
 			for {
 				packet, err := msgdata.ExtractPacket(&buf)
 				if err != nil {
-					break // 没有完整包或出错,等待更多数据
+					break
 				}
-				// 成功提取一个包,进行处理
-				go processPacket(packet) // 使用 goroutine 避免阻塞接收
+				go processPacket(packet)
 			}
 		}
 	}
@@ -84,8 +79,6 @@ func processPacket(packet []byte) {
 	}
 
 	switch packet[5] {
-	case 0x01: // heartbeat
-		// handle heartbeat
 	case 0x02: // STN
 		StationAnn(packet)
 	case 0x05: // SPC
@@ -100,9 +93,8 @@ func processPacket(packet []byte) {
 		SelfCheck(packet)
 	case 0x0a:
 		AlarmHandleTMS(packet)
-		//AlarmHandleICP(packet)
 	case 0x0b:
-		AlarmResetAll()
+		AlarmHoldResetAll(packet[8])
 	case 0x0c:
 		RecordStorageConf(packet[8:])
 	case 0x0d:
@@ -121,7 +113,6 @@ func StationAnn(data []byte) (err error) {
 	datalen := int(data[11])
 
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
-	lfshook.NewLogger().Logger.Infof("=============Get filename  : %v", filename)
 
 	//update stn voice
 	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{Special: specialVoice, PaType: "STN"})
@@ -217,7 +208,6 @@ func SpecialAnn(data []byte) {
 	//Pa status report
 	alstatus.PaStatus("", "SPC", "start")
 
-	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "SPC")
 	} else {
@@ -242,7 +232,6 @@ func EmgMsg(data []byte) {
 	//Pa status report
 	alstatus.PaStatus("", "EMG", "start")
 
-	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "EMG")
 	} else {
@@ -296,7 +285,6 @@ func DcsAnn(data []byte) {
 		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
 	}
 
-	//lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	//Pa status report
 	alstatus.PaStatus("", "DCS", "start")
 
@@ -356,23 +344,19 @@ func suppressKey(exten string, handler byte) string {
 // ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
 func AlarmHandleICP(data []byte) {
 	handler := data[8]
-	//extlen := data[9]
 	carr := data[12]
 	pos := data[13]
 	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秒窗口期内,直接丢弃
+			return
 		}
 
-		// 设置4秒后删除该 key,允许下次通过
 		time.AfterFunc(4*time.Second, func() {
 			suppressedExts.Delete(key)
 			lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
@@ -381,9 +365,7 @@ func AlarmHandleICP(data []byte) {
 
 	switch handler {
 	case 0x01: //answer(ICP+Alarm+PACU)
-		//NotifyPaiu(exten, "answer")
 
-		lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
 		if active.CabNum == "1" && active.Actived {
 			action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
 			//goto ami event ConfbridgeJoin, ICP answer PAD
@@ -504,7 +486,7 @@ func NotifyPaiu(Exten, Action string) {
 }
 
 // 挂断所有报警器
-func AlarmResetAll() {
+func AlarmHoldResetAll(data byte) {
 
 	var AlarmExts []model.Extension
 
@@ -513,16 +495,33 @@ func AlarmResetAll() {
 		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
 	}
 
-	for _, ext := range AlarmExts {
-		action.Hangup(ext.Extension)
-	}
+	if data == 1 {
+		for _, ext := range AlarmExts {
+			err := action.RedirectInQueue(ext.Extension, "0300", "default", "1")
+			if err != nil {
+				lfshook.NewLogger().Info(err)
+			}
+		}
 
-	if active.CabNum == "1" && active.Actived {
-		action.Hangup("2311")                    //1 车接听
-		alstatus.AlarmStatus("0000", "allreset") //send all reset status
-	} else if active.CabNum == "8" && active.Actived {
-		action.Hangup("2381")                    //8 车接听
-		alstatus.AlarmStatus("0000", "allreset") // send all reset status
+		if active.CabNum == "1" && active.Actived {
+			action.Hangup("2311")                   //1 车接听
+			alstatus.AlarmStatus("0000", "allhold") //send all hold status
+		} else if active.CabNum == "8" && active.Actived {
+			action.Hangup("2381")                   //8 车接听
+			alstatus.AlarmStatus("0000", "allhold") // send all hold status
+		}
+	} else if data == 2 {
+		for _, ext := range AlarmExts {
+			action.Hangup(ext.Extension)
+		}
+
+		if active.CabNum == "1" && active.Actived {
+			action.Hangup("2311")                    //1 车接听
+			alstatus.AlarmStatus("0000", "allreset") //send all reset status
+		} else if active.CabNum == "8" && active.Actived {
+			action.Hangup("2381")                    //8 车接听
+			alstatus.AlarmStatus("0000", "allreset") // send all reset status
+		}
 	}
 }