-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck-demo.sh
More file actions
executable file
·163 lines (140 loc) · 6.1 KB
/
Copy pathcheck-demo.sh
File metadata and controls
executable file
·163 lines (140 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Sensor Diagnostics Demo - Interactive API Demonstration
# Explores ros2_medkit capabilities with simulated sensors
GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
API_BASE="${GATEWAY_URL}/api/v1"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo_step() {
echo -e "\n${BLUE}=== $1 ===${NC}\n"
}
echo_success() {
echo -e "${GREEN}✓ $1${NC}"
}
echo_error() {
echo -e "${RED}✗ $1${NC}"
}
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Sensor Diagnostics Demo - API Explorer ║"
echo "║ (ros2_medkit + Simulated Sensors) ║"
echo "╚════════════════════════════════════════════════════════════╝"
# Check for jq dependency
if ! command -v jq >/dev/null 2>&1; then
echo_error "'jq' is required but not installed."
echo " Please install jq (e.g., 'sudo apt-get install jq') and retry."
exit 1
fi
# Check gateway health
echo ""
echo "Checking gateway health..."
if ! curl -sf "${API_BASE}/health" > /dev/null 2>&1; then
echo_error "Gateway not available at ${GATEWAY_URL}"
echo " Start with: ./run-demo.sh"
exit 1
fi
echo_success "Gateway is healthy!"
echo_step "1. Checking Gateway Health"
curl -s "${API_BASE}/health" | jq '.'
echo_step "2. Listing All Areas (Namespaces)"
curl -s "${API_BASE}/areas" | jq '.items[] | {id: .id, name: .name, description: .description}'
echo_step "3. Listing All Components"
curl -s "${API_BASE}/components" | jq '.items[] | {id: .id, name: .name, area: .area}'
echo_step "4. Listing All Apps (ROS 2 Nodes)"
curl -s "${API_BASE}/apps" | jq '.items[] | {id: .id, name: .name, namespace: .namespace}'
echo_step "5. Reading LiDAR Data"
echo "Getting latest scan from LiDAR simulator..."
curl -s "${API_BASE}/apps/lidar-sim/data/scan" | jq '{
angle_min: .angle_min,
angle_max: .angle_max,
range_min: .range_min,
range_max: .range_max,
sample_ranges: .ranges[:5]
}'
echo_step "6. Reading IMU Data"
echo "Getting latest IMU reading..."
curl -s "${API_BASE}/apps/imu-sim/data/imu" | jq '{
linear_acceleration: .linear_acceleration,
angular_velocity: .angular_velocity
}'
echo_step "7. Reading GPS Fix"
echo "Getting current GPS position..."
curl -s "${API_BASE}/apps/gps-sim/data/fix" | jq '{
latitude: .latitude,
longitude: .longitude,
altitude: .altitude,
status: .status
}'
echo_step "8. Listing LiDAR Configurations"
echo "These parameters can be modified at runtime to inject faults..."
curl -s "${API_BASE}/apps/lidar-sim/configurations" | jq '.items[] | {name: .name, value: .value, type: .type}'
echo_step "9. Checking Current Faults"
FAULTS_JSON=$(curl -s "${API_BASE}/faults")
echo "$FAULTS_JSON" | jq '.'
# If there are faults, demonstrate snapshot / bulk-data endpoints
FAULT_COUNT=$(echo "$FAULTS_JSON" | jq '.items | length')
if [ "$FAULT_COUNT" -gt 0 ]; then
# Find the first fault that has both a non-null entity_id and code
FIRST_FAULT_ENTRY=$(echo "$FAULTS_JSON" | jq -r '.items[] | select(.entity_id != null and .code != null) | "\(.entity_type) \(.entity_id) \(.code)"' | head -n 1)
if [ -z "$FIRST_FAULT_ENTRY" ]; then
echo ""
echo " Faults exist but none provide both 'entity_id' and 'code'."
echo " Skipping snapshot and bulk-data demonstration."
else
FIRST_ENTITY_TYPE=$(echo "$FIRST_FAULT_ENTRY" | awk '{print $1}')
FIRST_ENTITY=$(echo "$FIRST_FAULT_ENTRY" | awk '{print $2}')
FIRST_FAULT=$(echo "$FIRST_FAULT_ENTRY" | awk '{print $3}')
# Map entity_type to plural resource path (e.g., "app" -> "apps")
case "$FIRST_ENTITY_TYPE" in
app|apps) ENTITY_PATH="apps" ;;
component|components) ENTITY_PATH="components" ;;
area|areas) ENTITY_PATH="areas" ;;
*) ENTITY_PATH="apps" ;;
esac
echo_step "10. Fault Detail with Environment Data (Snapshots)"
echo "Fetching fault ${FIRST_FAULT} on ${ENTITY_PATH}/${FIRST_ENTITY}..."
curl -s "${API_BASE}/${ENTITY_PATH}/${FIRST_ENTITY}/faults/${FIRST_FAULT}" | jq '{
code: .item.code,
status: .item.status,
environment_data: {
extended_data_records: .environment_data.extended_data_records,
snapshot_count: (.environment_data.snapshots | length)
}
}'
echo_step "11. Bulk-Data Categories (Rosbag Recordings)"
echo "Checking available bulk-data categories..."
curl -s "${API_BASE}/${ENTITY_PATH}/${FIRST_ENTITY}/bulk-data" | jq '.'
echo_step "12. Bulk-Data Descriptors (Rosbag Files)"
echo "Listing available rosbag recordings..."
curl -s "${API_BASE}/${ENTITY_PATH}/${FIRST_ENTITY}/bulk-data/rosbags" | jq '.items[] | {
id: .id,
name: .name,
size: .size,
mimetype: .mimetype,
"x-medkit": ."x-medkit"
}'
fi
else
echo ""
echo " No active faults. Inject a fault first to see snapshot/bulk-data features:"
echo " ./inject-noise.sh && sleep 5 && bash $0"
fi
echo ""
echo_success "API demonstration complete!"
echo ""
echo "🔧 Try injecting faults with these scripts:"
echo " ./inject-noise.sh # Increase sensor noise"
echo " ./inject-failure.sh # Cause sensor timeouts"
echo " ./inject-nan.sh # Inject NaN values"
echo " ./inject-drift.sh # Inject sensor drift"
echo " ./restore-normal.sh # Restore normal operation"
echo ""
echo "📸 After injecting a fault, check snapshots and rosbags:"
echo " curl ${API_BASE}/faults | jq # List faults"
echo " curl ${API_BASE}/components/lidar-unit/faults/<CODE> | jq # Fault detail + snapshots"
echo " curl ${API_BASE}/components/lidar-unit/bulk-data/rosbags | jq # List rosbag recordings"
echo ""
echo "🌐 Web UI: http://localhost:3000"
echo "🌐 REST API: http://localhost:8080/api/v1/"