| 718 | } |
| 719 | |
| 720 | int lua_get_CAN_device2(lua_State *L) { |
| 721 | |
| 722 | // Allow : and . access |
| 723 | const int arg_offset = (luaL_testudata(L, 1, "CAN") != NULL) ? 1 : 0; |
| 724 | |
| 725 | binding_argcheck(L, 1 + arg_offset); |
| 726 | |
| 727 | const uint32_t raw_buffer_len = get_uint32(L, 1 + arg_offset, 1, 25); |
| 728 | const uint32_t buffer_len = static_cast<uint32_t>(raw_buffer_len); |
| 729 | |
| 730 | auto *scripting = AP::scripting(); |
| 731 | |
| 732 | if (scripting->_CAN_dev2 == nullptr) { |
| 733 | scripting->_CAN_dev2 = NEW_NOTHROW ScriptingCANSensor(AP_CAN::Protocol::Scripting2); |
| 734 | if (scripting->_CAN_dev2 == nullptr) { |
| 735 | return luaL_argerror(L, 1, "CAN device nullptr"); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | if (!scripting->_CAN_dev2->initialized()) { |
| 740 | // Driver not initialized, probably because there is no can driver set to scripting 2 |
| 741 | // Return nil |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | *new_ScriptingCANBuffer(L) = scripting->_CAN_dev2->add_buffer(buffer_len); |
| 746 | |
| 747 | return 1; |
| 748 | } |
| 749 | #endif // AP_SCRIPTING_CAN_SENSOR_ENABLED |
| 750 | |
| 751 | #if AP_SERIALMANAGER_ENABLED |
nothing calls this directly
no test coverage detected