create app for wiegand protocol

update app for wiegand protocol

improve wiegand app

app improvement and fix Kconig
This commit is contained in:
halyssonJr 2023-03-11 21:55:44 -03:00 committed by Alan Carvalho de Assis
parent a48810f4a5
commit 02db9c7612
4 changed files with 163 additions and 0 deletions

29
examples/wiegand/Kconfig Normal file
View File

@ -0,0 +1,29 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EXAMPLES_WIEGAND
tristate "Wiegand example"
default n
---help---
Enable the wiegand example
if EXAMPLES_WIEGAND
config EXAMPLES_WIEGAND_PROGNAME
string "Program name"
default "wiegand"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.
config EXAMPLES_WIEGAND_PRIORITY
int "wiegand task priority"
default 100
config EXAMPLES_WIEGAND_STACKSIZE
int "wiegand stack size"
default DEFAULT_TASK_STACKSIZE
endif

View File

@ -0,0 +1,23 @@
############################################################################
# apps/examples/wiegand/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifneq ($(CONFIG_EXAMPLES_WIEGAND),)
CONFIGURED_APPS += $(APPDIR)/examples/wiegand
endif

34
examples/wiegand/Makefile Normal file
View File

@ -0,0 +1,34 @@
############################################################################
# apps/examples/wiegand/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
# wiegand built-in application info
PROGNAME = $(CONFIG_EXAMPLES_WIEGAND_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_WIEGAND_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_WIEGAND_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_WIEGAND)
# wiegand Example
MAINSRC = wiegand.c
include $(APPDIR)/Application.mk

View File

@ -0,0 +1,77 @@
/****************************************************************************
* apps/examples/wiegand/wiegand.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <inttypes.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <nuttx/wiegand/wiegand.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Wiegand
****************************************************************************/
int main(int argc, FAR char *argv[])
{
int fd;
int ret;
struct wiegand_data_s data;
fd = open ("/dev/wiega0", O_RDONLY);
if (fd < 0)
{
printf("Erro: Failed to open \n");
return -1;
}
printf("Wiegand app is running\n");
while (1)
{
ret = read(fd, &data, sizeof(data));
if (ret > 0)
{
if (data.status == WIEGAND_SUCCESS)
{
printf("ABA Code: %d\n", data.aba_code);
printf("FC: %04x \n", data.facility_code);
printf("ID: %06x\n", data.id);
break;
}
}
sleep(1);
}
close (fd);
return 0;
}