samples: mgmt/osdp: Add new OSDP PD sample
This commit adds a PD sample for drivers/osdp. It receives OSDP commands and prints a message to console. Signed-off-by: Siddharth Chandrasekaran <siddharth@embedjournal.com>
This commit is contained in:
parent
9a91b4adf9
commit
0ae2f2f2f8
12
samples/subsys/mgmt/osdp/CMakeLists.txt
Normal file
12
samples/subsys/mgmt/osdp/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 Siddharth Chandrasekaran <siddharth@embedjournal.com>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.13.1)
|
||||||
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||||
|
|
||||||
|
project(osdp_sample)
|
||||||
|
|
||||||
|
target_sources(app PRIVATE src/main.c)
|
26
samples/subsys/mgmt/osdp/README.rst
Normal file
26
samples/subsys/mgmt/osdp/README.rst
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
.. _osdp-sample:
|
||||||
|
|
||||||
|
OSDP
|
||||||
|
####
|
||||||
|
|
||||||
|
OSDP describes the communication interface one or more Peripheral Devices (PD)
|
||||||
|
to a Control Panel (CP). The specification describes the protocol
|
||||||
|
implementation over a two-wire RS-485 multi-drop serial communication channel.
|
||||||
|
Nevertheless, this protocol can be used to transfer secure byte stream over any
|
||||||
|
physical channel in low memory embedded devices.
|
||||||
|
|
||||||
|
Although OSDP is steered towards the Access and Security industries, it can be
|
||||||
|
used as a general communication protocol for devices in a secure way without
|
||||||
|
too much resource requirements. The security is not top-notch (AES-128) but it
|
||||||
|
is reasonable enough, given that the alternative is no security at all.
|
||||||
|
|
||||||
|
OSDP Supports the control of the following components on a PD:
|
||||||
|
- LED
|
||||||
|
- Buzzer
|
||||||
|
- Keypad
|
||||||
|
- Output (GPIOs)
|
||||||
|
- Input Control (GPIOs)
|
||||||
|
- Displays
|
||||||
|
- Device status (tamper, power, etc.,)
|
||||||
|
- Card Reader
|
||||||
|
- Fingerprint Reader
|
11
samples/subsys/mgmt/osdp/prj.conf
Normal file
11
samples/subsys/mgmt/osdp/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 Siddharth Chandrasekaran <siddharth@embedjournal.com>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
CONFIG_PRINTK=y
|
||||||
|
CONFIG_LOG=y
|
||||||
|
|
||||||
|
# OSDP config
|
||||||
|
CONFIG_OSDP=y
|
71
samples/subsys/mgmt/osdp/src/main.c
Normal file
71
samples/subsys/mgmt/osdp/src/main.c
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Siddharth Chandrasekaran <siddharth@embedjournal.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <device.h>
|
||||||
|
#include <drivers/gpio.h>
|
||||||
|
#include <mgmt/osdp.h>
|
||||||
|
|
||||||
|
/* The devicetree node identifier for the "led0" alias. */
|
||||||
|
#define LED0_NODE DT_ALIAS(led0)
|
||||||
|
|
||||||
|
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
|
||||||
|
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
|
||||||
|
#define PIN DT_GPIO_PIN(LED0_NODE, gpios)
|
||||||
|
#if DT_PHA_HAS_CELL(LED0_NODE, gpios, flags)
|
||||||
|
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#error "BOARD does not define a debug LED"
|
||||||
|
#define LED0 ""
|
||||||
|
#define PIN 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FLAGS
|
||||||
|
#define FLAGS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SLEEP_TIME_MS 10
|
||||||
|
|
||||||
|
int cmd_handler(struct osdp_cmd *p)
|
||||||
|
{
|
||||||
|
printk("App received command %d\n", p->id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
int ret, led_state;
|
||||||
|
uint32_t cnt = 0;
|
||||||
|
struct device *dev;
|
||||||
|
struct osdp_cmd cmd;
|
||||||
|
|
||||||
|
dev = device_get_binding(LED0);
|
||||||
|
if (dev == NULL) {
|
||||||
|
printk("Failed to get LED0 binding\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
|
||||||
|
if (ret < 0) {
|
||||||
|
printk("Failed to configure gpio pin\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
led_state = 0;
|
||||||
|
while (1) {
|
||||||
|
if ((cnt & 0x7f) == 0x7f) {
|
||||||
|
/* show a sign of life */
|
||||||
|
led_state = !led_state;
|
||||||
|
}
|
||||||
|
if (osdp_pd_get_cmd(&cmd) == 0) {
|
||||||
|
cmd_handler(&cmd);
|
||||||
|
}
|
||||||
|
gpio_pin_set(dev, PIN, led_state);
|
||||||
|
k_msleep(SLEEP_TIME_MS);
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue