-
Notifications
You must be signed in to change notification settings - Fork 2
/
tsu_connector.c
60 lines (53 loc) · 1.71 KB
/
tsu_connector.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2018 The go-hpb Authors
// This file is part of the go-hpb.
//
// The go-hpb is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-hpb is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-hpb. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "tsu_connector.h"
#include "common.h"
#include "atomic.h"
#define TRACE() printf("func:%s,line:%d\n", __FUNCTION__, __LINE__)
static uint32_t g_sequence = 0;
static const unsigned char g_tsu_version = 0x10;
#define fetch_tsu_package_sequence() atomic_fetch_and_add(&g_sequence,1)
T_Package* tsu_package_new(uint8_t fid, uint32_t len, uint8_t hash_flag)
{
T_Package *p = (T_Package*)malloc(sizeof(T_Package)+len);
if(p)
{
p->sequence = fetch_tsu_package_sequence();
p->version = g_tsu_version;
p->status= 0;
p->function_id = fid;
if(1 == hash_flag)
{
p->sub_function = 1;//check hash
}
else
{
p->sub_function = 0;//get hash
}
}
return p;
}
int tsu_set_data(T_Package* p, uint16_t offset, uint8_t* data, uint32_t len)
{
memcpy(p->payload+offset, data, len);
return 0;
}
void tsu_finish_package(T_Package *p)
{
}