Exemple #1
0
def set_gps(GPS):
    characters = [0x80, 0x81]  # 0 = GPS off -> 0x30, 1 = GPS on -> 0x31
    cmd = Command.create_with_return_file_data_action(
        0x40, [0x0A, 0x32, characters[GPS], 0X0D], InterfaceType.D7ASP,
        D7Config(addressee=Addressee(access_class=0x11, id_type=IdType.NOID)))

    execute_rpc_command("<gateway ID>", cmd)
    debug("GPS was set to " + str(GPS) + " through RPC")
    push_to_tb({"gps": GPS})
    for i in range(0, 20):
        cmd = Command.create_with_return_file_data_action(
            0x40, [0x0A, 0x32, characters[GPS], 0X0D], InterfaceType.D7ASP,
            D7Config(
                addressee=Addressee(access_class=0x11, id_type=IdType.NOID)))
        time.sleep(0.5)
Exemple #2
0
    def start_transmitting(self, interface_configuration, payload):
        print(
            "Running throughput test with payload size {} and interface_configuration {}\n\nrunning ...\n"
            .format(len(payload), interface_configuration))

        if self.receiver_modem != None:
            self.received_commands = defaultdict(list)
            self.receiver_modem.start_reading()

        command = Command.create_with_return_file_data_action(
            file_id=0x40,
            data=payload,
            interface_type=InterfaceType.D7ASP,
            interface_configuration=interface_configuration)

        start = time.time()

        for i in range(self.config.msg_count):
            sys.stdout.write("{}/{}\r".format(i + 1, self.config.msg_count))
            sys.stdout.flush()
            self.transmitter_modem.d7asp_fifo_flush(command)

        end = time.time()
        print("transmitter: sending {} messages completed in: {} s".format(
            self.config.msg_count, end - start))
        print(
            "transmitter: throughput = {} bps with a payload size of {} bytes".
            format((self.config.msg_count * self.config.payload_size * 8) /
                   (end - start), self.config.payload_size))
Exemple #3
0
    def run(self):
        # cmd = Command.create_with_return_file_data_action(file_id, data, interface_type=InterfaceType.HOST,interface_configuration=None)
        cmd = Command.create_with_return_file_data_action(
            file_id=40,
            data=[0x31, 0x41, 0x45],
            interface_type=InterfaceType.D7ASP,
            interface_configuration=D7config(
                qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
                addressee=Addressee(access_class=0x11, id_type=IdType.NOID)))
        # cmd = {0x32, 0xd7, 0x01, 0x00, 0x10, 0x01, 0x20, 0x01, 0x00}
        # cmd = {0x011}
        self.execute_rpc_command(self.config.device, cmd)
        print("Send 1")

        self.update_progress(0)
        sleep(1)
        self.update_progress(20)
        sleep(1)
        self.update_progress(40)
        sleep(1)
        self.update_progress(60)
        sleep(1)
        self.update_progress(80)
        sleep(1)
        self.update_progress(100)

        self.execute_rpc_command(self.config.device, cmd)
        print()
        print("Send 2")
  def start_transmitting(self, interface_configuration, payload):
    print("Running throughput test with payload size {} and interface_configuration {}\n\nrunning ...\n".format(len(payload), interface_configuration))

    if self.receiver_modem != None:
      self.received_commands = defaultdict(list)
      self.receiver_modem.start_reading()

    command = Command.create_with_return_file_data_action(
      file_id=0x40,
      data=payload,
      interface_type=InterfaceType.D7ASP,
      interface_configuration=interface_configuration
    )

    start = time.time()

    for i in range(self.config.msg_count):
      sys.stdout.write("{}/{}\r".format(i + 1, self.config.msg_count))
      sys.stdout.flush()
      self.transmitter_modem.d7asp_fifo_flush(command)

    end = time.time()
    print("transmitter: sending {} messages completed in: {} s".format(self.config.msg_count, end - start))
    print("transmitter: throughput = {} bps with a payload size of {} bytes".format(
      (self.config.msg_count * self.config.payload_size * 8) / (end - start), self.config.payload_size)
    )
