Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zzha zzha
OpenXG-RAN
Commits
a55f4006
Commit
a55f4006
authored
6 years ago
by
laurent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change thread/core assignment, initial commit of replay IQ
parent
2e6d9d7d
Branches unavailable
2024.w06
2024.w05
2024.w04
2024.w03
2024.w02
2024.w01
2023.w51
2023.w50
2023.w49
2023.w48
2023.w47
2023.w45
2023.w43
2023.w42
2023.w41
2023.w40
2023.w39
2023.w38
2023.w37
2023.w36
2023.w34
2023.w33
2023.w32
2023.w31
2023.w30
2023.w29
2023.w28
2023.w27
2023.w26
2023.w25
2023.w24
2023.w23
2023.w22
2023.w21
2023.w20
2023.w19
2023.w18
2023.w18b
2023.w16
2023.w15
2023.w14
2023.w13
2023.w12
2023.w11
2023.w11b
2023.w10
2023.w10b
2023.w09
2023.w08
2023.w08b
2023.w07
2023.w06
2023.w05
2023.w03
2023.w02
2022.42
2022.41
2022.w51
2022.w50
2022.w49
2022.w48
2022.w47
2022.w46
2022.w45
2022.w43
2022.w42
2022.w42b
2022.w41
2022.w40
2022.w39
2022.w38
2022.w37
2022.w37b
2022.w36
2022.w35
2022.w33
2022.w32
2022.w31
2022.w31b
2022.w30
2022.w29
2022.w26
2022.w25
2022.w24
2022.w24b
2022.w23
2022.w22
2022.w21
2022.w20
2022.w19
2022.w18
2022.w17
2022.w15
2022.w15b
2022.w14a
2022.w13
2022.w13b
2022.w13a
2022.w12
2022.w10
2022.w09
2022.w09b
2022.w08
2022.w08b
2022.w07
2022.w07b
2022.w06
2022.w06a
2022.w05
2022.w05b
2022.w03_hotfix
2022.w03_b
2022.w02
2022.w01
2021.wk46
2021.wk14_a
2021.wk13_d
2021.wk13_c
2021.w51_c
2021.w51_a
2021.w50_a
2021.w49_b
2021.w49_a
2021.w48
2021.w47
2021.w46
2021.w46-powder
2021.w45
2021.w45_b
2021.w44
2021.w43
2021.w42
2021.w37
2021.w36
2021.w35
2021.w34
2021.w33
2021.w32
2021.w31
2021.w30
2021.w29
2021.w28
2021.w27
2021.w26
2021.w25
2021.w24
2021.w23
2021.w22
2021.w20
2021.w19
2021.w18_b
2021.w18_a
2021.w17_b
2021.w16
2021.w15
2021.w14
2021.w13_a
2021.w12
2021.w11
2021.w10
2021.w09
2021.w08
2021.w06
2021.w05
2021.w04
2021.w02
2020.w51_2
2020.w51
2020.w50
2020.w49
2020.w48_2
2020.w48
2020.w47
2020.w46_2
2020.w46
2020.w45_2
2020.w45
2020.w44
2020.w42_2
2020.w42
2020.w41
2020.w39
2020.w38
2020.w37
2020.w36
2020.w34
2020.w33
2020.w31
2020.w30
2020.w29
2020.w28
2020.w26
2020.w25
2020.w24
2020.w23
2020.w22
2020.w19
2020.w17
2020.w16
2020.w15
2020.w11
2020.w09
2020.w06
2020.w05
2020.w04
2020.w03
v2.1.0
v2.0.0
setparam
nr-ip-over-lte-v.1.5
nr-ip-over-lte-v.1.4
nr-ip-over-lte-v.1.3
nr-ip-over-lte-v.1.2
nr-ip-over-lte-v.1.1
nr-ip-over-lte-v.1.0
flexran-eol
develop-nr-2020w03
develop-nr-2020w02
develop-nr-2019w51
develop-nr-2019w50
develop-nr-2019w48
develop-nr-2019w47
develop-nr-2019w45
develop-nr-2019w43
develop-nr-2019w42
develop-nr-2019w40
develop-nr-2019w28
develop-nr-2019w23
benetel_phase_rotation
benetel_gnb_rel_2.0
benetel_gnb_rel_1.0
benetel_enb_rel_2.0
benetel_enb_rel_1.0
No related merge requests found
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
340 additions
and
105 deletions
+340
-105
cmake_targets/CMakeLists.txt
cmake_targets/CMakeLists.txt
+18
-0
common/utils/minimal_stub.c
common/utils/minimal_stub.c
+4
-0
common/utils/simple_executable.h
common/utils/simple_executable.h
+33
-0
common/utils/threadPool/measurement_display.c
common/utils/threadPool/measurement_display.c
+2
-16
executables/nr-ue.c
executables/nr-ue.c
+29
-0
executables/nr-uesoftmodem.c
executables/nr-uesoftmodem.c
+1
-4
executables/nr-uesoftmodem.h
executables/nr-uesoftmodem.h
+0
-1
targets/ARCH/COMMON/common_lib.h
targets/ARCH/COMMON/common_lib.h
+79
-63
targets/ARCH/rfsimulator/simulator.c
targets/ARCH/rfsimulator/simulator.c
+32
-21
targets/ARCH/rfsimulator/stored_node.c
targets/ARCH/rfsimulator/stored_node.c
+142
-0
No files found.
cmake_targets/CMakeLists.txt
View file @
a55f4006
...
...
@@ -2155,6 +2155,24 @@ add_definitions(-DASN1_MINIMUM_VERSION=924)
#################################
# add executables for operation
#################################
add_library
(
minimal_lib
${
OPENAIR_DIR
}
/common/utils/backtrace.c
${
OPENAIR_DIR
}
/common/utils/LOG/log.c
${
OPENAIR_DIR
}
/common/config/config_userapi.c
${
OPENAIR_DIR
}
/common/config/config_load_configmodule.c
${
OPENAIR_DIR
}
/common/config/config_cmdline.c
${
OPENAIR_DIR
}
/common/utils/minimal_stub.c
)
target_link_libraries
(
minimal_lib pthread dl
)
add_executable
(
replay_node
${
OPENAIR_TARGETS
}
/ARCH/rfsimulator/stored_node.c
)
target_link_libraries
(
replay_node minimal_lib
)
add_executable
(
measurement_display
${
OPENAIR_DIR
}
/common/utils/threadPool/measurement_display.c
)
target_link_libraries
(
measurement_display minimal_lib
)
# lte-softmodem is both eNB and UE implementation
###################################################
...
...
This diff is collapsed.
Click to expand it.
common/utils/minimal_stub.c
0 → 100644
View file @
a55f4006
int
T_stdout
;
void
exit_function
(
const
char
*
file
,
const
char
*
function
,
const
int
line
,
const
char
*
s
)
{
}
This diff is collapsed.
Click to expand it.
common/utils/simple_executable.h
0 → 100644
View file @
a55f4006
#ifndef __SIMPLE_EXE_H__
#define __SIMPLE_EXE_H__
#define __USE_GNU
#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <common/utils/assertions.h>
#include <common/utils/LOG/log.h>
#include "common_lib.h"
#ifdef T
#undef T
#define T(...)
#endif
#endif
This diff is collapsed.
Click to expand it.
common/utils/threadPool/measurement_display.c
View file @
a55f4006
...
...
@@ -2,22 +2,8 @@
Author: Laurent THOMAS, Open Cells
copyleft: OpenAirInterface Software Alliance and it's licence
*/
#include <common/utils/simple_executable.h>
#define __USE_GNU
#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "thread-pool.h"
#define SEP "\t"
...
...
@@ -26,7 +12,7 @@ uint64_t cpuCyclesMicroSec;
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
2
)
{
printf
(
"Need one paramter: the trace Linux pipe (fifo)"
);
printf
(
"Need one param
e
ter: the trace Linux pipe (fifo)"
);
exit
(
1
);
}
...
...
This diff is collapsed.
Click to expand it.
executables/nr-ue.c
View file @
a55f4006
...
...
@@ -125,6 +125,34 @@ extern double cpuf;
#define DAQ_PERIOD 66667ULL
#define FIFO_PRIORITY 40
void
init_thread
(
int
core
,
char
*
name
)
{
pthread_setname_np
(
pthread_self
(),
name
);
cpu_set_t
cpuset
;
CPU_ZERO
(
&
cpuset
);
if
(
core
>
0
)
CPU_SET
(
core
,
&
cpuset
);
AssertFatal
(
0
==
pthread_setaffinity_np
(
pthread_self
(),
sizeof
(
cpu_set_t
),
&
cpuset
),
""
);
struct
sched_param
sp
;
sp
.
sched_priority
=
FIFO_PRIORITY
;
AssertFatal
(
pthread_setschedparam
(
pthread_self
(),
SCHED_FIFO
,
&
sp
)
==
0
,
"Can't set thread priority, Are you root?
\n
"
);
/* Check the actual affinity mask assigned to the thread */
cpu_set_t
*
cset
=
CPU_ALLOC
(
CPU_SETSIZE
);
if
(
0
==
pthread_getaffinity_np
(
pthread_self
(),
CPU_ALLOC_SIZE
(
CPU_SETSIZE
),
cset
))
{
char
txt
[
512
]
=
{
0
};
for
(
int
j
=
0
;
j
<
CPU_SETSIZE
;
j
++
)
if
(
CPU_ISSET
(
j
,
cset
))
sprintf
(
txt
+
strlen
(
txt
),
" %d "
,
j
);
printf
(
"CPU Affinity of thread %s is %s
\n
"
,
name
,
txt
);
}
}
typedef
enum
{
pss
=
0
,
pbch
=
1
,
...
...
@@ -535,6 +563,7 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) {
}
void
*
UE_thread
(
void
*
arg
)
{
init_thread
(
1
,
"IQ samples"
);
PHY_VARS_NR_UE
*
UE
=
(
PHY_VARS_NR_UE
*
)
arg
;
// int tx_enabled = 0;
openair0_timestamp
timestamp
;
...
...
This diff is collapsed.
Click to expand it.
executables/nr-uesoftmodem.c
View file @
a55f4006
...
...
@@ -541,7 +541,6 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
frame_parms
[
CC_id
]
->
nb_antennas_tx
=
1
;
frame_parms
[
CC_id
]
->
nb_antennas_rx
=
1
;
//frame_parms[CC_id]->nushift = 0;
// NR: Init to legacy LTE 20Mhz params
frame_parms
[
CC_id
]
->
numerology_index
=
0
;
frame_parms
[
CC_id
]
->
ttis_per_subframe
=
1
;
...
...
@@ -685,7 +684,7 @@ int main( int argc, char **argv ) {
set_taus_seed
(
0
);
tpool_t
pool
;
Tpool
=
&
pool
;
char
params
[]
=
"
-1,-1,-1,-1
"
;
char
params
[]
=
"
2,3
"
;
initTpool
(
params
,
Tpool
,
false
);
cpuf
=
get_cpu_freq_GHz
();
itti_init
(
TASK_MAX
,
THREAD_MAX
,
MESSAGES_ID_MAX
,
tasks_info
,
messages_info
);
...
...
@@ -712,9 +711,7 @@ int main( int argc, char **argv ) {
frame_parms
[
CC_id
]
->
nb_antennas_rx
=
nb_antenna_rx
;
frame_parms
[
CC_id
]
->
nb_antenna_ports_eNB
=
1
;
//initial value overwritten by initial sync later
LOG_I
(
PHY
,
"Set nb_rx_antenna %d , nb_tx_antenna %d
\n
"
,
frame_parms
[
CC_id
]
->
nb_antennas_rx
,
frame_parms
[
CC_id
]
->
nb_antennas_tx
);
get_band
(
downlink_frequency
[
CC_id
][
0
],
&
frame_parms
[
CC_id
]
->
eutra_band
,
&
uplink_frequency_offset
[
CC_id
][
0
],
&
frame_parms
[
CC_id
]
->
frame_type
);
}
NB_UE_INST
=
1
;
...
...
This diff is collapsed.
Click to expand it.
executables/nr-uesoftmodem.h
View file @
a55f4006
...
...
@@ -236,7 +236,6 @@ extern double cpuf;
extern
int
setup_ue_buffers
(
PHY_VARS_NR_UE
**
phy_vars_ue
,
openair0_config_t
*
openair0_cfg
);
extern
void
fill_ue_band_info
(
void
);
extern
void
init_UE
(
int
);
extern
void
init_thread
(
int
sched_runtime
,
int
sched_deadline
,
int
sched_fifo
,
cpu_set_t
*
cpuset
,
char
*
name
);
extern
void
reset_opp_meas
(
void
);
extern
void
print_opp_meas
(
void
);
void
*
UE_thread
(
void
*
arg
);
...
...
This diff is collapsed.
Click to expand it.
targets/ARCH/COMMON/common_lib.h
View file @
a55f4006
This diff is collapsed.
Click to expand it.
targets/ARCH/rfsimulator/simulator.c
View file @
a55f4006
...
...
@@ -27,22 +27,15 @@
#define sample_t uint32_t // 2*16 bits complex number
#define sampleToByte(a,b) ((a)*(b)*sizeof(sample_t))
#define byteToSample(a,b) ((a)/(sizeof(sample_t)*(b)))
#define MAGICeNB 0xA5A5A5A5A5A5A5A5
#define MAGICUE 0x5A5A5A5A5A5A5A5A
typedef
struct
{
uint64_t
magic
;
uint32_t
size
;
uint32_t
nbAnt
;
uint64_t
timestamp
;
}
transferHeader
;
#define sample_t uint32_t // 2*16 bits complex number
typedef
struct
buffer_s
{
int
conn_sock
;
bool
alreadyRead
;
uint64_t
lastReceivedTS
;
bool
headerMode
;
transferHeader
th
;
samplesBlockHeader_t
th
;
char
*
transferPtr
;
uint64_t
remainToTransfer
;
char
*
circularBufEnd
;
...
...
@@ -55,6 +48,7 @@ typedef struct {
uint64_t
typeStamp
;
uint64_t
initialAhead
;
char
*
ip
;
int
saveIQfile
;
buffer_t
buf
[
FD_SETSIZE
];
}
rfsimulator_state_t
;
...
...
@@ -65,7 +59,7 @@ void allocCirBuf(rfsimulator_state_t *bridge, int sock) {
ptr
->
conn_sock
=
sock
;
ptr
->
headerMode
=
true
;
ptr
->
transferPtr
=
(
char
*
)
&
ptr
->
th
;
ptr
->
remainToTransfer
=
sizeof
(
transferHeader
);
ptr
->
remainToTransfer
=
sizeof
(
samplesBlockHeader_t
);
int
sendbuff
=
1000
*
1000
*
10
;
AssertFatal
(
setsockopt
(
sock
,
SOL_SOCKET
,
SO_SNDBUF
,
&
sendbuff
,
sizeof
(
sendbuff
))
==
0
,
""
);
struct
epoll_event
ev
=
{
0
};
...
...
@@ -87,7 +81,7 @@ void socketError(rfsimulator_state_t *bridge, int sock) {
LOG_W
(
HW
,
"Lost socket
\n
"
);
removeCirBuf
(
bridge
,
sock
);
if
(
bridge
->
typeStamp
==
MAGICUE
)
if
(
bridge
->
typeStamp
==
UE_MAGICDL_FDD
)
exit
(
1
);
}
}
...
...
@@ -120,6 +114,11 @@ void setblocking(int sock, enum blocking_t active) {
static
bool
flushInput
(
rfsimulator_state_t
*
t
);
void
fullwrite
(
int
fd
,
void
*
_buf
,
int
count
,
rfsimulator_state_t
*
t
)
{
if
(
t
->
saveIQfile
!=
-
1
)
{
if
(
write
(
t
->
saveIQfile
,
_buf
,
count
)
!=
count
)
LOG_E
(
HW
,
"write in save iq file failed (%s)
\n
"
,
strerror
(
errno
));
}
char
*
buf
=
_buf
;
int
l
;
setblocking
(
fd
,
notBlocking
);
...
...
@@ -145,7 +144,7 @@ void fullwrite(int fd, void *_buf, int count, rfsimulator_state_t *t) {
int
server_start
(
openair0_device
*
device
)
{
rfsimulator_state_t
*
t
=
(
rfsimulator_state_t
*
)
device
->
priv
;
t
->
typeStamp
=
MAGICeNB
;
t
->
typeStamp
=
ENB_MAGICDL_FDD
;
AssertFatal
((
t
->
listen_sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
>=
0
,
""
);
int
enable
=
1
;
AssertFatal
(
setsockopt
(
t
->
listen_sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
enable
,
sizeof
(
int
))
==
0
,
""
);
...
...
@@ -168,7 +167,7 @@ sin_addr:
int
start_ue
(
openair0_device
*
device
)
{
rfsimulator_state_t
*
t
=
device
->
priv
;
t
->
typeStamp
=
MAGICUE
;
t
->
typeStamp
=
UE_MAGICDL_FDD
;
int
sock
;
AssertFatal
((
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
>=
0
,
""
);
struct
sockaddr_in
addr
=
{
...
...
@@ -207,7 +206,7 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi
buffer_t
*
ptr
=&
t
->
buf
[
i
];
if
(
ptr
->
conn_sock
>=
0
)
{
transferHeader
header
=
{
t
->
typeStamp
,
nsamps
,
nbAnt
,
timestamp
};
samplesBlockHeader_t
header
=
{
t
->
typeStamp
,
nsamps
,
nbAnt
,
timestamp
};
fullwrite
(
ptr
->
conn_sock
,
&
header
,
sizeof
(
header
),
t
);
sample_t
tmpSamples
[
nsamps
][
nbAnt
];
...
...
@@ -290,8 +289,8 @@ static bool flushInput(rfsimulator_state_t *t) {
// check the header and start block transfer
if
(
b
->
headerMode
==
true
&&
b
->
remainToTransfer
==
0
)
{
AssertFatal
(
(
t
->
typeStamp
==
MAGICUE
&&
b
->
th
.
magic
==
MAGICeNB
)
||
(
t
->
typeStamp
==
MAGICeNB
&&
b
->
th
.
magic
==
MAGICUE
),
"Socket Error in protocol"
);
AssertFatal
(
(
t
->
typeStamp
==
UE_MAGICDL_FDD
&&
b
->
th
.
magic
==
ENB_MAGICDL_FDD
)
||
(
t
->
typeStamp
==
ENB_MAGICDL_FDD
&&
b
->
th
.
magic
==
UE_MAGICDL_FDD
),
"Socket Error in protocol"
);
b
->
headerMode
=
false
;
b
->
alreadyRead
=
true
;
...
...
@@ -322,7 +321,7 @@ static bool flushInput(rfsimulator_state_t *t) {
b
->
headerMode
=
true
;
b
->
transferPtr
=
(
char
*
)
&
b
->
th
;
b
->
remainToTransfer
=
sizeof
(
transferHeader
);
b
->
remainToTransfer
=
sizeof
(
samplesBlockHeader_t
);
b
->
th
.
magic
=-
1
;
}
}
...
...
@@ -447,10 +446,22 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
}
rfsimulator
->
typeStamp
=
strncasecmp
(
rfsimulator
->
ip
,
"enb"
,
3
)
==
0
?
MAGICeNB:
MAGICUE
;
LOG_I
(
HW
,
"rfsimulator: running as %s
\n
"
,
rfsimulator
->
typeStamp
==
MAGICeNB
?
"eNB"
:
"UE"
);
device
->
trx_start_func
=
rfsimulator
->
typeStamp
==
MAGICeNB
?
ENB_MAGICDL_FDD:
UE_MAGICDL_FDD
;
LOG_I
(
HW
,
"rfsimulator: running as %s
\n
"
,
rfsimulator
->
typeStamp
==
ENB_MAGICDL_FDD
?
"eNB"
:
"UE"
);
char
*
saveF
;
if
((
saveF
=
getenv
(
"saveIQfile"
))
!=
NULL
)
{
rfsimulator
->
saveIQfile
=
open
(
saveF
,
O_APPEND
|
O_CREAT
|
O_TRUNC
|
O_WRONLY
,
0666
);
if
(
rfsimulator
->
saveIQfile
!=
-
1
)
LOG_I
(
HW
,
"rfsimulator: will save written IQ samples in %s
\n
"
,
saveF
);
else
LOG_E
(
HW
,
"can't open %s for IQ saving (%s)
\n
"
,
saveF
,
strerror
(
errno
));
}
else
rfsimulator
->
saveIQfile
=
-
1
;
device
->
trx_start_func
=
rfsimulator
->
typeStamp
==
ENB_MAGICDL_FDD
?
server_start
:
start_ue
;
device
->
trx_get_stats_func
=
rfsimulator_get_stats
;
...
...
This diff is collapsed.
Click to expand it.
targets/ARCH/rfsimulator/stored_node.c
0 → 100644
View file @
a55f4006
/*
Author: Laurent THOMAS, Open Cells
copyleft: OpenAirInterface Software Alliance and it's licence
*/
#include <common/utils/simple_executable.h>
void
fullwrite
(
int
fd
,
void
*
_buf
,
int
count
)
{
char
*
buf
=
_buf
;
int
l
;
while
(
count
)
{
l
=
write
(
fd
,
buf
,
count
);
if
(
l
<=
0
)
{
if
(
errno
==
EINTR
)
continue
;
if
(
errno
==
EAGAIN
)
{
continue
;
}
else
{
AssertFatal
(
false
,
"Lost socket
\n
"
);
}
count
-=
l
;
buf
+=
l
;
}
}
}
int
server_start
(
short
port
)
{
int
listen_sock
;
AssertFatal
((
listen_sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
>=
0
,
""
);
int
enable
=
1
;
AssertFatal
(
setsockopt
(
listen_sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
enable
,
sizeof
(
int
))
==
0
,
""
);
struct
sockaddr_in
addr
=
{
sin_family:
AF_INET
,
sin_port:
htons
(
port
),
sin_addr:
{
s_addr
:
INADDR_ANY
}
};
bind
(
listen_sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
));
AssertFatal
(
listen
(
listen_sock
,
5
)
==
0
,
""
);
return
accept
(
listen_sock
,
NULL
,
NULL
);
}
int
client_start
(
char
*
IP
,
short
port
)
{
int
sock
;
AssertFatal
((
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
>=
0
,
""
);
struct
sockaddr_in
addr
=
{
sin_family:
AF_INET
,
sin_port:
htons
(
port
),
sin_addr:
{
s_addr
:
INADDR_ANY
}
};
addr
.
sin_addr
.
s_addr
=
inet_addr
(
IP
);
bool
connected
=
false
;
while
(
!
connected
)
{
LOG_I
(
HW
,
"rfsimulator: trying to connect to %s:%d
\n
"
,
IP
,
port
);
if
(
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
0
)
{
LOG_I
(
HW
,
"rfsimulator: connection established
\n
"
);
connected
=
true
;
}
perror
(
"simulated node"
);
sleep
(
1
);
}
return
sock
;
}
enum
blocking_t
{
notBlocking
,
blocking
};
void
setblocking
(
int
sock
,
enum
blocking_t
active
)
{
int
opts
;
AssertFatal
(
(
opts
=
fcntl
(
sock
,
F_GETFL
))
>=
0
,
""
);
if
(
active
==
blocking
)
opts
=
opts
&
~
O_NONBLOCK
;
else
opts
=
opts
|
O_NONBLOCK
;
AssertFatal
(
fcntl
(
sock
,
F_SETFL
,
opts
)
>=
0
,
""
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
4
)
{
printf
(
"Need parameters: source file, server or destination IP, TCP port
\n
"
);
exit
(
1
);
}
int
fd
;
AssertFatal
((
fd
=
open
(
argv
[
1
],
O_RDONLY
))
!=
-
1
,
"file: %s"
,
argv
[
1
]);
off_t
fileSize
=
lseek
(
fd
,
0
,
SEEK_END
);
int
serviceSock
;
if
(
strcmp
(
argv
[
2
],
"server"
)
==
0
)
{
serviceSock
=
server_start
(
atoi
(
argv
[
3
]));
}
else
{
client_start
(
argv
[
2
],
atoi
(
argv
[
3
]));
}
samplesBlockHeader_t
header
;
int
bufSize
=
100000
;
void
*
buff
=
malloc
(
bufSize
);
while
(
1
)
{
//Rewind the file to loop on the samples
if
(
lseek
(
fd
,
0
,
SEEK_CUR
)
>=
fileSize
)
lseek
(
fd
,
0
,
SEEK_SET
);
// Read one block and send it
setblocking
(
serviceSock
,
blocking
);
AssertFatal
(
read
(
fd
,
&
header
,
sizeof
(
header
)),
""
);
fullwrite
(
serviceSock
,
&
header
,
sizeof
(
header
));
int
dataSize
=
sizeof
(
sample_t
)
*
header
.
size
*
header
.
nbAnt
;
if
(
dataSize
>
bufSize
)
buff
=
realloc
(
buff
,
dataSize
);
AssertFatal
(
read
(
fd
,
buff
,
dataSize
)
==
dataSize
,
""
);
fullwrite
(
serviceSock
,
buff
,
dataSize
);
// Purge incoming samples
setblocking
(
serviceSock
,
notBlocking
);
while
(
recv
(
serviceSock
,
buff
,
bufSize
,
MSG_DONTWAIT
)
>
0
)
{
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment