Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Dependency: https://github.com/mortzdk/Websocket
- * This thread function constantly sends data read from serial port.
- */
- void *broadcastFromSerial(void *serialBuffer) {
- pthread_detach(pthread_self());
- (void) serialBuffer;
- char buffer[16] = "milannnnn<br>";
- int n = 100; // random value
- while(1) {
- usleep(1000000);
- ws_connection_close status;
- ws_message *m = message_new();
- m->len = strlen(buffer);
- char *temp = malloc( sizeof(char)*(m->len+1) );
- if (temp == NULL) {
- raise(SIGINT);
- break;
- }
- /*
- * Test koji generise promjenjiv sadrzaj za slanje.
- * https://stackoverflow.com/questions/2279379/how-to-convert-integer-to-char-in-c
- *
- * A char in C is already a number (the character's ASCII code), no conversion required.
- *
- * If you want to convert a digit to the corresponding character, you can simply add '0':
- *
- * c = i +'0';
- * The '0' is a character in the ASCll table.
- *
- */
- char a = (n % 10) + '0';
- buffer[7] = a ;
- memset(temp, '\0', (m->len+1));
- memcpy(temp, buffer, m->len);
- memset(temp, (n % 10) + '0' , 5);
- m->msg = temp;
- temp = NULL;
- if ( (status = encodeMessage(m)) != CONTINUE) {
- message_free(m);
- free(m);
- raise(SIGINT);
- break;;
- }
- list_multicast_all(l, m);
- message_free(m);
- free(m);
- n--;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement