Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FS-ELAB
pilc2server
Commits
f335e299
Commit
f335e299
authored
Mar 02, 2022
by
Joshua Supra
Browse files
fixed a bug in network
parent
7e2a566e
Changes
5
Hide whitespace changes
Inline
Side-by-side
main.c
View file @
f335e299
...
...
@@ -77,10 +77,10 @@ int main (int argc, char *argv[]){
InitIOCards
(
IOCards
);
zmq_recive_data
[
1
]
=
malloc
(
sizeof
(
zmq_data
));
zmq_recive_data
[
1
]
->
data
=
(
unsigned
int
*
)
malloc
(
256
*
sizeof
(
char
));
zmq_recive_data
[
1
]
->
data
=
(
unsigned
int
*
)
malloc
(
256
*
sizeof
(
int
));
/* Initalize the network communication */
zmq_recive_data
[
0
]
=
malloc
(
sizeof
(
zmq_data
));
zmq_recive_data
[
0
]
->
data
=
(
unsigned
int
*
)
malloc
(
256
*
sizeof
(
char
));
zmq_recive_data
[
0
]
->
data
=
(
unsigned
int
*
)
malloc
(
256
*
sizeof
(
int
));
//zmq_recive_data[0]->NrOfBytes = (unsigned int *) malloc (sizeof(unsigned int));
...
...
@@ -101,7 +101,7 @@ int main (int argc, char *argv[]){
while
(
1
)
{
NrOfBytesReceived
[
0
]
=
zmq_recv
(
client_responder
,
zmq_recive_data
[
0
]
->
data
,
255
,
ZMQ_DONTWAIT
);
zmq_recive_data
[
0
]
->
data
,
1023
,
ZMQ_DONTWAIT
);
zmq_recive_data
[
0
]
->
socket
=
client_responder
;
if
(
NrOfBytesReceived
[
0
]
!=
-
1
)
{
zmq_recive_data
[
0
]
->
NrOfBytes
=
NrOfBytesReceived
[
0
];
...
...
@@ -118,7 +118,7 @@ int main (int argc, char *argv[]){
while
(
1
)
{
// NrOfBytesReceived[0] = -1;
NrOfBytesReceived
[
1
]
=
zmq_recv
(
gui_responder
,
zmq_recive_data
[
1
]
->
data
,
255
,
ZMQ_DONTWAIT
);
zmq_recive_data
[
1
]
->
data
,
1023
,
ZMQ_DONTWAIT
);
zmq_recive_data
[
1
]
->
socket
=
gui_responder
;
if
(
NrOfBytesReceived
[
1
]
!=
-
1
)
{
...
...
pilc2_functions/libpilc2.a
View file @
f335e299
No preview for this file type
pilc2_functions/pilc2_IO_GPIOs.c
View file @
f335e299
...
...
@@ -181,7 +181,7 @@ const char* IOCardType(unsigned char IOCard_ID){
*****************************************************************************/
char
InitIOCards
(
IOCardStruct
*
IOCard
){
unsigned
char
num_IO_cards
=
0
;
/* check each card slot for HW version */
for
(
int
i
=
0
;
i
<
16
;
i
++
){
WriteFPGA
(
SPI_CS_MUX_OFFSET
,
i
);
...
...
@@ -420,12 +420,9 @@ void *updateIOLeds(void *vargp) {
led_color
.
Green
=
25
;
led_color
.
Blue
=
0
;
break
;
}
}
WriteFrontLED
(
i
,
led_color
.
Red
,
led_color
.
Green
,
led_color
.
Blue
);
}
}
WriteFrontLED
(
i
,
led_color
.
Red
,
led_color
.
Green
,
led_color
.
Blue
);
mask
=
mask
<<
1
;
}
...
...
pilc2_functions/pilc2_network.c
View file @
f335e299
...
...
@@ -73,11 +73,15 @@ int FunctionCall(zmq_data *zmq_data_struct){
unsigned
int
command
=
zmq_data_struct
->
data
[
0
];
int
nbytes
=
0
;
int
value
=
1
;
/*for (int i = 0; i< zmq_data_struct->NrOfBytes >> 2; i++){
printf("%d\n",zmq_data_struct->data[i]);
}*/
FunctionNumber
=
zmq_data_struct
->
data
[
1
];
//printf("%d\n",((zmq_data_struct->NrOfBytes)>>2)-2);
for
(
int
i
=
0
;
i
<
((
zmq_data_struct
->
NrOfBytes
)
>>
2
)
-
2
;
i
++
){
funcArg
[
i
]
=
zmq_data_struct
->
data
[
2
+
i
];
//printf("%.8x\n",funcArg[i]);
//printf("%d\n",funcArg[i]);
}
switch
(
FunctionNumber
){
...
...
@@ -91,6 +95,9 @@ int FunctionCall(zmq_data *zmq_data_struct){
case
GET_PILC_INET
:
value
=
getPiLCinet
(
zmq_data_struct
);
break
;
case
GET_DATE
:
value
=
GetDate
(
zmq_data_struct
);
break
;
case
INIT_IO_CARDS
:
PiLC2InitIOCards
();
break
;
case
SPI_WRITE
:
PiLC2WSPI
(
funcArg
[
0
],
funcArg
[
1
],
funcArg
[
2
]);
break
;
case
SPI_READ
:
value
=
PiLC2RSPI
(
funcArg
[
0
],
funcArg
[
1
],
zmq_data_struct
->
socket
);
break
;
case
SET_IO_CFG
:
SetIOConfig
(
funcArg
);
break
;
}
if
(
value
==
1
){
//echo the command
...
...
@@ -489,7 +496,19 @@ int GetDate(zmq_data *zmq_data_struct) {
buffer
[
3
]
=
ptm
->
tm_hour
;
buffer
[
4
]
=
ptm
->
tm_min
;
buffer
[
5
]
=
ptm
->
tm_sec
;
buffer
[
6
]
=
CheckLink
();;
char
*
ifname
=
"eth1"
;
int
socId
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_IP
);
struct
ifreq
if_req
;
(
void
)
strncpy
(
if_req
.
ifr_name
,
ifname
,
sizeof
(
if_req
.
ifr_name
));
ioctl
(
socId
,
SIOCGIFFLAGS
,
&
if_req
);
close
(
socId
);
buffer
[
6
]
=
(
if_req
.
ifr_flags
&
IFF_UP
)
&&
(
if_req
.
ifr_flags
&
IFF_RUNNING
);
//printf("%i \n", buffer[1]);
...
...
@@ -499,16 +518,27 @@ int GetDate(zmq_data *zmq_data_struct) {
return
0
;
}
int
CheckLink
(
void
)
{
char
*
ifname
=
"eth1"
;
int
PiLC2RSPI
(
unsigned
int
card
,
unsigned
int
reg
,
void
*
socket
)
{
unsigned
int
value
;
WriteFPGA
(
SPI_CS_MUX_OFFSET
,
card
);
value
=
(
unsigned
int
)
ReadIOCard
(
reg
);
zmq_send
(
socket
,
&
value
,
4
,
0
);
return
0
;
}
int
socId
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_IP
);
void
PiLC2WSPI
(
unsigned
int
card
,
unsigned
int
reg
,
unsigned
int
data
)
{
struct
ifreq
if_req
;
(
void
)
strncpy
(
if_req
.
ifr_name
,
ifname
,
sizeof
(
if_req
.
ifr_name
));
ioctl
(
socId
,
SIOCGIFFLAGS
,
&
if_req
);
close
(
socId
);
WriteFPGA
(
SPI_CS_MUX_OFFSET
,
card
);
WriteIOCard
(
reg
,
data
);
}
return
(
if_req
.
ifr_flags
&
IFF_UP
)
&&
(
if_req
.
ifr_flags
&
IFF_RUNNING
);
void
SetIOConfig
(
unsigned
int
*
data
)
{
/*for(int i= 0; i <64; i++){
printf("%d\n", data[i]);
}*/
}
pilc2_functions/pilc2_network.h
View file @
f335e299
...
...
@@ -20,6 +20,9 @@
#define GET_PILC_INET 0x7
#define GET_DATE 0x8
#define INIT_IO_CARDS 0x9
#define SPI_WRITE 0xA
#define SPI_READ 0xB
#define SET_IO_CFG 0xC
typedef
struct
{
void
*
socket
;
...
...
@@ -44,8 +47,12 @@ int PiLC2GetRamData(unsigned int RAMBaseAddress, unsigned int numofdata, void *s
int
PiLC2GetIOCards
(
zmq_data
*
zmq_data_struct
);
int
getPiLCinet
(
zmq_data
*
zmq_data_struct
);
int
GetDate
(
zmq_data
*
zmq_data_struct
);
int
PiLC2RSPI
(
unsigned
int
card
,
unsigned
int
reg
,
void
*
socket
);
void
PiLC2WSPI
(
unsigned
int
card
,
unsigned
int
reg
,
unsigned
int
data
);
void
PiLC2InitIOCards
(
void
);
int
CheckLink
(
void
);
void
SetIOConfig
(
unsigned
int
*
data
);
void
*
context
;
void
*
client_responder
;
void
*
gui_responder
;
...
...
Write
Preview
Supports
Markdown
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