Index: shared/scripts/configuration/utility.py =================================================================== diff -u -r4c3783ae2fafb0cd91a66c648f8ccfc78174db86 -ra9219e9ca0692311f23f60aa7c9b574fb449d3e6 --- shared/scripts/configuration/utility.py (.../utility.py) (revision 4c3783ae2fafb0cd91a66c648f8ccfc78174db86) +++ shared/scripts/configuration/utility.py (.../utility.py) (revision a9219e9ca0692311f23f60aa7c9b574fb449d3e6) @@ -11,8 +11,10 @@ # ############################################################################ + import csv import glob +import math import object import os import names @@ -26,18 +28,19 @@ from builtins import format from configuration import config from dialin.ui import utils -from datetime import datetime -from dialin.ui import utils +from dialin.utils import * from dialin.common.msg_ids import MsgIds from dialin.ui.hd_simulator import HDSimulator +from dialin.protocols import DenaliMessage, DenaliCanMessenger, DenaliChannels +from datetime import datetime LOG_LOCATION = "/home/denali/Desktop/sd-card/log/*.log" hd_simulator = HDSimulator() def color_verification(exp_val = "Red", act_val = "#c53b33"): test.compare(config.COLOR_CODES[color_name],(act_val.color[name])) - + def check_if_object_is_within_the_container(obj=None, container=None): """ check if an object is inside a container @@ -1557,4 +1560,78 @@ entry = pyStr(entry) #type casted into string format for value in entry: squish.mouseClick(squish.waitForObject(keypad_input(value))) - test.endSection() \ No newline at end of file + test.endSection() + +def pad_message_with_zeros(message): + """ + Returns a packet padded with zeros that guarantees that the packet is a multiple of 8 bytes. + + @param message: packet that may or may not be multiple of 8 bytes + @return:: packet that is 8-byte multiple + + """ + PACKET_LENGTH = 4 + + message_length = len(message) + + if message_length % PACKET_LENGTH != 0: + add_these_many_zeros = math.ceil(message_length / PACKET_LENGTH) * \ + PACKET_LENGTH - message_length + + message += [0] * add_these_many_zeros + + return message + + +def ui_all_publication_handler(message: dict) -> None: + """ + This function is the default handler of the ui received messages which only prints out the received message + - This function can be used as an example. + - Be careful that there is only one ui publication method + and it will be overwritten on each call to the function set_ui_all_publication of the HDSimulator. + Look into the _init_loader of the Simulator class for example on how to register. + self.interface.hd.set_ui_all_publication(ui_all_publication_handler) + - This function is filtering the two message ID: + MsgIds.MSG_ID_UI_CHECK_IN.value, + MsgIds.MSG_ID_ACK_MESSAGE_THAT_REQUIRES_ACK.value + for the simplicity of the printed message and as example of how to filter. + That filter can obviously be removed. + + @param message: the ui received message + @return: event binary from simulator + """ + exception_msg_id = { + MsgIds.MSG_ID_UI_CHECK_IN.value, + MsgIds.MSG_ID_ACK_MESSAGE_THAT_REQUIRES_ACK.value + } + msg_id = DenaliMessage.get_message_id(message) + if msg_id in exception_msg_id: + return + + message_list = DenaliCanMessenger.convert_message_to_string(message) + event_binary = "" + pad_message_with_zeros(message_list) + + return event_binary + + +def cmd_set_create_treatment_click_event(response): + """ + Sends a set RTC response message + + @param response: (int) 0=NO, 1=YES + @return: N + """ + test.log("HD: Sending response {0}".format(response)) + + payload = integer_to_bytearray(response) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.ui_to_hd_ch_id, + message_id=MsgIds.MSG_ID_UI_INITIATE_TREATMENT_REQUEST.value, + payload=payload) + + return message + +def get_current_date_and_time(date_format='%Y/%b/%d - %H:%M'): + + date = datetime.now() + return str(date.strftime(date_format))