bugfixes in the script and database and a work in progress sim for nicos development
This commit is contained in:
13
sim/.__afs7E221F9A5
Executable file
13
sim/.__afs7E221F9A5
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/local/bin/iocsh
|
||||
|
||||
on error break
|
||||
|
||||
require sinqSPS, wall_e
|
||||
|
||||
epicsEnvSet("STREAM_PROTOCOL_PATH","./db")
|
||||
epicsEnvSet("PREFIX","SQ:TEST")
|
||||
|
||||
epicsEnvSet("SET_SIM_MODE","") # Run Shutter Simulation Instead of Connecting with SPS
|
||||
runScript "$(sinqSPS_DIR)shutter.cmd" "SPS_IP=127.0.0.1, FETCH_DB=210, FETCH_PORT=2002, WRITE_PORT=2003"
|
||||
|
||||
iocInit()
|
9
sim/ioc.sh
Executable file
9
sim/ioc.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
export EPICS_HOST_ARCH=linux-x86_64
|
||||
export EPICS_BASE=/usr/local/epics/base-7.0.7
|
||||
|
||||
PARENT_PATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
|
||||
|
||||
echo "${PARENT_PATH}/st.cmd"
|
||||
/usr/local/bin/procServ -L - -f -i ^D^C 20001 "${PARENT_PATH}/st.cmd"
|
92
sim/shutter_sim.py
Normal file
92
sim/shutter_sim.py
Normal file
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
from threading import Thread
|
||||
|
||||
HOST = "127.0.0.1" # Localhost
|
||||
READ_PORT = int(sys.argv[1]) # Port to listen on
|
||||
WRITE_PORT = int(sys.argv[2]) # Port to listen on
|
||||
|
||||
LOG2FILE = True # TODO False if len(sys.argv) < 3 else bool(int(sys.argv[3]))
|
||||
|
||||
logger = logging.getLogger('shutter')
|
||||
|
||||
if LOG2FILE:
|
||||
logging.basicConfig(filename=os.path.join(os.getcwd(), 'shutter_sim.log'), level=logging.INFO)
|
||||
|
||||
logger.info(f'Read Requests on {HOST}:{READ_PORT}, Write Requests on {HOST}:{WRITE_PORT}')
|
||||
|
||||
def receive(conn, sock_name):
|
||||
# received = conn.recv(1024, socket.MSG_DONTWAIT)
|
||||
received = conn.recv(1024)
|
||||
logger.info(f'RECEIVED on {sock_name}: "{received}"')
|
||||
logger.info('Decimal on %s: %s' % (sock_name, ' '.join(map(str, [received[i+2] for i in range(len(received)-2)]))))
|
||||
return received
|
||||
|
||||
def send(conn, data: str):
|
||||
logger.info(f'SENDING: "{data}"')
|
||||
return conn.sendall(data)
|
||||
|
||||
def read_requests():
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
|
||||
s.bind((HOST, READ_PORT))
|
||||
s.listen()
|
||||
conn, _ = s.accept()
|
||||
|
||||
with conn:
|
||||
while True:
|
||||
data = receive(conn, "read")
|
||||
|
||||
# if not data: # Empty implies client disconnected
|
||||
# break # Close Server
|
||||
|
||||
try:
|
||||
|
||||
if data == b'':
|
||||
send(conn, b'')
|
||||
|
||||
elif len(data) == 14 and data[0] == 83 and data[1] == 53:
|
||||
# Trying to fetch data
|
||||
org = data[8]
|
||||
db = data[9]
|
||||
s7addr = data[10] * 256 + data[11]
|
||||
s7len = data[12] * 256 + data[13]
|
||||
logger.info(f'Fetch: db: {db}, address: {s7addr}, total: {s7len}')
|
||||
|
||||
send(conn, b'0' * s7len)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception('Simulation Broke')
|
||||
# send('?OV')
|
||||
|
||||
def write_requests():
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
|
||||
s.bind((HOST, WRITE_PORT))
|
||||
s.listen()
|
||||
conn, _ = s.accept()
|
||||
|
||||
with conn:
|
||||
while True:
|
||||
data = receive(conn, "write")
|
||||
|
||||
# if not data: # Empty implies client disconnected
|
||||
# break # Close Server
|
||||
|
||||
|
||||
read_thread = Thread(target=read_requests)
|
||||
write_thread = Thread(target=write_requests)
|
||||
|
||||
read_thread.run()
|
||||
write_thread.run()
|
||||
|
||||
while True:
|
||||
pass
|
13
sim/st.cmd
Executable file
13
sim/st.cmd
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/local/bin/iocsh
|
||||
|
||||
on error break
|
||||
|
||||
require sinqSPS, wall_e
|
||||
|
||||
epicsEnvSet("STREAM_PROTOCOL_PATH","./db")
|
||||
epicsEnvSet("PREFIX","SQ:TEST")
|
||||
|
||||
epicsEnvSet("SET_SIM_MODE","") # Run Shutter Simulation Instead of Connecting with SPS
|
||||
runScript "$(sinqSPS_DIR)shutter.cmd" "SPS_IP=127.0.0.1, FETCH_DB=210, FETCH_PORT=2030, WRITE_PORT=2031"
|
||||
|
||||
iocInit()
|
Reference in New Issue
Block a user