주석에 보면 //이곳은 시리얼로부터 데이터를 수신했을 때 부분-->ListenfromSerial함수호출하여 사용하면 될까요?[센서네트워크]

ydgvnk70의 이미지

#include
#include
#include
#include
#include "tdef.h"
#include "ttype.h"
//시리얼 통신 관련 헤더파일
#include
#include
#include
#define TOSH_DATA_LENGTH 33
#define BAUDRATE B57600
#define MODEMDEVICE "/dev/ttyS2"

#define TOSH_DATA_LENGTH 33

struct TinyOS_Serial_MSG
{
unsigned short PT;
unsigned char SRC;
unsigned char DST;
unsigned char ST;
unsigned char data[TOSH_DATA_LENGTH];
unsigned short crc;
}__attribute__ ((packed)) TinyOS_Serial_MSG;

//////// Values for receiving data from serial ////////
struct TinyOS_Serial_MSG RecvMsg;
unsigned char RecvBuff[50];
unsigned char Startflag;
unsigned char SevenD_flag;
int Rindex;
///////////////////////////////////////////////////////

//////// Values for transmitting data to serial ////////
struct TinyOS_Serial_MSG SendMsg;
unsigned char SendBuff[50];
unsigned char Sindex;
unsigned short CRC_Value;
unsigned char Type = 0x0A;
unsigned char GroupID = 0x7D;
///////////////////////////////////////////////////////

int fd;

void Parsing_Buff(unsigned char *RecvBuff, unsigned char RecvLen);
void SendMsgtoSerial(unsigned char *SendData, unsigned char SendLen);

//이곳은 시리얼로부터 데이터를 수신했을때~~~~~~~~~~~~

void Parsing_Buff(unsigned char *RecvBuff, unsigned char RecvLen)
{
// RecvBuff[0] and [1] are 0x7E and 0x42
/* typedef struct TOS_Msg{
unsigned short PT;
unsigned char SRC;
unsigned char DST;
unsigned char ST;
int8_t DATA[TOSH_DATA_LENGTH];
unsigned short crc;
} */
int i;
memcpy(&RecvMsg.PT, RecvBuff+2, 2);
RecvMsg.SRC = RecvBuff[4];
RecvMsg.DST = RecvBuff[5];
RecvMsg.ST = RecvBuff[6];
for ( i=0 ; i RecvMsg.data[i] = RecvBuff[7+i];
}
}

unsigned short crcByte(unsigned short crc, unsigned char b)
{
unsigned char i;
crc = crc ^ b << 8;
i = 8;
do
if (crc & 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc = crc << 1;
while (--i);

return crc;
}
uint8_t
GetPacket_from_sensor(uHealthPDU *rPDU, uint8_t *RecvData) {

uHealthPDU *ptr=rPDU;
uint8_t i;
TinyOS_Serial_MSG *RecvMsg = (TinyOS_Serial_MSG *) RecvData;

uint8_t buffer[40];
int n;

/* memset((uint8_t *) rPDU, 0x0, sizeof(uHealthPDU)); */
if (fd > 0) {
memset(buffer, 0x0, 40);
n = read(fd, buffer, 40);
strncpy((uint8_t *) rPDU, buffer, n);
close(fd);
return (rPDU->PT);
}
else {
return(FAIL);
}

// ----------------------------------------
}

uHealthPDU *
MakePacket_to_sensor(uHealthPDU rPDU, uint8_t *Tokenset) {

uHealthPDU *ptr;

ptr = (uHealthPDU *) malloc(sizeof(uHealthPDU));

memset(ptr, 0x0, sizeof(uHealthPDU));
ptr->PT = CON_RES;
ptr->SRC = rPDU.DST;
ptr->DST = rPDU.SRC;
ptr->ST = rPDU.ST;
strcpy((uint8_t *) ptr+4, Tokenset);

return(ptr);

}
int
SendPacket_to_sensor(uHealthPDU *sPDU) {

// 테스트코드 ---------------------------

int fd, n;

fd = open("data/serial.out", O_WRONLY | O_CREAT, 0644);
if (fd > 0) {
n = write(fd, sPDU, strlen((uint8_t *) sPDU));
close(fd);
return (SUCCESS);
}
else {
return(FAIL);
}

// ----------------------------------------
}

int
FlushPacket(uHealthPDU *PDU) {

if (PDU != (uHealthPDU *) NULL)
free(PDU);

}

uint8_t
*DecrytionPacket(uHealthPDU rPDU, uint8_t *key) {

uint8_t len =0;
uint8_t str[2];
uint8_t *MedicalData;

str[0] = rPDU.data[2];
str[1] = 0x0;
len = atoi(str);

MedicalData = (uint8_t *) malloc (sizeof(uint8_t) * 30);
memset(MedicalData, 0x0, 30);
strncpy(MedicalData, &(rPDU.data[3]),len);

RC4( key, sizeof(key), MedicalData, len );
printf("CONNECTED | 수신데이터 복호화결과 :(%s)\n",MedicalData);

return ((uint8_t *) MedicalData);
}

int
SaveData_to_buffer(uint8_t *PureData) {

// 테스트코드 ---------------------------

int fd, n;

fd = open("data/pure.data", O_WRONLY | O_CREAT | O_APPEND , 0644);
if (fd > 0) {
n = write(fd, PureData, strlen((uint8_t *) PureData));
close(fd);
return (SUCCESS);
}
else {
return(FAIL);
}
// ----------------------------------------
}

uHealthPDU *
MakeTimeSessionPacket_to_sensor(uHealthPDU rPDU, uint8_t i, uint8_t k) {

uHealthPDU *ptr;
uint8_t buffer[3];

ptr = (uHealthPDU *) malloc(sizeof(uHealthPDU));

memset(buffer, 0x0, 3);
memset(ptr, 0x0, sizeof(uHealthPDU));

ptr->PT = TOKEN_REQ;
ptr->SRC = rPDU.DST;
ptr->DST = rPDU.SRC;
ptr->ST = rPDU.ST;
sprintf(buffer,"%d%d",i,k);
ptr->data[0] = buffer[0];
ptr->data[1] = buffer[1];

return(ptr);
}

int
Generate_RandomTokenID(uint8_t *ti,uint8_t *tk) {

*ti = 1+(int) (5.0*rand()/(RAND_MAX+1.0));
*tk = 1+(int) (5.0*rand()/(RAND_MAX+1.0));
}

uint8_t
VerifyChallengeKey(uHealthPDU rPDU, uint8_t *key) {

return(SUCCESS);
}

int
SetTimeoutValue(uint8_t *stype) {

return(SUCCESS);

}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.