Exemple #5
0
def execute_rpc_command(device_id, data):
    json_alp_cmd = Command.create_with_return_file_data_action(
        file_id=40,
        data=data,
        interface_type=InterfaceType.D7ASP,
        interface_configuration=D7config(
            qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
            addressee=Addressee(access_class=0x11, id_type=IdType.NOID)))
    # we will do it by a manual POST to /api/plugins/rpc/oneway/ , which is the route specified
    # in the documentation
    cmd = {
        "method": "execute-alp-async",
        "params": jsonpickle.encode(json_alp_cmd),
        "timeout": 500
    }
    path_params = {'deviceId': device_id}
    query_params = {}
    header_params = {}
    header_params['Accept'] = api_client.select_header_accept(['*/*'])
    header_params['Content-Type'] = api_client.select_header_content_type(
        ['application/json'])

    # Authentication setting
    auth_settings = ['X-Authorization']
    return api_client.call_api('/api/plugins/rpc/oneway/{deviceId}',
                               'POST',
                               path_params,
                               query_params,
                               header_params,
                               body=cmd,
                               post_params=[],
                               files={},
                               response_type='DeferredResultResponseEntity',
                               auth_settings=auth_settings,
                               async=False)
Exemple #6
0
 def send(self):
     cmd = Command.create_with_return_file_data_action(
         file_id=0x40,
         data=map(ord, list(self.command)),
         interface_type=InterfaceType.D7ASP,
         interface_configuration=Configuration(
             qos=QoS(resp_mod=QoS.RESP_MODE_NO),
             addressee=Addressee(access_class=0, id_type=IdType.BCAST)))
     self.modem.d7asp_fifo_flush(alp_command=cmd)
     self.add("me: " + self.command, curses.A_REVERSE)
Exemple #7
0
 def test_create_with_return_file_data_action(self):
   data = [ 1 ]
   c = Command.create_with_return_file_data_action(file_id=0x40, data=data)
   self.assertEqual(len(c.actions), 1)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), ReturnFileData)
   self.assertEqual(type(c.actions[0].operand), Data)
   self.assertEqual(c.actions[0].operand.offset.id, 0x40)
   self.assertEqual(c.actions[0].operand.offset.offset.value, 0)
   self.assertEqual(c.actions[0].operand.length.value, 1)
   self.assertEqual(c.actions[0].operand.data, data)
 def test_create_with_return_file_data_action(self):
   data = [ 1 ]
   c = Command.create_with_return_file_data_action(file_id=0x40, data=data)
   self.assertEqual(len(c.actions), 1)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), ReturnFileData)
   self.assertEqual(type(c.actions[0].operand), Data)
   self.assertEqual(c.actions[0].operand.offset.id, 0x40)
   self.assertEqual(c.actions[0].operand.offset.size, 1)
   self.assertEqual(c.actions[0].operand.offset.offset, 0)
   self.assertEqual(c.actions[0].operand.length, 1)
   self.assertEqual(c.actions[0].operand.data, data)
Exemple #9
0
 def send(self):
   cmd = Command.create_with_return_file_data_action(
     file_id=0x40,
     data=map(ord, list(self.command)),
     interface_type=InterfaceType.D7ASP,
     interface_configuration=Configuration(
       qos=QoS(resp_mod=QoS.RESP_MODE_NO),
       addressee=Addressee(
         access_class=0,
         id_type=IdType.BCAST
       )
     )
   )
   self.modem.d7asp_fifo_flush(alp_command=cmd)
   self.add("me: " + self.command, curses.A_REVERSE)
Exemple #10
0
 def test_create_with_return_file_data_action_d7asp(self):
   data = [1]
   c = Command.create_with_return_file_data_action(file_id=0x40, data=data, interface_type=InterfaceType.D7ASP)
   self.assertEqual(len(c.actions), 2)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), Forward)
   self.assertEqual(type(c.actions[0].operand), InterfaceConfiguration)
   self.assertEqual(c.actions[0].operand.interface_id.value, 0xD7)
   self.assertEqual(type(c.actions[0].operand.interface_configuration), Configuration)
   self.assertEqual(type(c.actions[1]), RegularAction)
   self.assertEqual(type(c.actions[1].operation), ReturnFileData)
   self.assertEqual(type(c.actions[1].operand), Data)
   self.assertEqual(c.actions[1].operand.offset.id, 0x40)
   self.assertEqual(c.actions[1].operand.offset.offset.value, 0)
   self.assertEqual(c.actions[1].operand.length.value, 1)
   self.assertEqual(c.actions[1].operand.data, data)
