{"action":"created","issue":{"url":"https://api.github.com/repos/lancaster-university/codal-core/issues/58","repository_url":"https://api.github.com/repos/lancaster-university/codal-core","labels_url":"https://api.github.com/repos/lancaster-university/codal-core/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/lancaster-university/codal-core/issues/58/comments","events_url":"https://api.github.com/repos/lancaster-university/codal-core/issues/58/events","html_url":"https://github.com/lancaster-university/codal-core/pull/58","id":388281215,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM2NTgyNjkz","number":58,"title":"Jacdac protocol errors","user":{"login":"jamesadevine","id":4742697,"node_id":"MDQ6VXNlcjQ3NDI2OTc=","avatar_url":"https://avatars3.githubusercontent.com/u/4742697?v=4","gravatar_id":"","url":"https://api.github.com/users/jamesadevine","html_url":"https://github.com/jamesadevine","followers_url":"https://api.github.com/users/jamesadevine/followers","following_url":"https://api.github.com/users/jamesadevine/following{/other_user}","gists_url":"https://api.github.com/users/jamesadevine/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesadevine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesadevine/subscriptions","organizations_url":"https://api.github.com/users/jamesadevine/orgs","repos_url":"https://api.github.com/users/jamesadevine/repos","events_url":"https://api.github.com/users/jamesadevine/events{/privacy}","received_events_url":"https://api.github.com/users/jamesadevine/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-12-06T16:04:04Z","updated_at":"2018-12-06T16:44:09Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/lancaster-university/codal-core/pulls/58","html_url":"https://github.com/lancaster-university/codal-core/pull/58","diff_url":"https://github.com/lancaster-university/codal-core/pull/58.diff","patch_url":"https://github.com/lancaster-university/codal-core/pull/58.patch"},"body":"@pelikhan @teddyseyed @mmoskal \r\n\r\nThis PR introduces a new control packet type: `ERROR`. It also adds a new interface to a JDDriver `handleErrorPacket`, which is invoked when a control packet flagging an error is received.\r\n\r\nError codes are automatically placed into control packets by the logic driver based on the JDDevice state in a driver. To set an error code call `driver.device.setError(ERR_CODE)`. Protocol error codes are limited to 16 numbers (4 bits), time will tell if this is enough error codes...\r\n\r\nJDProtocol now accepts a debugging name that is placed in the control packet when an error is flagged: `JDProtocol::setDebugName`, you can also retrieve the current debug name using `JDProtocol::getDebugName`. Currently it's one debug name per device, rather than per driver. I might take it out, as i'm not sure how useful it is.\r\n\r\nI've only added two error codes at the moment `STATUS_OK` and `PERIPHERAL_MALFUNCTION`. I'm the list will grow as we move forward.\r\n\r\nAn example is shown below:\r\n\r\n```cpp\r\nstruct JDTestPacket\r\n{\r\n    uint8_t x;\r\n    uint8_t y;\r\n} __attribute((__packed__));\r\n\r\nclass JDHostTest : public JDDriver\r\n{\r\n    public:\r\n    JDHostTest() : JDDriver(JDDevice(HostDriver, 10)) {}\r\n\r\n    void send()\r\n    {\r\n        JDTestPacket tp;\r\n\r\n        tp.x = target_random(255);\r\n        tp.y = target_random(255);\r\n\r\n        JDProtocol::send((uint8_t*)&tp, sizeof(tp), this->device.address);\r\n    }\r\n\r\n    void setError()\r\n    {\r\n        this->device.setError(PERIPHERAL_MALFUNCTION);\r\n    }\r\n};\r\n\r\n\r\nclass JDVirtualTest : public JDDriver\r\n{\r\n    public:\r\n    JDVirtualTest() : JDDriver(JDDevice(VirtualDriver, 10)) {}\r\n\r\n    int handlePacket(JDPkt* packet)\r\n    {\r\n        JDTestPacket* tp = (JDTestPacket*)packet->data;\r\n        DMESG(\"REC: x %d y %d\",tp->x, tp->y);\r\n        Event(9999,999);\r\n        return DEVICE_OK;\r\n    }\r\n\r\n    int handleErrorPacket(JDPkt* p)\r\n    {\r\n        ControlPacket* cp = (ControlPacket*)p->data;\r\n        ControlPacketError* err = (ControlPacketError*)cp->data;\r\n\r\n        char name[CONTROL_PACKET_ERROR_NAME_LENGTH + 1] = { 0 };\r\n        memcpy(name, err, CONTROL_PACKET_ERROR_NAME_LENGTH);\r\n        name[CONTROL_PACKET_ERROR_NAME_LENGTH] = 0;\r\n\r\n        DMESG(\"ERROR: %s %d\", name, err->code);\r\n        return DEVICE_OK;\r\n    }\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/lancaster-university/codal-core/issues/comments/444940893","html_url":"https://github.com/lancaster-university/codal-core/pull/58#issuecomment-444940893","issue_url":"https://api.github.com/repos/lancaster-university/codal-core/issues/58","id":444940893,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDk0MDg5Mw==","user":{"login":"pelikhan","id":4175913,"node_id":"MDQ6VXNlcjQxNzU5MTM=","avatar_url":"https://avatars0.githubusercontent.com/u/4175913?v=4","gravatar_id":"","url":"https://api.github.com/users/pelikhan","html_url":"https://github.com/pelikhan","followers_url":"https://api.github.com/users/pelikhan/followers","following_url":"https://api.github.com/users/pelikhan/following{/other_user}","gists_url":"https://api.github.com/users/pelikhan/gists{/gist_id}","starred_url":"https://api.github.com/users/pelikhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelikhan/subscriptions","organizations_url":"https://api.github.com/users/pelikhan/orgs","repos_url":"https://api.github.com/users/pelikhan/repos","events_url":"https://api.github.com/users/pelikhan/events{/privacy}","received_events_url":"https://api.github.com/users/pelikhan/received_events","type":"User","site_admin":false},"created_at":"2018-12-06T16:44:09Z","updated_at":"2018-12-06T16:44:09Z","author_association":"CONTRIBUTOR","body":"Very nice!\r\n"}}
{"actor":{"display_login":"pelikhan"}}