-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket_sig.py
executable file
·53 lines (42 loc) · 1.52 KB
/
socket_sig.py
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
# encoding: utf-8
"""
socket_sig.py
Created by Sam Cook on 2011-01-18.
Copyright (c) 2011 __MyCompanyName__. All rights reserved.
"""
import sys
import os
import ecp_header
import naf
from socket import *
from struct import pack, unpack
if __name__ == '__main__':
# for send/receive
host = "192.168.0.2"
port = 240
buf = 1024
addr = (host,port)
# socket for sending to CAMAC
sendSock = socket(AF_INET, SOCK_DGRAM)
sendSock.settimeout(10)
# message to send
msg = ecp_header.gettop() + naf.naf(8, 'testStatus')#, a = 0, data =2)
print(msg)
sendSock.sendto(msg, addr)
data = ''
while (not data):
data, addr2 = sendSock.recvfrom(buf)
print(data)
print(data)
print(unpack("B"*24,data))
# sample outputs naf = 16, 0, clearLAM,
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 58, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 71, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 78, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 93, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# naf = 24, testLAM, 0
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 122, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 144, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# naf = 16, readGrp1, 0
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 166, 184, 0, 0, 0, 1, 0, 3, 10, 0)
# (96, 96, 247, 0, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 180, 184, 0, 0, 0, 1, 0, 3, 10, 0)