[Connected Car] markkpatel:
Would like to communicate with the cars Body Control Module via the Uconnect radio

I would like to communicate with the cars Body Control Module via the Uconnect radio.

Need more people to look at the code and work out how to do this communication.

Following / finding the code is proving difficult for just one person.

1. Enabling CAN communication between Uconnect and BCM (don't know how to do this). CAN is mentioned alot in the code.

2. Writing data to BCM once CAN is correctly enabled: done with "ipc.open(chan, mode)" and "ipc.write(a, b, c). ie ipc.open(33, "w") will create a file /dev/ipc/CH33 (channel 33). Will still need to work out what data to send to what channel.

3. Will data be read automatically from file or do we need to send a read signal, etc

This will allow us to do some simple but interesting things, such as

Update vehicle config with:

UnitOptionPresent = false

PressureUnitsPresent = true

CapacityUnitsPresent = true

DistanceUnitsPresent = true

PowerUnitsPresent = true

ConsumptionUnitsPresent = true

SpeedUnitsPresent = true

TemperatureUnitsPresent = true

TorqueUnitsPresent = true

This will turn off US-Metric option in the Display Settings screen and turn on the Custom Units Settings screen, which will allows us among other things to select the TPMS units (PSI, Bar, Kba) and temperature units (Celsius or Fahrenheit), etc.

Example code: platform_canserviceMgr.lua

local service = require("service")
local timer = require("timer")
local ipc = require("ipc")
local bit = require("bit")
module((...), package.seeall)
local CAN_SERVICE = "com.harman.service.canservice"
local AMS_SERVICE = "com.aicas.xlet.manager.AMS"
local HWKEYS_CHANNEL = 6
local CONFIG_CHANNEL = 17
local HVAC_CHANNEL = 20
local VEH_MSG1_CHANNEL = 21
local VEH_MSG2_CHANNEL = 22
local S330_CHANNEL = 8
local TESTER_PRSNT_REQ = {
id = {3, 254},
name = "testToolPresent"
}
local CANC1_CHANNEL = 23
local CANC2_CHANNEL = 24
local DIAG1_CHANNEL = 18
local DIAG2_CHANNEL = 19
local START_REMAINING_CHANNEL_TIME = 50000
local CHANNEL_ALREADY_STARTED = false
local function SendIOCReq(req)
local REQUEST_CHAN = 6
local WRITE_MODE = "w"
local SEND_SIG_FLAG = 4
local REQ_SIZE = 0
local ERROR = 1
if type(req) ~= "table" or type(req.id) ~= "table" then
print("canserviceMgr ERROR: SendIOCReq input param is invalid format")
return ERROR
end
local chan = ipc.open(REQUEST_CHAN, WRITE_MODE)
if chan == nil then
print("canserviceMgr ERROR: cannot open ipc channel " .. tostring(REQUEST_CHAN) .. " to send " .. tostring(req.name))
return ERROR
end
sendBuffer = {}
sendBuffer[1] = SEND_SIG_FLAG
sendBuffer[2] = bit.bor(bit.band(req.id[1], 15), bit.band(bit.lshift(REQ_SIZE, 4), 240))
sendBuffer[3] = bit.band(req.id[2], 255)
chan:write(sendBuffer)
chan:close()
end
local function openCanserviceChannel()
if CHANNEL_ALREADY_STARTED == false then
print(" openCanserviceChannel ")
service.asyncInvoke(CAN_SERVICE, "openchan", {number = CANC1_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = CANC2_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = DIAG1_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = DIAG2_CHANNEL})
CHANNEL_ALREADY_STARTED = true
end
end
local function onOwnerChanged(newName, oldOwner, newOwner)
if newName == CAN_SERVICE then
service.asyncInvoke(CAN_SERVICE, "opencontrolchan", {number = HWKEYS_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = HWKEYS_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = VEH_MSG1_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = VEH_MSG2_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = HVAC_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = S330_CHANNEL})
service.asyncInvoke(CAN_SERVICE, "openchan", {number = CONFIG_CHANNEL})
SendIOCReq(TESTER_PRSNT_REQ)
end
if newName == AMS_SERVICE then
print(" AMS Available now")
openCanserviceChannel()
end
end
local channelStartTimer
local function ontimer()
channelStartTimer:stop()
openCanserviceChannel()
end
channelStartTimer = timer.new(ontimer)
channelStartTimer:start(START_REMAINING_CHANNEL_TIME, 1)
service.subscribeOwnerChanged(CAN_SERVICE, onOwnerChanged)
if service.nameHasOwner(CAN_SERVICE) then
print(" Can service available")
onOwnerChanged(CAN_SERVICE, "", "")
end
service.subscribeOwnerChanged(AMS_SERVICE, onOwnerChanged)
if service.nameHasOwner(AMS_SERVICE) then
print(" AMS service available")
onOwnerChanged(AMS_SERVICE, "", "")
end