Exemple #1
0
def main():

    # In this example, we are Alice.
    myName = "Alice"

    # Initialize the connection
    cqc = init(myName)

    # Send Hello message
    print("App {} tells CQC: 'HELLO'".format(myName))
    hdr = CQCHeader()
    hdr.setVals(CQC_VERSION, CQC_TP_HELLO, 0, 0)
    msg = hdr.pack()
    cqc.send(msg)

    # Receive return message
    data = cqc.recv(192)
    hdr = CQCHeader(data)
    if hdr.tp == CQC_TP_HELLO:
        print("CQC tells App {}: 'HELLO'".format(myName))
    else:
        print("Did not receive a hello message, but rather: {}".format(
            hdr.printable()))

        # Close the connection
    cqc.close()
Exemple #2
0
 def construct_simple(self, tp):
     """Construct simple message.
     
     For example a HELLO message if tp=CQC_TP_HELLO.
     """
     hdr = CQCHeader()
     hdr.setVals(CQC_VERSION, tp, self._appID, 0)
     msg = hdr.pack()
     return msg
Exemple #3
0
 def create_return_message(app_id, msg_type, length=0, cqc_version=CQC_VERSION):
     """
     Creates a messaage that the protocol should send back
     :param app_id: the app_id to which the message should be send
     :param msg_type: the type of message to return
     :param length: the length of additional message
     :param cqc_version: The cqc version of the message
     :return: a new header message to be send back
     """
     hdr = CQCHeader()
     hdr.setVals(cqc_version, msg_type, app_id, length)
     return hdr.pack()
Exemple #4
0
    def _send_back_cqc(self, header, msgType, length=0):
        """
        Return a simple CQC header with the specified type.

        header	 CQC header of the packet we respond to
        msgType  Message type to return
        length	 Length of additional message
        """
        hdr = CQCHeader()
        hdr.setVals(CQC_VERSION, msgType, header.app_id, length)

        msg = hdr.pack()
        self.transport.write(msg)
Exemple #5
0
    def sendGetTime(self, qID, notify=1, block=1, action=0):
        """Sends get-time message

        - **Arguments**

            :qID:         qubit ID
            :command:     Command to be executed, eg CQC_CMD_H
            :notify:     Do we wish to be notified when done.
            :block:         Do we want the qubit to be blocked
            :action:     Are there more commands to be executed
        """
        # Send Header
        hdr = CQCHeader()
        hdr.setVals(CQC_VERSION, CQC_TP_GET_TIME, self._appID,
                    CQCCmdHeader.HDR_LENGTH)
        msg = hdr.pack()
        self.commit(msg)

        # Send Command
        cmd_hdr = CQCCmdHeader()
        cmd_hdr.setVals(qID, 0, notify, block, action)
        cmd_msg = cmd_hdr.pack()
        self.commit(cmd_msg)