-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.capl
More file actions
68 lines (58 loc) · 1.95 KB
/
test.capl
File metadata and controls
68 lines (58 loc) · 1.95 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
/*
* CAPL Script: Message Disabling Example
* Description: This script demonstrates how to intercept and disable a specific CAN message
* from being transmitted on the bus.
* Date: July 10, 2025
*/
variables
{
// Define the ID of the message you want to disable
const int DISABLED_MESSAGE_ID = 0x123; // Change this to your target message ID
// Flag to track if message disabling is active
int isDisabled = 1; // 1 = disabled, 0 = enabled
}
// This function runs at the start of measurement
on start
{
write("Message disabling script started");
write("Message 0x%x is currently %s", DISABLED_MESSAGE_ID, isDisabled ? "DISABLED" : "ENABLED");
}
// This function intercepts all messages before they are sent
on preTransmit *
{
// Check if the message being transmitted matches our target ID
if (this.id == DISABLED_MESSAGE_ID && isDisabled)
{
// Cancel the transmission of this message
cancelTransmit();
// Optionally log that we blocked a message
write("Blocked transmission of message ID: 0x%x", DISABLED_MESSAGE_ID);
}
}
// Function to toggle message disabling on/off
on key 'D'
{
isDisabled = !isDisabled;
write("Message 0x%x is now %s", DISABLED_MESSAGE_ID, isDisabled ? "DISABLED" : "ENABLED");
}
// Alternative method: Using a specific message handler to disable a particular message
// Provide a function to disable a different message ID dynamically
on key '1' ... '9'
{
// Calculate new message ID based on key press (1-9 → 0x101-0x109)
int newID = 0x100 + this - '0';
DISABLED_MESSAGE_ID = newID;
write("Now targeting message ID: 0x%x (Status: %s)",
DISABLED_MESSAGE_ID,
isDisabled ? "DISABLED" : "ENABLED");
}
// Optional: Function to demonstrate how to disable message by its name
// (requires database with message definitions)
on preTransmit Engine_Status // Replace with your actual message name
{
if (isDisabled)
{
cancelTransmit();
write("Blocked message 'Engine_Status'");
}
}