
— 33 —
payload. To get payload bytes just
load()
this SLOT to copy contents into work buffer. SLOT can hold up
to 229 bytes but this configuration method allows you to set only the first 30 bytes; all other bytes in the
SLOT will be cleared.
If no command was given, command payload is empty or command is incorrect, SLOT will not be modified
and
param()
will return 0.
Example 6.
# Fuel level tank simulator. Sends PGN 127505 "Fluid Level".
# Allows to set arbitrary "fuel level" via "YD:PARAM yy" command,
# where yy — desired fuel level (hexadecimal value, in %)
#
prepare PGN 127505 "Fluid Level" with 100% full diesel tank, fluid instance = 0
SLOT1 = 0111F219 FF 08 00A861FFFFFFFFFF
# main loop executed each second
heartbeat(1000)
{
# new tank level settings received via "YD:PARAM" ?
if (param(SLOT2) == 1) # is only one byte read (correct payload length)?
{
load(SLOT2) # copy slot to work buffer
A = get(0, INT8) * 250 # get new fluid level %, convert to N2K resolution
load(SLOT1) # load PGN 127505 into work buffer
set(DATA+1, INT16, A) # update "fluid level %" data field
save(SLOT1) # save SLOT1 with modified "fluid level %" data
}
# Send PGN 127505 "Fluid Level"
load(SLOT1)
send(CAN1)
}