demo tweaks ...

pull/9/head
Ondřej Hruška 7 years ago
parent 8415f15c99
commit 87d1841fc8
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 23
      demo/demo.c
  2. 3
      demo/demo.h
  3. 2
      demo/hello/TF_Config.h
  4. 5
      demo/hello/master.c
  5. 5
      demo/hello/slave.c
  6. 6
      demo/utils.c

@ -28,9 +28,9 @@ void demo_disconn(void)
void TF_WriteImpl(const uint8_t *buff, size_t len)
{
printf("--------------------\n");
printf("\033[32mTF_WriteImpl - sending frame:\033[0m\n");
printf("\033[32m--- TX %ld bytes ---\033[0m\n", len);
dumpFrame(buff, len);
usleep(1000);
if (sockfd != -1) {
write(sockfd, buff, len);
@ -74,20 +74,10 @@ static int demo_client(void* unused)
printf("\n Child Process \n");
while ((n = read(sockfd, recvBuff, sizeof(recvBuff) - 1)) > 0) {
printf("\033[36m--- RX %ld bytes ---\033[0m\n", n);
dumpFrame(recvBuff, (size_t) n);
TF_Accept(recvBuff, (size_t) n);
}
// printf("\n End read \n");
//
// if (n < 0) {
// printf("\n Read error \n");
// }
//
// printf("\n Close sock \n");
// close(sockfd);
// sockfd = -1;
//
// return true;
return 0;
}
@ -130,7 +120,7 @@ static int demo_server(void* unused)
conn_disband = false;
while ((n = read(sockfd, recvBuff, sizeof(recvBuff) - 1)) > 0 && !conn_disband) {
printf("...read %ld\n", n);
printf("\033[36m--- RX %ld bytes ---\033[0m\n", n);
dumpFrame(recvBuff, n);
TF_Accept(recvBuff, (size_t) n);
}
@ -154,6 +144,11 @@ void signal_handler(int sig)
exit(sig);
}
void demo_sleep(void)
{
while(1) usleep(10);
}
void demo_init(TF_PEER peer)
{
signal(SIGTERM, signal_handler);

@ -11,6 +11,9 @@
#define PORT 9798
/** Sleep and wait for ^C */
void demo_sleep(void);
/** Init server - DOES NOT init TinyFrame! */
void demo_init(TF_PEER peer);

@ -10,7 +10,7 @@
#define TF_ID_BYTES 1
#define TF_LEN_BYTES 2
#define TF_TYPE_BYTES 1
#define TF_CKSUM_TYPE TF_CKSUM_CRC32
#define TF_CKSUM_TYPE TF_CKSUM_CRC16
#define TF_USE_SOF_BYTE 1
#define TF_SOF_BYTE 0x01
typedef uint16_t TF_TICKS;

@ -3,9 +3,6 @@
//
#include <stdio.h>
#include <stdlib.h>
#include <zconf.h>
#include "../../TinyFrame.h"
#include "../demo.h"
bool testIdListener(TF_MSG *msg)
@ -34,5 +31,5 @@ int main(void)
TF_QuerySimple(2, (pu8)"Query!", 6, testIdListener, 0);
while(1) usleep(10);
demo_sleep();
}

@ -3,9 +3,7 @@
//
#include <stdio.h>
#include "../../TinyFrame.h"
#include "../demo.h"
#include <unistd.h>
#include <memory.h>
bool helloListener(TF_MSG *msg)
@ -34,6 +32,5 @@ int main(void)
TF_AddTypeListener(2, replyListener);
demo_init(TF_SLAVE);
printf("MAIN PROCESS CONTINUES...\n");
while(1) usleep(10);
demo_sleep();
}

@ -18,15 +18,15 @@ void dumpFrame(const uint8_t *buff, size_t len)
}
printf("\n");
}
printf("--- end of frame ---\n");
printf("--- end of frame ---\n\n");
}
void dumpFrameInfo(TF_MSG *msg)
{
printf("\033[33mRX frame\n"
printf("\033[33mFrame info\n"
" type: %02Xh\n"
" data: \"%.*s\"\n"
" len: %u\n"
" id: %Xh\033[0m\n",
" id: %Xh\033[0m\n\n",
msg->type, msg->len, msg->data, msg->len, msg->frame_id);
}

Loading…
Cancel
Save