/***********************************Callback**************************************************/ void goalCallback(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal) { std::vector<std::string> jointNames = goal->trajectory.joint_names; if (checkIfValid(jointNames)) { size_t commandSize = goal->trajectory.points.size(); for (int i = 0; i < commandSize - 1; ++i) { sensor_msgs::JointState command; command.name = goal->trajectory.joint_names; command.position = goal->trajectory.points[i].positions; command.velocity = goal->trajectory.points[i].velocities; command.effort = goal->trajectory.points[i].effort; _jointCommand.publish(command); ROS_INFO_STREAM(goal->trajectory.points[i]); clrFeedback(); _feedback.joint_names = jointNames; _feedback.desired.effort = goal->trajectory.points[i].effort; _feedback.desired.velocities = goal->trajectory.points[i].velocities; _feedback.desired.positions = goal->trajectory.points[i].positions; waitForExecution(); } sensor_msgs::JointState command; command.name = goal->trajectory.joint_names; command.position = goal->trajectory.points[commandSize - 1].positions; for(int i = 0; i < command.name.size(); ++i) { command.velocity.push_back(0.2); } command.effort = goal->trajectory.points[commandSize - 1].effort; rosInfo("Last"); _jointCommand.publish(command); clrFeedback(); _feedback.joint_names = jointNames; _feedback.desired.effort = goal->trajectory.points[commandSize - 1].effort; _feedback.desired.velocities = goal->trajectory.points[commandSize - 1].velocities; _feedback.desired.positions = goal->trajectory.points[commandSize - 1].positions; waitForExecution(); _result.error_code = control_msgs::FollowJointTrajectoryResult::SUCCESSFUL; _result.error_string = "Cool"; _actionServer.setSucceeded(_result); } else { _result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS; _result.error_string = "Not cool"; _actionServer.setAborted(_result); } }
void main(void) { char twoDimArray[9][9]; char characterArray[81]; int row,col; int c,numChars, inputRecord,inputCharacters; int i,j,k; i = j = k= 0; row = col = numChars = 0; inputCharacters = 1; inputRecord = 1; int x = checkIfValid(characterArray,twoDimArray, inputCharacters); }
QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv, const QString &p, const QString &iface, const QDBusConnection& con, bool isDynamic) : connection(con), service(serv), path(p), interface(iface), lastError(checkIfValid(serv, p, iface, isDynamic)), isValid(!lastError.isValid()) { if (!isValid) return; if (!connection.isConnected()) { lastError = QDBusError(QDBusError::Disconnected, QLatin1String("Not connected to D-Bus server")); } else if (!service.isEmpty()) { currentOwner = connectionPrivate()->getNameOwner(service); // verify the name owner if (currentOwner.isEmpty()) { lastError = connectionPrivate()->lastError; } } }
/********************************** * Reference: http://www.programminglogic.com/example-of-client-server-program-in-c-using-sockets-and-tcp/ * Reference: http://www-scf.usc.edu/~bagde/networksproject/multiserver.c * Reference: http://stackoverflow.com/questions/8777055/using-select-in-client-server-acknowledgement-in-c * Reference: http://stackoverflow.com/questions/5660393/c-socket-client * Reference: http://codereview.stackexchange.com/questions/41748/small-one-time-pad-encryption-program * Reference: http://www.binarytides.com/server-client-example-c-sockets-linux/ * Reference: http://www.tutorialspoint.com/unix_sockets/socket_server_example.htm * Reference: http://beej.us/guide/bgnet/output/html/multipage/clientserver.html * Reference: http://www.binarytides.com/socket-programming-c-linux-tutorial/ ***********************************/ int main(int argc, char** argv) { char cipher[BUFF_SIZE]; char key[BUFF_SIZE]; char acknowledge[1]; int fd; int i; int port; int keyLength; int numSent; int textLength; int sockfd; int isValid; struct sockaddr_in serv_addr; struct hostent *server; if (argc < 4) //check for the correct number of arguments { printf("Error in otp_enc: not enough arguments\n"); exit(1); } port = atoi(argv[3]); //get port if (port < 0 || port > 65535) { printf("Error in otp_enc: Not a valid port\n"); exit(1); } fd = open(argv[1], O_RDONLY); if (fd < 0) //check if the file can be read { printf("Error in otp_enc: cannot open plaintext file %s\n", argv[1]); exit(1); } textLength = read(fd, cipher, BUFF_SIZE); //get the context of the file and the number of bytes isValid = checkIfValid(textLength, cipher); //check if file is valid if (isValid == 0) { printf("Error in otp_enc: ciphertext contains bad characters\n"); exit(1); } close(fd); fd = open(argv[2], O_RDONLY); //check if key is valid key if (fd < 0) { printf("Error in otp_enc: cannot open key file %s\n", argv[2]); exit(1); } keyLength = read(fd, key, BUFF_SIZE); //get the context of the key and the number of bytes isValid = checkIfValid(keyLength, key); //check if context of key is valid if (isValid == 0) { printf("Error in otp_enc: key contains bad characters\n"); exit(1); } close(fd); if (keyLength < textLength) //error out if the key to smaller than the file { printf("Error in otp_enc: key '%s' is too small\n", argv[2]); } sockfd = socket(AF_INET, SOCK_STREAM, 0); //create socket if (sockfd < 0) { printf("Error in otp_enc: could not contact otp_enc_d on port %d\n", port); exit(2); } bzero((char *)&serv_addr, sizeof(serv_addr)); //clear address server = gethostbyname("localhost"); if (server == NULL) { printf("Error in otp_enc: could not connect to otp_enc_d\n"); exit(2); } serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(port); if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) //connect to otp_enc_d { printf("Error in otp_enc: could not connect to otp_enc_d on port %d\n", port); exit(2); } numSent = write(sockfd, cipher, textLength - 1); //send text to otp_enc_d if (numSent < textLength - 1) { printf("Error in otp_enc: could not send plaintext to otp_enc_d on port %d\n", port); exit(2); } int receivedNum; bzero(acknowledge, sizeof(acknowledge)); receivedNum = read(sockfd, acknowledge, 1); if (receivedNum < 0) { printf("Error in otp_enc: could not receive acknowledgement from otp_enc_d\n"); exit(2); } numSent = write(sockfd, key, keyLength - 1); //send key to otp_enc_d if (numSent < keyLength - 1) { printf("Error in otp_enc: could not send key to otp_enc_d on port %d\n", port); exit(2); } bzero(cipher, sizeof(cipher)); //zero cipher while (receivedNum > 0) { receivedNum = read(sockfd, cipher, textLength - 1); //get text from otp_enc_d } for (i = 0; i < textLength - 1; i++) //print text { printf("%c", cipher[i]); } printf("\n"); close(sockfd); return 0; }