|
|
@@ -20,6 +20,7 @@ import (
|
|
|
)
|
|
|
|
|
|
var AminInstance *amigo.Amigo
|
|
|
+var trainInfo = ""
|
|
|
|
|
|
func HandleAMI(event map[string]string) {
|
|
|
//lfshook.NewLogger().Infof("===start======%s", event["Event"]
|
|
|
@@ -56,13 +57,18 @@ func HandleAMI(event map[string]string) {
|
|
|
case "UserEvent": // RCD filename; PA;CPA; CabCab
|
|
|
lfshook.NewLogger().Infof("========event:%s File:%s", event["Event"], event["FILENAME"])
|
|
|
|
|
|
- if event["UserEvent"] == "SetRecordFile" { //Get record file name
|
|
|
- //延时一下1秒;
|
|
|
- //time.Sleep(time.Second)
|
|
|
+ //Get record file name ,encode and upload
|
|
|
+ if event["UserEvent"] == "SetRecordFile" {
|
|
|
+
|
|
|
+ if configs.ConfigGlobal.ProcessRecord != "yes" {
|
|
|
+ break
|
|
|
+ }
|
|
|
|
|
|
//检测录音文件是否存在;最多检测5次,每次间隔1秒
|
|
|
var fileExists bool
|
|
|
for i := 0; i < 5; i++ {
|
|
|
+ time.Sleep(time.Second) // 等待1秒
|
|
|
+
|
|
|
if _, err := os.Stat(event["FILENAME"]); err == nil {
|
|
|
fileExists = true
|
|
|
lfshook.NewLogger().Infof("File found: %s", event["FILENAME"])
|
|
|
@@ -70,34 +76,83 @@ func HandleAMI(event map[string]string) {
|
|
|
} else if os.IsNotExist(err) {
|
|
|
lfshook.NewLogger().Infof("File not found (attempt %d): %s", i+1, event["FILENAME"])
|
|
|
} else {
|
|
|
- lfshook.NewLogger().Errorf("Error checking file: %v", err)
|
|
|
+ lfshook.NewLogger().Infof("Error checking file: %v", err)
|
|
|
}
|
|
|
- time.Sleep(time.Second) // 等待1秒
|
|
|
}
|
|
|
|
|
|
- if !fileExists {
|
|
|
- lfshook.NewLogger().Errorf("File not found after 5 attempts: %s", event["FILENAME"])
|
|
|
- // 可选:发送错误通知或跳过后续处理
|
|
|
+ if !fileExists { //5秒内没有生成录音文件
|
|
|
+ lfshook.NewLogger().Infof("File %s not found after 5 attempts", event["FILENAME"])
|
|
|
break
|
|
|
}
|
|
|
|
|
|
- //检测录音文件是否超过3min;
|
|
|
+ //获取录音文件时长,检测录音文件是否超过3min;
|
|
|
duration, err := utils.GetDuration(event["FILENAME"])
|
|
|
if err != nil {
|
|
|
- lfshook.NewLogger().Errorf("Get duration err: %+v", err)
|
|
|
+ utils.Logger.Printf("Get duration err: %+v", err)
|
|
|
+ break
|
|
|
}
|
|
|
-
|
|
|
- //如果超过则切割
|
|
|
- if duration > 180 {
|
|
|
-
|
|
|
+ lfshook.NewLogger().Infof("==========duration===== %s", duration)
|
|
|
+ //转wav文件的采样率到22kHz,并切割位180秒每段
|
|
|
+ var FileNames []string
|
|
|
+ if duration >= 600 { //超过600秒的超长文件,不处理
|
|
|
+ lfshook.NewLogger().Infof("File over 600 sec, Ignored !")
|
|
|
+ break
|
|
|
+ } else if duration < 600 { //小于600秒文件进行转换和切割
|
|
|
+ FileNames, err = utils.ConvertAndSegmentWAV(event["FILENAME"], strings.Replace(event["FILENAME"], ".wav", "", -1))
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Infof("Get duration err: %+v", err)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ lfshook.NewLogger().Infof("=============== File %+v found after convert", FileNames)
|
|
|
}
|
|
|
|
|
|
- //执行加密操作
|
|
|
- DstFile := fmt.Sprintf("%s.bin", event["FILENAME"])
|
|
|
- utils.AudioFileEncode(DstFile, event["FILENAME"])
|
|
|
+ //执行加密操作,并将录音信息写入日志文件
|
|
|
+ DstFile := ""
|
|
|
+ if len(FileNames) > 0 { // 文件切割之后进入循环处理
|
|
|
+ for _, file := range FileNames {
|
|
|
+ DstFile = fmt.Sprintf("%s.bin", file)
|
|
|
|
|
|
- //切割&加密之后推送生成的文件名;
|
|
|
- alstatus.SendRecordFile(DstFile, event["RecordType"])
|
|
|
+ lfshook.NewLogger().Infof("===========Bin file====%s", DstFile)
|
|
|
+ err = utils.AudioFileEncode(DstFile, file)
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Infof("Encode file: %s err: %+v", DstFile, err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //切割&加密之后发送生成的文件名到STC;
|
|
|
+ alstatus.SendRecordFile(DstFile, event["RecordType"])
|
|
|
+
|
|
|
+ trainInfo = active.ActivedCab
|
|
|
+
|
|
|
+ if strings.Contains(event["FILENAME"], "PAD") {
|
|
|
+ _, caller, callee := utils.GetPadInfo(event["FILENAME"])
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: PAD , CabNumber: %c , LocationCode: %c, Connected: %s, RecordFileName:%s", trainInfo, caller[2], caller[3], callee, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "PA") {
|
|
|
+ _, caller, _ := utils.GetPadInfo(event["FILENAME"])
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: PA, Caller: %s, RecordFileName: %s", trainInfo, caller, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "C2C") {
|
|
|
+ _, caller, _ := utils.GetPadInfo(event["FILENAME"])
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: CabCab, Caller: %s, RecordFileName: %s", trainInfo, caller, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "CPA") {
|
|
|
+ _, caller, _ := utils.GetPadInfo(event["FILENAME"])
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: CPA, Caller: %s, RecordFileName: %s", trainInfo, caller, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "EMG") {
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: EMG, RecordFileName: %s", trainInfo, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "STN") {
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: STN, RecordFileName: %s", trainInfo, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "DCS") {
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: DCS, RecordFileName: %s", trainInfo, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "SPC") {
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: SPC, RecordFileName: %s", trainInfo, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "CHK") {
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: Self Check, RecordFileName: %s", trainInfo, DstFile)
|
|
|
+ } else if strings.Contains(event["FILENAME"], "TONE") {
|
|
|
+ utils.Logger.Printf("Train Information: CabNumber %s, MessageType: TONE Test, RecordFileName: %s", trainInfo, DstFile)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ lfshook.NewLogger().Infof("No files to upload!!!")
|
|
|
+ break
|
|
|
+ }
|
|
|
|
|
|
} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
|
|
|
//PA & CPA interrupt others
|