iCub-main
Loading...
Searching...
No Matches
template_buttons.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3 * Author: Valentina Gaggero
4 * email: valentina.gaggero@iit.it
5 * website: www.robotcub.org
6 * Permission is granted to copy, distribute, and/or modify this program
7 * under the terms of the GNU General Public License, version 2 or any
8 * later version published by the Free Software Foundation.
9 *
10 * A copy of the license can be found at
11 * http://www.robotcub.org/icub/license/gpl.txt
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 * Public License for more details
17*/
18
19/* @file template_buttons.c
20 @brief
21 @author valentina.gaggero@iit.it
22 @date 03/22/2013
23**/
24
25
26// --------------------------------------------------------------------------------------------------------------------
27// - external dependencies
28// --------------------------------------------------------------------------------------------------------------------
29
30
31
32// --------------------------------------------------------------------------------------------------------------------
33// - declaration of external variables
34// --------------------------------------------------------------------------------------------------------------------
35
36
37// --------------------------------------------------------------------------------------------------------------------
38// - declaration of extern public interface
39// --------------------------------------------------------------------------------------------------------------------
40#include "template_buttons.hpp"
41#include "OPCprotocolManager.h"
42
43// --------------------------------------------------------------------------------------------------------------------
44// - declaration of extern hidden interface
45// --------------------------------------------------------------------------------------------------------------------
46
47
48// --------------------------------------------------------------------------------------------------------------------
49// - #define with internal scope
50// --------------------------------------------------------------------------------------------------------------------
51
52
53
54// --------------------------------------------------------------------------------------------------------------------
55// - definition (and initialisation) of extern variables, but better using _get(), _set()
56// --------------------------------------------------------------------------------------------------------------------
57extern OPCprotocolManager *opcMan_ptr;
58
59
60
61// --------------------------------------------------------------------------------------------------------------------
62// - typedef with internal scope
63// --------------------------------------------------------------------------------------------------------------------
64
65
66
67// --------------------------------------------------------------------------------------------------------------------
68// - declaration of static functions
69// --------------------------------------------------------------------------------------------------------------------
70static uint32_t s_getAddressFromUser(void);
71
72// --------------------------------------------------------------------------------------------------------------------
73// - definition (and initialization) of static variables
74// --------------------------------------------------------------------------------------------------------------------
75
76
77// --------------------------------------------------------------------------------------------------------------------
78// - definition of extern public functions
79// --------------------------------------------------------------------------------------------------------------------
80void commands(void)
81{
82 printf("\nq: quit\n");
83 printf("0: ........\n");
84 printf("1: ........\n");
85 printf("2: ........\n");
86 printf("3: ........\n");
87 printf("4: ........\n");
88 printf("5: ........\n");
89 printf("\n");
90}
91
92static uint32_t s_getAddressFromUser(void)
93{
94 char addrstr[20];
95 uint32_t ip1,ip2,ip3,ip4, address=0;
96
97 printf("Insert destination host: x.x.x.x ");
98 scanf("%s", &addrstr[0]);
99 sscanf(addrstr,"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
100 address = (ip1<<24)|(ip2<<16)|(ip3<<8)|ip4 ;
101
102 return(address);
103}
104
105
106int32_t callback_button_x(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr, int16_t id)
107{
108 printf("button %d\n", id);
109
110 uint32_t dest_addr = s_getAddressFromUser();
111 uint16_t size = 0;
112 opcprotman_res_t res;
113
114 addr->set(4444, dest_addr);
115
116 if(opcMan_ptr == NULL)
117 {
118 printf("opcMan_ptr is NULL\n");
119 return(0);
120 }
121
122 res = opcprotman_Form(opcMan_ptr, opcprotman_opc_ask, id, NULL /*setdata*/, (opcprotman_message_t*)payload_ptr, &size);
123 if(opcprotman_OK != res)
124 {
125
126 printf("erron in former\n");
127 return(0);
128 }
129 printf("in button %d : size=%d \n", id, size);
130
131 return(size);
132}
133
134
135
136
137// fill the callback with your code
138uint32_t callback_button_0(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
139{
140 uint32_t dest_addr = s_getAddressFromUser();
141 uint16_t size = 0;
142
143
144// addr->set(4444, (10<<24)|(255<<16)|(72<<8)|19 );
145 addr->set(4444, dest_addr);
146
147// opcprotman_Form(opcMan_ptr, opcprotman_opc_ask, 1, NULL /*setdata*/, payload_ptr, &size);
148
149 return(size);
150}
151
152uint32_t callback_button_1(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
153{
154 return(callback_button_x(payload_ptr, payload_size, addr, 1));
155}
156
157uint32_t callback_button_2(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
158{
159 return(callback_button_x(payload_ptr, payload_size, addr, 2));
160}
161
162
163uint32_t callback_button_3(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
164{
165 return(0);
166}
167
168uint32_t callback_button_4(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
169{
170 return(0);
171}
172
173uint32_t callback_button_5(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
174{
175 return(0);
176}
177
178uint32_t callback_button_6(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
179{
180 return(0);
181}
182
183uint32_t callback_button_7(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
184{
185 return(0);
186}
187
188uint32_t callback_button_8(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
189{
190 return(0);
191}
192
193uint32_t callback_button_9(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
194{
195 return(0);
196}
197
198
199uint32_t callback_button_10(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
200{
201 return(0);
202}
203
uint32_t callback_button_3(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_8(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
int32_t callback_button_x(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr, int16_t id)
OPCprotocolManager * opcMan_ptr
Definition main.cpp:88
uint32_t callback_button_7(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_0(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_1(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_4(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_5(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
void commands(void)
uint32_t callback_button_2(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_10(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
static uint32_t s_getAddressFromUser(void)
uint32_t callback_button_6(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_9(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)