Skip to content

Commit

Permalink
examples: Fix makefile and some minor udpates
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Jun 4, 2024
1 parent c95b95f commit 1fd71f3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
12 changes: 12 additions & 0 deletions examples/c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

ROOT_DIR ?= ../..
BUILD_DIR ?= $(ROOT_DIR)/build

all:
gcc -I$(ROOT_DIR)/include cp_app.c -o cp_sample -L$(BUILD_DIR)/lib -losdp
gcc -I$(ROOT_DIR)/include pd_app.c -o pd_sample -L$(BUILD_DIR)/lib -losdp
4 changes: 2 additions & 2 deletions examples/c/cp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int sample_cp_send_func(void *data, uint8_t *buf, int len)
(void)(data);
(void)(buf);

// Fill these
// TODO (user): send buf of len bytes, over the UART channel.

return len;
}
Expand All @@ -33,7 +33,7 @@ int sample_cp_recv_func(void *data, uint8_t *buf, int len)
(void)(buf);
(void)(len);

// Fill these
// TODO (user): read from UART channel into buf, for upto len bytes.

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/c/pd_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int sample_pd_send_func(void *data, uint8_t *buf, int len)
(void)(data);
(void)(buf);

// Fill these
// TODO (user): send buf of len bytes, over the UART channel.

return len;
}
Expand All @@ -39,7 +39,7 @@ int sample_pd_recv_func(void *data, uint8_t *buf, int len)
(void)(buf);
(void)(len);

// Fill these
// TODO (user): read from UART channel into buf, for upto len bytes.

return 0;
}
Expand Down
12 changes: 10 additions & 2 deletions examples/cpp/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#
# Copyright (c) 2024 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

ROOT_DIR ?= ../..
BUILD_DIR ?= $(ROOT_DIR)/build

all:
g++ -std=c++0x -I../../include cp_app.cpp -o cp_sample -L../../build/lib -losdp
g++ -std=c++0x -I../../include pd_app.cpp -o pd_sample -L../../build/lib -losdp
g++ -std=c++0x -I$(ROOT_DIR)/include cp_app.cpp -o cp_sample -L$(BUILD_DIR)/lib -losdp
g++ -std=c++0x -I$(ROOT_DIR)/include pd_app.cpp -o pd_sample -L$(BUILD_DIR)/lib -losdp
13 changes: 11 additions & 2 deletions examples/cpp/cp_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int sample_cp_send_func(void *data, uint8_t *buf, int len)
(void)(data);
(void)(buf);

// Fill these
// TODO (user): send buf of len bytes, over the UART channel.

return len;
}
Expand All @@ -25,7 +25,7 @@ int sample_cp_recv_func(void *data, uint8_t *buf, int len)
(void)(buf);
(void)(len);

// Fill these
// TODO (user): read from UART channel into buf, for upto len bytes.

return 0;
}
Expand All @@ -49,6 +49,13 @@ osdp_pd_info_t pd_info[] = {
}
};

int event_handler(void *data, int pd, struct osdp_event *event) {
(void)(data);

std::cout << "PD" << pd << " EVENT: " << event->type << std::endl;
return 0;
}

int main()
{
OSDP::ControlPanel cp;
Expand All @@ -57,6 +64,8 @@ int main()

cp.setup(1, pd_info);

cp.set_event_callback(event_handler, nullptr);

while (1) {
// your application code.

Expand Down
20 changes: 10 additions & 10 deletions examples/cpp/pd_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int sample_pd_send_func(void *data, uint8_t *buf, int len)
(void)(data);
(void)(buf);

// Fill these
// TODO (user): send buf of len bytes, over the UART channel.

return len;
}
Expand All @@ -25,19 +25,11 @@ int sample_pd_recv_func(void *data, uint8_t *buf, int len)
(void)(buf);
(void)(len);

// Fill these
// TODO (user): read from UART channel into buf, for upto len bytes.

return 0;
}

int pd_command_handler(void *self, struct osdp_cmd *cmd)
{
(void)(self);

std::cout << "PD: CMD: " << cmd->id << std::endl;
return 0;
}

osdp_pd_info_t info_pd = {
.name = "pd[101]",
.baud_rate = 9600,
Expand Down Expand Up @@ -73,6 +65,14 @@ osdp_pd_info_t info_pd = {
.scbk = nullptr,
};

int pd_command_handler(void *data, struct osdp_cmd *cmd)
{
(void)(data);

std::cout << "PD: CMD: " << cmd->id << std::endl;
return 0;
}

int main()
{
OSDP::PeripheralDevice pd;
Expand Down

0 comments on commit 1fd71f3

Please sign in to comment.