summaryrefslogtreecommitdiff
authorDustin Frisch <dustin@dustin-frisch.de>2011-06-20 02:44:19 (GMT)
committer Dustin Frisch <dustin@dustin-frisch.de>2011-06-20 02:44:19 (GMT)
commitbba2e754c0162291c3969163c0d8fc9ea7ec16b6 (patch) (side-by-side diff)
tree9bd317e338e49763b5398e387391d43883f73ef8
parent04ed0441703fcdd1773049c0d6f13e4e663b92e8 (diff)
downloadsmartsens-server-master.zip
smartsens-server-master.tar.gz
Enhanced protocolHEADmaster
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/smartsens/server.h22
-rw-r--r--src/server.c72
2 files changed, 74 insertions, 20 deletions
diff --git a/include/smartsens/server.h b/include/smartsens/server.h
index 55d68d8..39d8739 100644
--- a/include/smartsens/server.h
+++ b/include/smartsens/server.h
@@ -102,16 +102,26 @@ uint8_t smartsens_server_client_event_capabilities(smartsens_server_client_t* cl
uint8_t smartsens_server_client_feedback_capabilities(smartsens_server_client_t* client);
+float smartsens_server_client_event_accelerometer_max(smartsens_server_client_t* client);
+
+float smartsens_server_client_event_gyroscope_max(smartsens_server_client_t* client);
+
+float smartsens_server_client_event_light_max(smartsens_server_client_t* client);
+
+float smartsens_server_client_event_magnetic_field_max(smartsens_server_client_t* client);
+
+float smartsens_server_client_event_proximity_max(smartsens_server_client_t* client);
+
/**
* Sends a vibration feedback to the client.
*/
-void smartsens_server_send_feedback_vibration(smartsens_server_client_t* client,
- uint16_t duration);
+void smartsens_server_send_feedback_vibrator(smartsens_server_client_t* client,
+ uint16_t duration);
-void smartsens_server_send_feedback_blink(smartsens_server_client_t* client,
- uint16_t duration);
+void smartsens_server_send_feedback_blinker(smartsens_server_client_t* client,
+ uint16_t duration);
-void smartsens_server_send_feedback_flash(smartsens_server_client_t* client,
- uint8_t status);
+void smartsens_server_send_feedback_flasher(smartsens_server_client_t* client,
+ uint8_t status);
#endif /* SMARTSENS_SERVER_H_ */
diff --git a/src/server.c b/src/server.c
index 709799f..d874a0e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1,5 +1,9 @@
#include "smartsens/server.h"
-#include "smartsens/protocol.h"
+
+#include <smartsens/protocol.h>
+#include <smartsens/protocol/ctrl.h>
+#include <smartsens/protocol/events.h>
+#include <smartsens/protocol/feedback.h>
#include <stdlib.h>
#include <stdint.h>
@@ -114,6 +118,12 @@ struct smartsens_server_client {
* The feedback capabilities of the device.
*/
uint8_t feedback_capabilities;
+
+ float event_accelerometer_max;
+ float event_gyroscope_max;
+ float event_light_max;
+ float event_magnetic_field_max;
+ float event_proximity_max;
};
void smartsens_server_disconnect(smartsens_server_client_t* client) {
@@ -126,6 +136,11 @@ void smartsens_server_disconnect(smartsens_server_client_t* client) {
/* Remove client from list of clients */
client->server->clients[client->id] = NULL;
+ /* Disconnect sockets of client */
+ close(client->socket_ctrl);
+ close(client->socket_event);
+ close(client->socket_feedback);
+
/* Free client */
free(client);
}
@@ -164,6 +179,7 @@ static void smartsens_server_ctrl_accept(smartsens_server_t* server,
/* Create client structure */
client = (smartsens_server_client_t*) malloc(sizeof(smartsens_server_client_t));
client->server = server;
+ client->data = NULL;
client->socket_ctrl = socket;
/* Assign client to next free slot */
@@ -198,6 +214,12 @@ static void smartsens_server_ctrl_accept(smartsens_server_t* server,
client->event_capabilities = device_info->event_capabilities;
client->feedback_capabilities = device_info->feedback_capabilities;
+ client->event_accelerometer_max = device_info->event_accelerometer_max;
+ client->event_gyroscope_max = device_info->event_gyroscope_max;
+ client->event_light_max = device_info->event_light_max;
+ client->event_magnetic_field_max = device_info->event_magnetic_field_max;
+ client->event_proximity_max = device_info->event_proximity_max;
+
/* Free received information */
free(device_info);
@@ -505,7 +527,9 @@ smartsens_server_client_t* smartsens_server_client(smartsens_server_t* server,
}
void* smartsens_server_client_data(smartsens_server_client_t* client) {
- return client->data;
+ return (client != NULL) ?
+ client->data :
+ NULL;
}
uint16_t smartsens_server_client_screen_width(smartsens_server_client_t* client) {
@@ -524,6 +548,26 @@ uint8_t smartsens_server_client_feedback_capabilities(smartsens_server_client_t*
return client->feedback_capabilities;
}
+float smartsens_server_client_event_accelerometer_max(smartsens_server_client_t* client) {
+ return client->event_accelerometer_max;
+}
+
+float smartsens_server_client_event_gyroscope_max(smartsens_server_client_t* client) {
+ return client->event_gyroscope_max;
+}
+
+float smartsens_server_client_event_light_max(smartsens_server_client_t* client) {
+ return client->event_light_max;
+}
+
+float smartsens_server_client_event_magnetic_field_max(smartsens_server_client_t* client) {
+ return client->event_magnetic_field_max;
+}
+
+float smartsens_server_client_event_proximity_max(smartsens_server_client_t* client) {
+ return client->event_proximity_max;
+}
+
uint8_t smartsens_server_send_feedback(smartsens_server_client_t* client,
const smartsens_packet_feedback_t* packet) {
/* Send event packet and receive return code */
@@ -532,15 +576,15 @@ uint8_t smartsens_server_send_feedback(smartsens_server_client_t* client,
sizeof(smartsens_packet_feedback_header_t) + SMARTSENS_PACKET_FEEDBACK_DATA_LENGTH[packet->header.type]);
}
-void smartsens_server_send_feedback_vibration(smartsens_server_client_t* client,
- uint16_t duration) {
+void smartsens_server_send_feedback_vibrator(smartsens_server_client_t* client,
+ uint16_t duration) {
smartsens_packet_feedback_t packet;
uint8_t rc;
/* Fill packet */
- packet.header.type = SMARTSENS_FEEDBACK_TYPE_VIBRATE;
+ packet.header.type = SMARTSENS_FEEDBACK_TYPE_VIBRATOR;
- packet.data.feedback_vibrate.duration = htons(duration);
+ packet.data.feedback_vibrator.duration = htons(duration);
rc = smartsens_server_send_feedback(client,
&packet);
@@ -549,15 +593,15 @@ void smartsens_server_send_feedback_vibration(smartsens_server_client_t* client,
}
}
-void smartsens_server_send_feedback_blink(smartsens_server_client_t* client,
- uint16_t duration) {
+void smartsens_server_send_feedback_blinker(smartsens_server_client_t* client,
+ uint16_t duration) {
smartsens_packet_feedback_t packet;
uint8_t rc;
/* Fill packet */
- packet.header.type = SMARTSENS_FEEDBACK_TYPE_BLINK;
+ packet.header.type = SMARTSENS_FEEDBACK_TYPE_BLINKER;
- packet.data.feedback_blink.duration = htons(duration);
+ packet.data.feedback_blinker.duration = htons(duration);
rc = smartsens_server_send_feedback(client,
&packet);
@@ -566,15 +610,15 @@ void smartsens_server_send_feedback_blink(smartsens_server_client_t* client,
}
}
-void smartsens_server_send_feedback_flash(smartsens_server_client_t* client,
- uint8_t status) {
+void smartsens_server_send_feedback_flasher(smartsens_server_client_t* client,
+ uint8_t status) {
smartsens_packet_feedback_t packet;
uint8_t rc;
/* Fill packet */
- packet.header.type = SMARTSENS_FEEDBACK_TYPE_FLASH;
+ packet.header.type = SMARTSENS_FEEDBACK_TYPE_FLASHER;
- packet.data.feedback_flash.status = status;
+ packet.data.feedback_flasher.status = status;
rc = smartsens_server_send_feedback(client,
&packet);