MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / AP_HAL__I2CDevice_transfer

Function AP_HAL__I2CDevice_transfer

libraries/AP_Scripting/lua_bindings.cpp:662–687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

660}
661
662int AP_HAL__I2CDevice_transfer(lua_State *L) {
663 binding_argcheck(L, 3);
664
665 AP_HAL::I2CDevice * ud = *check_AP_HAL__I2CDevice(L, 1);
666
667 // Parse string of bytes to send
668 size_t send_len;
669 const uint8_t* send_data = (const uint8_t*)(lua_tolstring(L, 2, &send_len));
670
671 // Parse and setup rx buffer
672 uint32_t rx_len = get_uint8_t(L, 3);
673 uint8_t rx_data[rx_len];
674
675 // Transfer
676 ud->get_semaphore()->take_blocking();
677 const bool success = ud->transfer(send_data, send_len, rx_data, rx_len);
678 ud->get_semaphore()->give();
679
680 if (!success) {
681 return 0;
682 }
683
684 // Return a string
685 lua_pushlstring(L, (const char *)rx_data, rx_len);
686 return 1;
687}
688
689#if AP_SCRIPTING_CAN_SENSOR_ENABLED
690int lua_get_CAN_device(lua_State *L) {

Callers

nothing calls this directly

Calls 6

lua_tolstringFunction · 0.85
lua_pushlstringFunction · 0.85
take_blockingMethod · 0.45
get_semaphoreMethod · 0.45
transferMethod · 0.45
giveMethod · 0.45

Tested by

no test coverage detected