Commit e0265563 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add missing files

parent dbfce1dd
#!/usr/bin/python
# -*- coding: utf-8 -*-
''' Edit this module at will to create custom widgets that can send TC or
receive TM - and do anything you like with the data.
(c) 2016-2019 European Space Agency
'''
__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__url__ = "https://taste.tools"
import sys
import os
import importlib
import DV
try:
from PySide.QtCore import (QObject, Signal, Slot, Qt, QTimer)
import PySide.QtGui as QtGui
except ImportError:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from asn1_value_editor import UserWidgetsCommon
# ** IMPORTANT **
# you must list here the classes you want to expose to the GUI:
__all__ = ['PedestrianButton', 'TrafficLight', 'Pedestrian']
class PedestrianButton(UserWidgetsCommon.TC):
''' Fill / mimick this class to create a custom TC widget '''
name = 'Nice Button' # name on the GUI combo button
instantiated = False
def __init__(self, asn1_typename, parent):
''' Initialise the widget '''
super(PedestrianButton, self).__init__(asn1_typename, parent)
if PedestrianButton.instantiated:
self.close()
return
self._asn1_typename = asn1_typename
self.widget = QtGui.QPushButton("Request passage")
self.widget.clicked.connect(self.clicked)
self.setWidget(self.widget)
# parent is the ASN.1 value editor
self.parent = parent
self.setWindowTitle(parent.messageName)
self.show()
PedestrianButton.instantiated = True
@staticmethod
def applicable():
''' Return True to activate this widget '''
return True
@staticmethod
def editorIsApplicable(editor):
''' Return true if this particular editor is compatible with this
widget'''
return editor.messageName == "Button"
def clicked(self):
''' Called when user clicks on the button '''
self.parent.sendTC()
class TrafficLight(UserWidgetsCommon.TM):
'''Save telemetries in the database'''
name = 'View Traffic Light' # name for the combo button in the GUI
def __init__(self, parent=None):
''' Initialise the widget '''
super(TrafficLight, self).__init__(parent)
self.widget = QtGui.QLabel()
self.colorMap = { DV.red: QtGui.QPixmap ("red.png"),
DV.orange: QtGui.QPixmap ("orange.png"),
DV.green: QtGui.QPixmap ("green.png") }
self.widget.setPixmap (self.colorMap[DV.red])
self.setWidget(self.widget)
self.setWindowTitle(parent.treeItem.text())
self.show()
@Slot()
def new_tm(self):
''' Slot called when a TM has been received in the editor '''
# Nothing to do, the update() function does nothing thread-related
# that would need to be done here
pass
def update(self, value):
''' Receive ASN.1 value '''
color = value.Get()
self.widget.setPixmap (self.colorMap[color])
@staticmethod
def applicable():
''' Return True to enable this widget '''
return True
@staticmethod
def editorIsApplicable(editor):
''' Return true if this particular editor is compatible with this
widget'''
return editor.messageName == "Color"
class Pedestrian(UserWidgetsCommon.TM):
'''Save telemetries in the database'''
name = 'View Traffic Light' # name for the combo button in the GUI
def __init__(self, parent=None):
''' Initialise the widget '''
super(Pedestrian, self).__init__(parent)
self.widget = QtGui.QLabel()
self.colorMap = { DV.wait: QtGui.QPixmap ("wait.png"),
DV.go: QtGui.QPixmap ("go.png")}
self.widget.setPixmap (self.colorMap[DV.wait])
self.setWidget(self.widget)
self.setWindowTitle(parent.treeItem.text())
self.show()
@Slot()
def new_tm(self):
''' Slot called when a TM has been received in the editor '''
# Nothing to do, the update() function does nothing thread-related
# that would need to be done here
pass
def update(self, value):
''' Receive ASN.1 value '''
status = value.Get()
self.widget.setPixmap (self.colorMap[status])
@staticmethod
def applicable():
''' Return True to enable this widget '''
return True
@staticmethod
def editorIsApplicable(editor):
''' Return true if this particular editor is compatible with this
widget'''
return editor.messageName == "Info_User"
if __name__ == '__main__':
print('This module can only be imported from the main TASTE guis')
sys.exit(-1)
/* CIF PROCESS (250, 150), (150, 75) */
process Controller;
state Green;
substructure
in (short);
out (Go_Orange);
/* CIF START (604, 136), (70, 35) */
START short ;
/* CIF NEXTSTATE (583, 191), (110, 35) */
NEXTSTATE Second_Delay;
/* CIF START (343, 131), (70, 35) */
START;
/* CIF NEXTSTATE (331, 186), (93, 35) */
NEXTSTATE First_Delay;
/* CIF state (583, 191), (110, 35) */
state Second_Delay;
/* CIF input (604, 246), (70, 35) */
input Clock;
/* CIF return (621, 301), (35, 35) */
return Go_Orange;
endstate;
/* CIF state (331, 186), (93, 35) */
state First_Delay;
/* CIF input (206, 241), (70, 35) */
input Clock;
/* CIF PROCEDURECALL (155, 296), (171, 35) */
call Set_Timer (5000, Clock);
/* CIF NEXTSTATE (185, 351), (111, 35) */
NEXTSTATE Second_Delay;
/* CIF input (361, 241), (123, 35) */
input Button (cmd);
/* CIF PROCEDURECALL (336, 296), (171, 35) */
call Set_Timer (5000, Clock);
/* CIF NEXTSTATE (364, 346), (117, 35) */
NEXTSTATE Second_Delay;
endstate;
endsubstructure;
state Red;
substructure
out (Go_Green);
/* CIF START (59, 69), (59, 35) */
START;
/* CIF NEXTSTATE (15, 119), (147, 35) */
NEXTSTATE Everybody_Stopped;
/* CIF state (237, 112), (73, 35) */
state Walking;
/* CIF input (238, 167), (70, 35) */
input Clock;
/* CIF output (211, 222), (124, 35) */
output Info_User (Wait);
/* CIF PROCEDURECALL (234, 277), (79, 35) */
call Blue_Off;
/* CIF PROCEDURECALL (184, 327), (178, 35) */
call Set_Timer (2000, Clock);
/* CIF NEXTSTATE (210, 382), (127, 35) */
NEXTSTATE Walking_Is_Over;
endstate;
/* CIF state (430, 116), (127, 35) */
state Walking_Is_Over;
/* CIF input (373, 171), (70, 35) */
input Clock;
/* CIF return (391, 226), (35, 35) */
return Go_Green;
/* CIF input (477, 171), (123, 35) */
input Button (cmd);
/* CIF task (453, 226), (172, 35) */
task Walk_Requested := True;
/* CIF NEXTSTATE (504, 281), (70, 35) */
NEXTSTATE -;
endstate;
/* CIF state (15, 119), (147, 35) */
state Everybody_Stopped;
/* CIF input (53, 174), (70, 35) */
input Clock;
/* CIF output (32, 229), (112, 35) */
output Info_User (Go);
/* CIF PROCEDURECALL (50, 284), (75, 35) */
call Blue_On;
/* CIF PROCEDURECALL (3, 334), (171, 35) */
call Set_Timer (5000, Clock);
/* CIF task (0, 389), (177, 35) */
task Walk_Requested := False;
/* CIF NEXTSTATE (52, 439), (73, 35) */
NEXTSTATE Walking;
endstate;
endsubstructure;
/* CIF TEXT (939, 61), (282, 152) */
timer clock;
dcl dummy t_Boolean;
dcl Walk_Requested T_Boolean := False;
dcl Cmd Command;
dcl blue_led t_boolean := true;
/* CIF ENDTEXT */
/* CIF START (155, 40), (70, 33) */
START;
/* CIF NEXTSTATE (152, 93), (75, 35) */
NEXTSTATE Off;
/* CIF state (152, 93), (75, 35) */
state Off;
/* CIF input (117, 148), (134, 35) */
input Initialize (dummy);
/* CIF PROCEDURECALL (142, 203), (85, 35) */
call Kick_WD;
/* CIF PROCEDURECALL (96, 253), (178, 35) */
call Set_Timer (1000, Clock);
/* CIF output (138, 308), (92, 35) */
output Color (Red);
/* CIF PROCEDURECALL (149, 363), (71, 35) */
call Red_On;
/* CIF PROCEDURECALL (145, 418), (79, 35) */
call Blue_Off;
/* CIF output (122, 468), (124, 35) */
output Info_User (Wait);
/* CIF NEXTSTATE (154, 518), (61, 35) */
NEXTSTATE Red;
endstate;
/* CIF state (548, 49), (70, 35) */
state Red;
/* CIF connect (583, 104), (0, 35) */
connect Go_Green;
/* CIF PROCEDURECALL (494, 159), (178, 35) */
call Set_Timer (5000, Clock);
/* CIF output (529, 214), (106, 35) */
output Color (Green);
/* CIF PROCEDURECALL (540, 269), (85, 35) */
call Green_On;
/* CIF decision (520, 319), (124, 50) */
decision Walk_requested;
/* CIF ANSWER (469, 389), (70, 24) */
(True):
/* CIF NEXTSTATE (444, 433), (119, 35) */
NEXTSTATE Green via Short;
/* CIF ANSWER (638, 389), (68, 24) */
(False):
/* CIF NEXTSTATE (635, 433), (74, 35) */
NEXTSTATE Green;
enddecision;
endstate;
/* CIF state (773, 61), (70, 35) */
state Orange;
/* CIF input (773, 116), (70, 35) */
input Clock;
/* CIF PROCEDURECALL (719, 171), (178, 35) */
call Set_Timer (1000, Clock);
/* CIF output (761, 226), (92, 35) */
output Color (Red);
/* CIF PROCEDURECALL (772, 281), (71, 35) */
call Red_On;
/* CIF NEXTSTATE (773, 331), (70, 35) */
NEXTSTATE Red;
endstate;
/* CIF state (973, 314), (70, 35) */
state Green;
/* CIF connect (1008, 369), (0, 35) */
connect Go_Orange;
/* CIF PROCEDURECALL (907, 419), (201, 35) */
call Set_Timer (2000, Clock);
/* CIF output (950, 474), (114, 35) */
output Color (Orange);
/* CIF PROCEDURECALL (961, 529), (93, 35) */
call Orange_On;
/* CIF NEXTSTATE (973, 579), (70, 35) */
NEXTSTATE Orange;
endstate;
endprocess Controller;
\ No newline at end of file
-- User implementation of the STM32_Debug function
-- This file will never be overwritten once edited and modified
-- Only the interface of functions is regenerated (in the .ads file)
-- Notes : in RM0090 section 10-3-3 we can find the mapping table for the DMA
-- it says for example that DMA1 can be connected to the transmitter of USART2
-- (USART2_Tx) using Channel 4 / Stream 6. This is the only right config
-- Main mappings:
-- DMA1 : USART2_Tx / Channel 4 / Stream 6
-- DMA1 : USART2_Rx / Channel 5 / Stream 5
-- DMA2 : USART6_Tx / Channel 5 / Stream 6 or Stream 7
-- DMA2 : USART6_Rx / Chennel 5 / Stream 1 or Stream 2
--
-- Then the alternate functions map also to specific USARTs:
-- AF7 maps to USART 1..3
-- AF8 maps to USART 4..6
--
-- And in the Datasheet of STM32F405/7 we have the GPIO / AF mapping:
-- PC6 = USART6_Tx
-- PC7 = USART6_Rx
-- PA2 = USART2_Tx (AF7)
-- PA3 = USART2_Rx (AF7)
pragma Style_Checks (off);
with STM32.Board; use STM32.Board;
with STM32.GPIO; use STM32.GPIO;
with STM32.DMA; use STM32.DMA;
with STM32.Device; use STM32.Device;
with HAL; use HAL;
with STM32.USARTs; use STM32.USARTs;
with Ada.Interrupts; use Ada.Interrupts;
with Ada.Interrupts.Names; use Ada.Interrupts.Names;
-- with Types; use Types;
with System;
with Interfaces; use Interfaces;
package body STM32_Debug is
-- PA2/PA3 are the GPIOs corresponding to the ftdi of the discovery shield
-- they are used for taste GUI communication
-- use PC6/PC7 for the debug printf
-- Transceiver : USART renames USART_2;
-- Transceiver_AF : constant STM32.GPIO_Alternate_Function := GPIO_AF_USART2_7;
-- TX_Pin : constant GPIO_Point := PA2;
-- RX_Pin : constant GPIO_Point := PA3;
-- Controller : DMA_Controller renames DMA_1;
-- Tx_Channel : constant DMA_Channel_Selector := Channel_4;
-- Tx_Stream : constant DMA_Stream_Selector := Stream_6;
-- Rx_Channel : constant DMA_Channel_Selector := Channel_5;
-- Rx_Stream : constant DMA_Stream_Selector := Stream_5;
-- USART_IRQ : constant Interrupt_ID := USART2_Interrupt;
TX_Pin : constant GPIO_Point := PC6;
RX_Pin : constant GPIO_Point := PC7;
Controller : DMA_Controller renames DMA_2;
Tx_Channel : constant DMA_Channel_Selector := Channel_5;
Tx_Stream : constant DMA_Stream_Selector := Stream_7;
Rx_Channel : constant DMA_Channel_Selector := Channel_5;
Rx_Stream : constant DMA_Stream_Selector := Stream_1;
USART_IRQ : constant Interrupt_ID := USART6_Interrupt;
Transceiver : USART renames USART_6;
Transceiver_AF : constant STM32.GPIO_Alternate_Function := GPIO_AF_USART6_8;
-- One-message buffer for reception
Incoming_Msg : aliased asn1sccDebug_PrintableString :=
asn1sccDebug_PrintableString_Init;
Msg_Idx : Natural := 0;
Msg_Complete : Boolean := False;
procedure Initialize_Hardware;
procedure String_To_OctetString (str : String ;
res : in out asn1sccDebug_PrintableString);
procedure String_To_OctetString (str : String ;
res : in out asn1sccDebug_PrintableString)
is
idx : Natural := 1;
begin
res.Length := str'Length;
for char of str loop
exit when idx > res.Data'Length;
res.Data (idx) := Character'Pos (char);
idx := idx + 1;
end loop;
end String_To_OctetString;
protected Reception is
-- Interrupt business must be done in a protected object
pragma Interrupt_Priority;
procedure Handle_Reception with Inline;
procedure IRQ_Handler with Attach_Handler => USART_IRQ;
end Reception;
protected body Reception is
procedure Handle_Reception is
-- Receive one char.
Received_Char : constant Character :=
Character'Val (Current_Input (Transceiver));
-- Buf : aliased asn1sccDebug_PrintableString;
begin
if Received_Char /= ASCII.CR and Msg_Idx < Incoming_Msg.Data'Length
then
if Msg_Idx = 0 then
Incoming_Msg := asn1sccDebug_PrintableString_Init;
Msg_Complete := False;
end if;
-- Append character to buffer
Msg_Idx := Msg_Idx + 1;
Incoming_Msg.Data (Msg_Idx) := Character'Pos (Received_Char);
Incoming_Msg.Length := Incoming_Msg.Length + 1;
else
-- Reception complete
Msg_Idx := 0;
loop
exit when not Status (Transceiver, Read_Data_Register_Not_Empty);
end loop;
-- If we disable interrupts here, it allows to receive data only
-- when we want... at the risk of missing data.
-- Disable_Interrupts (Transceiver, Source => Received_Data_Not_Empty);
-- String_To_OctetString(str => "Received: " & Received_Char & ASCII.CR & ASCII.LF,
-- res => Buf);
-- String_To_OctetString(str => "Received: ", res => Buf);
-- Send_to_UART (Buf'Access);
-- Send_to_UART (Incoming_Msg'Access);
-- Incoming_Msg.Length := 0;
Msg_Complete := True;
end if;
end;
procedure IRQ_Handler is
begin
-- check for data arrival
if Status (Transceiver, Read_Data_Register_Not_Empty) and
Interrupt_Enabled (Transceiver, Received_Data_Not_Empty)
then
Handle_Reception;
Clear_Status (Transceiver, Read_Data_Register_Not_Empty);
end if;
end IRQ_Handler;
end Reception;
-------------------------------
-- Initialize_Hardware --
-------------------------------
procedure Initialize_Hardware is
Config_GPIO : constant GPIO_Port_Configuration :=
(Mode => Mode_AF,
AF => Transceiver_AF,
AF_Speed => Speed_50MHz,
AF_Output_Type => Push_Pull,
Resistors => Pull_Up);
Config_DMA : DMA_Stream_Configuration;
begin
------------------------
-- GPIO Configuration --
------------------------
Enable_Clock (RX_Pin & TX_Pin);
Configure_IO (RX_Pin & TX_Pin,
Config => Config_GPIO);
-------------------------
-- USART Configuration --
-------------------------
Enable_Clock (Transceiver);
Enable (Transceiver);
Set_Baud_Rate (Transceiver, 115_200);
Set_Mode (Transceiver, Tx_Rx_Mode);
Set_Stop_Bits (Transceiver, Stopbits_1);
Set_Word_Length (Transceiver, Word_Length_8);
Set_Parity (Transceiver, No_Parity);
Set_Flow_Control (Transceiver, No_Flow_Control);
--------------------
-- Initialize_DMA --
--------------------
Enable_Clock (Controller);
Reset (Controller, Tx_Stream);
Config_DMA.Channel := Tx_Channel;
Config_DMA.Direction := Memory_To_Peripheral;
Config_DMA.Increment_Peripheral_Address := False;
Config_DMA.Increment_Memory_Address := True;
Config_DMA.Peripheral_Data_Format := Bytes;
Config_DMA.Memory_Data_Format := Bytes;
Config_DMA.Operation_Mode := Normal_Mode;
Config_DMA.Priority := Priority_Very_High;
Config_DMA.FIFO_Enabled := True;
Config_DMA.FIFO_Threshold := FIFO_Threshold_Full_Configuration;
Config_DMA.Memory_Burst_Size := Memory_Burst_Single;
Config_DMA.Peripheral_Burst_Size := Peripheral_Burst_Single;
Configure (Controller, Tx_Stream, Config_DMA);
Enable (Transceiver);
Enable_Interrupts (Transceiver, Received_Data_Not_Empty);
end Initialize_Hardware;
-- ---------------------------------------------------- --
-- Provided interface "Get_Message"
-- ---------------------------------------------------- --
procedure Get_Message(Last_Message: out asn1sccDebug_PrintableString) is
begin
Disable_Interrupts (Transceiver, Source => Received_Data_Not_Empty);
if Msg_Complete then
Last_Message := Incoming_Msg;
Msg_Complete := False;
else
Last_Message.Length := 0;
end if;
Enable_Interrupts (Transceiver, Received_Data_Not_Empty);
end Get_Message;
---------------------------------------------------------
-- Provided interface "Send_to_UART"
---------------------------------------------------------
procedure Send_to_UART(chars: in out asn1sccDebug_PrintableString) is
begin
-- Previous Send should have left status "Transfer Complete Indicated"
-- We must clear it before starting a new transfer
Clear_All_Status (Controller, Tx_Stream);
Start_Transfer
(Controller,
Tx_Stream,
Source => chars.Data'Address,
Destination => Data_Register_Address (Transceiver),
Data_Count => UInt16(chars.length));
Enable_DMA_Transmit_Requests (Transceiver);
end;
procedure Switch_Leds_On is
begin
All_LEDs_On;
end;
procedure Switch_Leds_Off is
begin
All_LEDs_Off;
end;
procedure Green_On is
begin
Turn_Off (Red_Led);
Turn_Off (Orange_Led);
Turn_On (Green_Led);
end;