Exemple #11
0
 def test_create_with_return_file_data_action_d7asp(self):
   data = [1]
   c = Command.create_with_return_file_data_action(file_id=0x40, data=data, interface_type=InterfaceType.D7ASP)
   self.assertEqual(len(c.actions), 2)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), Forward)
   self.assertEqual(type(c.actions[0].operand), InterfaceConfiguration)
   self.assertEqual(c.actions[0].operand.interface_id, 0xD7)
   self.assertEqual(type(c.actions[0].operand.interface_configuration), Configuration)
   self.assertEqual(type(c.actions[1]), RegularAction)
   self.assertEqual(type(c.actions[1].operation), ReturnFileData)
   self.assertEqual(type(c.actions[1].operand), Data)
   self.assertEqual(c.actions[1].operand.offset.id, 0x40)
   self.assertEqual(c.actions[1].operand.offset.size, 1)
   self.assertEqual(c.actions[1].operand.offset.offset, 0)
   self.assertEqual(c.actions[1].operand.length, 1)
   self.assertEqual(c.actions[1].operand.data, data)
Exemple #12
0
    def run(self):
        # cmd = Command.create_with_return_file_data_action(file_id, data, interface_type=InterfaceType.HOST,interface_configuration=None)
        cmd = Command.create_with_return_file_data_action(file_id=40, data=[0x03],
                                                          interface_type=InterfaceType.D7ASP,
                                                          interface_configuration=D7config(
                                                              qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
                                                              addressee=Addressee(access_class=0x11,
                                                                                  id_type=IdType.NOID)))
        #cmd = {0x32, 0xd7, 0x01, 0x00, 0x10, 0x01, 0x20, 0x01, 0x00}
        # cmd = {0x011}

        for x in range(5):
            print("Alert {} to node".format(x))
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway1,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway1))
            sleep(0.5)
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway2,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway2))
            sleep(0.5)
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway3,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway3))
            sleep(0.5)
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway4,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway4))
            sleep(1)
                       help="serial device /dev file",
                       default="/dev/tty.usbserial-FTGCT0HY")
argparser.add_argument("-b",
                       "--baudrate",
                       help="baudrate for serial device",
                       type=int,
                       default=115200)

config = argparser.parse_args()

modem = Modem(config.serial, config.baudrate, show_logging=False)

cmd = Command.create_with_return_file_data_action(
    file_id=0x40,
    data=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    interface_type=InterfaceType.D7ASP,
    interface_configuration=Configuration(qos=QoS(resp_mod=QoS.RESP_MODE_NO),
                                          addressee=Addressee(
                                              access_class=0,
                                              id_type=IdType.BCAST)))

last_message = 0

sent = 0
received = 0


def stats():
    print "sent", sent, "received", received


while True:
Exemple #14
0
import argparse

from d7a.alp.command import Command
from d7a.alp.interface import InterfaceType
from d7a.d7anp.addressee import Addressee, IdType
from d7a.sp.configuration import Configuration
from d7a.sp.qos import QoS, ResponseMode
from d7a.system_files.uid import UidFile
from modem.modem import Modem

alp_command = Command.create_with_return_file_data_action(
    file_id=1,
    data=[0x00, 0x01],
    interface_type=InterfaceType.D7ASP,
    interface_configuration=Configuration(
        qos=QoS(resp_mod=ResponseMode.RESP_MODE_ALL),
        addressee=Addressee(access_class=0x01, id_type=IdType.NOID)))

print alp_command

print list(bytearray(alp_command))
Exemple #15
0
argparser.add_argument("-s", "--serial", help="serial device /dev file", 
                       default="/dev/tty.usbserial-FTGCT0HY")
argparser.add_argument("-b", "--baudrate", help="baudrate for serial device", 
                       type=int, default=115200)

config = argparser.parse_args()

modem = Modem(config.serial, config.baudrate, show_logging=False)

cmd = Command.create_with_return_file_data_action(
    file_id=0x40,
    data=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    interface_type=InterfaceType.D7ASP,
    interface_configuration=Configuration(
      qos=QoS(resp_mod=QoS.RESP_MODE_NO),
      addressee=Addressee(
        access_class=0,
        id_type=IdType.BCAST
      )
    )
  )

last_message = 0

sent = 0
received = 0

def stats():
	print "sent", sent, "received", received

while True: