Added new services.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11770 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
parent
19c6dfea6d
commit
f9adf287c9
|
@ -141,6 +141,7 @@ CSRC = $(STARTUPSRC) \
|
||||||
$(TESTSRC) \
|
$(TESTSRC) \
|
||||||
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
|
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
|
||||||
tservices.c \
|
tservices.c \
|
||||||
|
proxies/tssockstub.c \
|
||||||
main.c
|
main.c
|
||||||
|
|
||||||
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
||||||
|
|
|
@ -17,9 +17,61 @@
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "chtssi.h"
|
#include "chtssi.h"
|
||||||
|
#include "proxies/tssockstub.h"
|
||||||
#include "rt_test_root.h"
|
#include "rt_test_root.h"
|
||||||
#include "oslib_test_root.h"
|
#include "oslib_test_root.h"
|
||||||
#include "chprintf.h"
|
#include "chprintf.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define SERVER_PORT_NUM 8080
|
||||||
|
#define SERVER_IP_ADDRESS "192.136.23.21"
|
||||||
|
|
||||||
|
void tcpexample(void) {
|
||||||
|
int socket_fd;
|
||||||
|
struct sockaddr_in ra;
|
||||||
|
|
||||||
|
int recv_data; char data_buffer[80];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates an TCP socket (SOCK_STREAM) with Internet Protocol Family
|
||||||
|
* (PF_INET). Protocol family and Address family related. For example
|
||||||
|
* PF_INET Protocol Family and AF_INET family are coupled.
|
||||||
|
*/
|
||||||
|
socket_fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
|
if ( socket_fd < 0 ) {
|
||||||
|
chprintf((BaseSequentialStream *)&SD1, "socket call failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Connects to server ip-address. */
|
||||||
|
memset(&ra, 0, sizeof(struct sockaddr_in));
|
||||||
|
ra.sin_family = AF_INET;
|
||||||
|
ra.sin_addr.s_addr = inet_addr(SERVER_IP_ADDRESS);
|
||||||
|
ra.sin_port = htons(SERVER_PORT_NUM);
|
||||||
|
|
||||||
|
|
||||||
|
if (connect(socket_fd, (struct sockaddr *)&ra,
|
||||||
|
sizeof (struct sockaddr_in)) < 0) {
|
||||||
|
chprintf((BaseSequentialStream *)&SD1, "connect failed \n");
|
||||||
|
close(socket_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (send(socket_fd, "Baba", sizeof "Baba", 0) < 0) {
|
||||||
|
chprintf((BaseSequentialStream *)&SD1, "send failed \n");
|
||||||
|
close(socket_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
recv_data = recv(socket_fd, data_buffer, sizeof data_buffer, 0);
|
||||||
|
if (recv_data < 0) {
|
||||||
|
chprintf((BaseSequentialStream *)&SD1, "recv failed \n");
|
||||||
|
close(socket_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data_buffer[recv_data] = '\0';
|
||||||
|
chprintf((BaseSequentialStream *)&SD1, "received data: %s\n",data_buffer);
|
||||||
|
close(socket_fd);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LED blinker thread, times are in milliseconds.
|
* LED blinker thread, times are in milliseconds.
|
||||||
|
@ -43,6 +95,8 @@ static THD_FUNCTION(Thread1, arg) {
|
||||||
chThdSleepMilliseconds(160);
|
chThdSleepMilliseconds(160);
|
||||||
palToggleLine(LINE_LED_BLUE);
|
palToggleLine(LINE_LED_BLUE);
|
||||||
chThdSleepMilliseconds(600);
|
chThdSleepMilliseconds(600);
|
||||||
|
tcpexample();
|
||||||
|
chThdSleepMilliseconds(5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +130,7 @@ int main(void) {
|
||||||
/*
|
/*
|
||||||
* Creates the blinker thread (and any other ancillary thread).
|
* Creates the blinker thread (and any other ancillary thread).
|
||||||
*/
|
*/
|
||||||
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL);
|
chThdCreateStatic(waThread1, sizeof waThread1, NORMALPRIO+10, Thread1, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* System initializations.
|
* System initializations.
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
|
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "chtssi.h"
|
#include "tservices.h"
|
||||||
|
#include "proxies/tssockstub.h"
|
||||||
#include "chprintf.h"
|
#include "chprintf.h"
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -50,28 +51,35 @@
|
||||||
static THD_WORKING_AREA(waTsSimpleService, 1024);
|
static THD_WORKING_AREA(waTsSimpleService, 1024);
|
||||||
static THD_FUNCTION(TsSimpleService, tsstate) {
|
static THD_FUNCTION(TsSimpleService, tsstate) {
|
||||||
|
|
||||||
/* WARNING: do not put blocking call out of the cycle,
|
BaseSequentialStream *ssp = (BaseSequentialStream*)&SD1;
|
||||||
i.e. no calls that suspend
|
|
||||||
the current thread!.*/
|
|
||||||
|
|
||||||
ts_state_t *svcp = tsstate;
|
ts_state_t *svcp = tsstate;
|
||||||
|
|
||||||
/* Start the request/process/response cycle.*/
|
/* Start the 'wait request / process / response' cycle.*/
|
||||||
while (tssiWaitRequest(tsstate) == SMC_SVC_OK) {
|
for (;/* ever */;) {
|
||||||
int i;
|
int i;
|
||||||
chprintf((BaseSequentialStream*)&SD1,
|
|
||||||
"TsSimpleService received a new request.\r\n");
|
/* Wait a service request.*/
|
||||||
|
msg_t r = tssiWaitRequest(tsstate);
|
||||||
|
|
||||||
|
/* Check if status is ko. It could not happen.*/
|
||||||
|
if (r != SMC_SVC_OK) {
|
||||||
|
chprintf(ssp, "Unexpected wait request error.\r\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process the request.*/
|
||||||
|
chprintf(ssp, "r = %d, TsSimpleService received a new request.\r\n", r);
|
||||||
if (svcp->ts_datalen > 0) {
|
if (svcp->ts_datalen > 0) {
|
||||||
*(TS_GET_DATA(svcp) + TS_GET_DATALEN(svcp) - 1) = '\0';
|
*(TS_GET_DATA(svcp) + TS_GET_DATALEN(svcp) - 1) = '\0';
|
||||||
chprintf((BaseSequentialStream*)&SD1,
|
chprintf(ssp, "My non secure 'alter ego' has a request.\r\n");
|
||||||
"My non secure 'alter ego' has a request.\r\n");
|
chprintf(ssp, "She tells: '");
|
||||||
chprintf((BaseSequentialStream*)&SD1,
|
chprintf(ssp, TS_GET_DATA(svcp));
|
||||||
"She tells: '");
|
chprintf(ssp, "'\r\n");
|
||||||
chprintf((BaseSequentialStream*)&SD1, TS_GET_DATA(svcp));
|
|
||||||
chprintf((BaseSequentialStream*)&SD1, "'\r\n");
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < 100000; ++i)
|
for (i = 0; i < 100000; ++i)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
/* Set the response.*/
|
||||||
TS_SET_STATUS(svcp, i);
|
TS_SET_STATUS(svcp, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +97,7 @@ static THD_FUNCTION(TsSimpleService, tsstate) {
|
||||||
TS_STATE_TABLE
|
TS_STATE_TABLE
|
||||||
TS_CONF_TABLE_BEGIN
|
TS_CONF_TABLE_BEGIN
|
||||||
TS_CONF_TABLE_ENTRY("TsSimpleService", waTsSimpleService, TS_BASE_PRIO, TsSimpleService, TS_STATE(0))
|
TS_CONF_TABLE_ENTRY("TsSimpleService", waTsSimpleService, TS_BASE_PRIO, TsSimpleService, TS_STATE(0))
|
||||||
|
TS_CONF_TABLE_ENTRY("TsStubsService", waTsStubsService, TS_BASE_PRIO+10, TsStubsService, TS_STATE(1))
|
||||||
TS_CONF_TABLE_END
|
TS_CONF_TABLE_END
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
Loading…
Reference in New Issue