Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
snoato committed Jan 18, 2016
2 parents f30ef8f + c8ad91b commit 2e671f3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
43 changes: 36 additions & 7 deletions RSAL/LINKV1.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ int motorStat4 = 0;

void init(){
enable_servos();

}

char* getDigitalWrapped(int port){
Expand Down Expand Up @@ -143,7 +142,15 @@ char* generateConnLAO(){
json_object_dotset_string(root_object_lao, "ConnLAO.Controller.Motor 3.Motor 4 Button.ControlType", "Button");
json_object_dotset_string(root_object_lao, "ConnLAO.Controller.Motor 3.Motor 4 Button.Descriptor", "Switch");

return json_serialize_to_string_pretty(root_value_lao);
char* result = json_serialize_to_string_pretty(root_value_lao);

//Free up variables
free(root_value_lao);
free(root_object_lao);
root_value_lao = 0;
root_object_lao = 0;

return result;
}

char* generateDataMsg(){
Expand All @@ -167,14 +174,22 @@ char* generateDataMsg(){
json_object_dotset_string(root_object, "Data.Digital 14", getDigitalWrapped(14));
json_object_dotset_string(root_object, "Data.Digital 15", getDigitalWrapped(15));

return json_serialize_to_string_pretty(root_value);

char* result = json_serialize_to_string_pretty(root_value);

//Free up variables
free(root_value);
free(root_object);
root_value = 0;
root_object = 0;

return result;
}

void control(char* msg){
ctrl_root_value = json_parse_string(msg);


input = json_value_get_object(ctrl_root_value);

if(json_object_dotget_string(input, "Control.Motor 1 Button") != NULL){
if(motorStat1 == 0){
motorStat1 = 1;
Expand Down Expand Up @@ -262,15 +277,29 @@ void control(char* msg){
if((number = (int)json_object_dotget_number(input, "Control.Slider S4")) != 0){
servoPos4 = number;
}

//Free up variables
free(ctrl_root_value);
free(input);
input = 0;
ctrl_root_value = 0;
}

int is_get(char * msg){
int returnStatus = 0;
ctrl_root_value = json_parse_string(msg);

input = json_value_get_object(ctrl_root_value);

if(json_object_dotget_string(input, "GET") != NULL){
return 1;
returnStatus = 1;
}
return 0;

//Free up variables
free(ctrl_root_value);
free(input);
input = 0;
ctrl_root_value = 0;

return returnStatus;
}
18 changes: 9 additions & 9 deletions RSAL/RSAL.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MIDaC KIPR Link ROSL (Robotic System Abstraction Layer)
Version 0.1
MIDaC KIPR Link RSAL (Robotic System Abstraction Layer)
Version 0.9
*/
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -18,27 +18,28 @@ struct sockaddr_un remote;
char str[2048];

void sendMsg(char* msg){
if(strlen(msg) > 2047){
int ward = (strlen(msg)/2048) + 1;
int lenghtOfMsg = strlen(msg);
if(lenghtOfMsg > 2047){
int ward = (lenghtOfMsg/2048) + 1;
char* message = malloc(2048*ward);
strcpy(message, msg);
for(i=strlen(msg); i<2048*ward; i++){
for(i=lenghtOfMsg; i<2048*ward; i++){
message[i] = ' ';
}
message[2048*ward] = '\0';
if (send(sock, message, strlen(message), 0) == -1) {
if (send(sock, message, lenghtOfMsg, 0) == -1) {
perror("send");
exit(1);
}
free(message);
}else{
char* message = malloc(2048);
strcpy(message, msg);
for(i=strlen(msg); i<2048; i++){
for(i=lenghtOfMsg; i<2048; i++){
message[i] = ' ';
}
message[2048] = '\0';
if (send(sock, message, strlen(message), 0) == -1) {
if (send(sock, message, lenghtOfMsg, 0) == -1) {
perror("send");
exit(1);
}
Expand Down Expand Up @@ -73,7 +74,6 @@ int main(int argc, char *argv[])
exit(1);
}


remote.sun_family = AF_UNIX;
strcpy(remote.sun_path, SOCK_PATH);
len = strlen(remote.sun_path) + sizeof(remote.sun_family) + 1;
Expand Down

0 comments on commit 2e671f3

Please sign in to comment.