#!/bin/sh /etc/rc.common

START=99
STOP=10

USE_PROCD=1
PROG_PATH="/usr/bin"

start_service() {

    # Start socat services

    procd_open_instance socat_smd11
    procd_set_param command $PROG_PATH/socat -d -d pty,link=/dev/ttyIN,raw,echo=0,group=20,perm=660 pty,link=/dev/ttyOUT,raw,echo=1,group=20,perm=660
    procd_set_param respawn
    procd_close_instance
	sleep 1
	
	procd_open_instance socat_smd7
    procd_set_param command $PROG_PATH/socat -d -d pty,link=/dev/ttyIN2,raw,echo=0,group=20,perm=660 pty,link=/dev/ttyOUT2,raw,echo=1,group=20,perm=660
    procd_set_param respawn
    procd_close_instance
	sleep 1

    # Start forwarding services
	
	procd_open_instance socat_smd11_from_ttyIN
    procd_set_param command /bin/ash -c "/bin/cat /dev/ttyIN > /dev/smd11"
    procd_set_param respawn
    procd_close_instance

    procd_open_instance socat_smd11_to_ttyIN
    procd_set_param command /bin/ash -c "/bin/cat /dev/smd11 > /dev/ttyIN"
    procd_set_param respawn
    procd_close_instance
	
	
    procd_open_instance socat_smd7_from_ttyIN2
    procd_set_param command /bin/ash -c "/bin/cat /dev/ttyIN2 > /dev/smd7"
    procd_set_param respawn
    procd_close_instance

    procd_open_instance socat_smd7_to_ttyIN2
    procd_set_param command /bin/ash -c "/bin/cat /dev/smd7 > /dev/ttyIN2"
    procd_set_param respawn
    procd_close_instance
}

stop_service() {
    killall socat
}
