{"id":13741129,"url":"https://github.com/TheMatjaz/VCAN","last_synced_at":"2025-05-08T21:32:31.702Z","repository":{"id":93644309,"uuid":"257709219","full_name":"TheMatjaz/VCAN","owner":"TheMatjaz","description":"VCAN is a tiny virtual CAN and CAN-FD bus library in C","archived":false,"fork":false,"pushed_at":"2020-04-28T20:33:45.000Z","size":169,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-04T04:07:24.922Z","etag":null,"topics":["bus","c","c11","can-bus","can-fd","library","virtual","virtual-bus","virtual-can-bus"],"latest_commit_sha":null,"homepage":"https://thematjaz.github.io/VCAN/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheMatjaz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-04-21T20:33:41.000Z","updated_at":"2024-07-30T23:38:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"86a2b2ca-039e-4df1-b689-a0c7f3c37bfb","html_url":"https://github.com/TheMatjaz/VCAN","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMatjaz%2FVCAN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMatjaz%2FVCAN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMatjaz%2FVCAN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMatjaz%2FVCAN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheMatjaz","download_url":"https://codeload.github.com/TheMatjaz/VCAN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224774646,"owners_count":17367768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bus","c","c11","can-bus","can-fd","library","virtual","virtual-bus","virtual-can-bus"],"created_at":"2024-08-03T04:00:55.744Z","updated_at":"2024-11-15T11:30:56.188Z","avatar_url":"https://github.com/TheMatjaz.png","language":"C","funding_links":[],"categories":["Utils"],"sub_categories":["Libraries"],"readme":"VCAN is a tiny virtual CAN and CAN-FD bus in C\n===============================================================================\n\nEspecially useful for debugging and testing without using actual\nCAN-connected devices, VCAN is a tiny C library that allows the user to connect\nvirtual nodes on a virtual bus and make them react whenever someone transmits a\nmessage on the bus.\n\nAfter the transmission, each node obtains a copy of the message\nand a callback on each node is called to warn the node of a message being\nreceived.\n\n\n\nKnown limitations\n----------------------------------------\n\nVCAN is simple, synchronous and single-threaded. It does not simulate\ntransmission errors, collisions, arbitration, etc. just pure data transfer.\nCallbacks should be fast.\n\n... but you are free to alter it to your specific needs!\n\n\n\nUsage example\n----------------------------------------\n\n```c\n// Create and initialise a virtual bus.\nvcan_bus_t bus;\nvcan_err_t err;\nerr = vcan_init(\u0026bus);  // Fails on NULL args\nassert(err == VCAN_OK);\n\n// Create 3 virtual nodes.\n// Make them print the received message on reception using the callback.\n// The definition of callback_print_msg() is available in the tst/test.c file\nvcan_node_t node1 = {\n        .id = 1,\n        .callback_on_rx = callback_print_msg,\n};\nvcan_node_t node2 = {\n        .id = 2,\n        .callback_on_rx = callback_print_msg,\n};\nvcan_node_t node3 = {\n        .id = 3,\n        .callback_on_rx = callback_print_msg,\n};\n\n// Connect the nodes to the bus - by default up to 16 nodes.\n// It's just a #define constant, it can be changed easily.\nerr = vcan_connect(\u0026bus, \u0026node1); // Fails on NULL args or full bus\nassert(err == VCAN_OK);\nerr = vcan_connect(\u0026bus, \u0026node2); // Fails on NULL args or full bus\nassert(err == VCAN_OK);\nerr = vcan_connect(\u0026bus, \u0026node3); // Fails on NULL args or full bus\nassert(err == VCAN_OK);\n\n// Transmit!\nputs(\"Transmitting from node 1, node 2 and 3 receive.\");\nconst vcan_msg_t msg = {\n        .id = 0xABCD,\n        .len = 3,\n        .data = {0x00, 0x1A, 0x2B}\n};\nerr = vcan_tx(\u0026bus, \u0026msg, \u0026node1); // Fails on NULL bus or NULL msg\nassert(err == VCAN_OK);\n\n// Because we transmitted from node 1, only node 2 and node 3 received the\n// message. Of course node 1 did not receive it, because it sent it.\n// The callbacks were triggered immediately and your stdout should\n// look like this:\n//\n// Transmitting from node 1, node 2 and 3 receive.\n// Node 2 received ID: 0x0000ABCD | Len: 3 | Data: 00 1A 2B\n// Node 3 received ID: 0x0000ABCD | Len: 3 | Data: 00 1A 2B\n\n// If you transmit from a NULL node, then all nodes receive the message.\nputs(\"Transmitting from NULL node, everyone receives.\");\nerr = vcan_tx(\u0026bus, \u0026msg, NULL);\nassert(err == VCAN_OK);\n\n// And now the stdout should look like this:\n//\n// Transmitting from NULL node, everyone receives.\n// Node 1 received ID: 0x0000ABCD | Len: 3 | Data: 00 1A 2B\n// Node 2 received ID: 0x0000ABCD | Len: 3 | Data: 00 1A 2B\n// Node 3 received ID: 0x0000ABCD | Len: 3 | Data: 00 1A 2B\n\n// Disconnecting nodes is easy.\nerr = vcan_disconnect(\u0026bus, \u0026node2); // Fails on NULL args or already\n// disconnected node\nassert(err == VCAN_OK);\n\n// Now node2 will not receive anything anymore.\nputs(\"Transmitting from node 1 after node 2 disconnection,\"\n     \" node 3 receives.\");\nerr = vcan_tx(\u0026bus, \u0026msg, \u0026node1);\nassert(err == VCAN_OK);\n\n// And now the stdout should look like this:\n//\n// Transmitting from node 1 after node 2 disconnection, node 3 receives.\n// Node 3 received ID: 0x0000ABCD | Len: 3 | Data: 00 1A 2B\n```\n\nYou can also check the `tst/test.c` file for more examples.\n\n\n\nInclude it in your project\n----------------------------------------\n\n### Static source inclusion\n\nCopy the `inc/vcan.h` and `src/vcan.c` files into your existing\nC project, add them to the source folders and compile. Done.\n\n\n\n### Compiling into all possible targets\n\n```\nmkdir build \u0026\u0026 cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release\ncmake --build .\n```\n\nThis will build all targets:\n\n- a `libvcan.a` static library\n- a test runner executable `testvcan`\n- the Doxygen documentation (if Doxygen is installed)\n\nTo compile with the optimisation for size, use the\n`-DCMAKE_BUILD_TYPE=MinSizeRel` flag instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheMatjaz%2FVCAN","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTheMatjaz%2FVCAN","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheMatjaz%2FVCAN/lists"}