LingxinMeng 7 月之前
父节点
当前提交
ccc3cae4df

+ 44 - 0
aarch64/pjisuv/master/service/produce_window.go

@@ -1892,7 +1892,51 @@ func ProduceWindow() {
 					create = true
 				}
 			}
+			// 38
+			if topic == masterConfig.TopicOfFaultInfo &&
+				(len(masterConfig.RuleOfFaultInfo1) > 0 ||
+					len(masterConfig.RuleOfFaultInfo3) > 0) {
+				subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
+					Node:  commonConfig.RosNode,
+					Topic: topic,
+					Callback: func(data *pjisuv_msgs.FaultVec) {
+						subscribersTimeMutexes[i].Lock()
+						if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
+							subscribersMutexes[i].Lock()
+							faultHappenTime := util.GetNowTimeCustom()         // 获取当前故障发生时间
+							lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
+							faultLabel := ""
+							if len(masterConfig.RuleOfFaultInfo1) > 0 {
+								for _, f := range masterConfig.RuleOfFaultInfo1 {
+									faultLabel = f(data)
+									if faultLabel != "" {
+										saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
 
+										subscribersTimes[i] = time.Now()
+										goto TriggerSuccess
+									}
+								}
+							}
+							if len(masterConfig.RuleOfFaultInfo3) > 0 {
+								for _, f := range masterConfig.RuleOfFaultInfo3 {
+									faultLabel = f(shareVars, data)
+									if faultLabel != "" {
+										saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
+										subscribersTimes[i] = time.Now()
+										goto TriggerSuccess
+									}
+								}
+							}
+						TriggerSuccess:
+							subscribersMutexes[i].Unlock()
+						}
+						subscribersTimeMutexes[i].Unlock()
+					},
+				})
+				if err == nil {
+					create = true
+				}
+			}
 			// 39 有共享变量的订阅者必须被创建
 			if topic == masterConfig.TopicOfPjVehicleFdbPub {
 				subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{

+ 5 - 6
pjisuv_msgs/common_msgs.go

@@ -16,18 +16,17 @@ type Header struct {
 	FaultVec       FaultVec       `rosname:"fault_vec"`
 	TimeStatistics TimeStatistics `rosname:"time_statistics"`
 }
-
+type TimeStatistics struct {
+	msg.Package      `ros:"common_msgs"`
+	DevTimeStatusMsg []TimeStatus `rosname:"dev_time_status_msg"`
+	SendingTimestamp float64      `rosname:"sending_timestamp"`
+}
 type FaultVec struct {
 	msg.Package      `ros:"common_msgs"`
 	InfoVec          []FaultInfo `rosname:"info_vec"`
 	ModuleFaultLevel int32       `rosname:"module_fault_level"`
 }
 
-type TimeStatistics struct {
-	msg.Package      `ros:"common_msgs"`
-	DevTimeStatusMsg []TimeStatus `rosname:"dev_time_status_msg"`
-	SendingTimestamp float64      `rosname:"sending_timestamp"`
-}
 type FaultInfo struct {
 	msg.Package  `ros:"common_msgs"`
 	TimestampSec float64 `rosname:"timestamp_sec"`

+ 56 - 0
tools/send_fault_info/main/main.go

@@ -0,0 +1,56 @@
+package main
+
+import (
+	"cicv-data-closedloop/pjisuv_msgs"
+	"github.com/bluenviron/goroslib/v2"
+	"log"
+	"os"
+	"os/signal"
+	"time"
+)
+
+func main() {
+	// create a node and connect to the master
+	n, err := goroslib.NewNode(goroslib.NodeConf{
+		Name:          "goroslib_pub_fault_info",
+		MasterAddress: "127.0.0.1:11311",
+	})
+	if err != nil {
+		panic(err)
+	}
+	defer n.Close()
+
+	// create a publisher
+	pub, err := goroslib.NewPublisher(goroslib.PublisherConf{
+		Node:  n,
+		Topic: "/fault_info",
+		Msg:   &pjisuv_msgs.FaultVec{},
+	})
+	if err != nil {
+		panic(err)
+	}
+	defer pub.Close()
+
+	r := n.TimeRate(1 * time.Second)
+
+	c := make(chan os.Signal, 1)
+	signal.Notify(c, os.Interrupt)
+
+	for {
+		select {
+		// publish a message every second
+		case <-r.SleepChan():
+			msg := &pjisuv_msgs.FaultVec{
+				InfoVec: []pjisuv_msgs.FaultInfo{
+					{ErrorCode: 12345}, // 发送故障码12345
+				},
+			}
+			log.Printf("Outgoing: %+v\n", msg)
+			pub.Write(msg)
+
+		// handle CTRL-C
+		case <-c:
+			return
+		}
+	}
+}

+ 5 - 0
trigger/pjisuv/fault_info/ErrorCode/main/ErrorCode.go

@@ -20,5 +20,10 @@ func Rule(data *pjisuv_msgs.FaultVec) string {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
+	for _, infoVec := range data.InfoVec {
+		if infoVec.ErrorCode != 0 {
+			return Label()
+		}
+	}
 	return ""
 }