aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModelLocator.cs
blob: a7d08eb45b0e57d157e787e0f6acf7d681dfabd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Tango.Core.DI;
using Tango.MachineStudio.Technician.ViewModels;

namespace Tango.MachineStudio.Technician
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public static class ViewModelLocator
    {
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        static ViewModelLocator()
        {
            TangoIOC.Default.Register<MachineTechViewVM>();
        }

        public static MachineTechViewVM MachineTechViewVM
        {
            get
            {
                return TangoIOC.Default.GetInstance<MachineTechViewVM>();
            }
        }
    }
}
ght .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * CommunicationTask.c
 *
 *  Created on: 8 ����� 2018
 *      Author: shlomo
 */

#include "include.h"
#include "drivers/Uart_Comm/uart.h"
#include "communicationTask.h"
static void (*callback)(char* buffer, size_t length);

Mailbox_Handle          CommunicationRxMsgQ = NULL;
Mailbox_Handle          CommunicationTxMsgQ = NULL;

typedef struct CommRxMessage{
    uint16_t messageId;
    uint16_t msgSize;
}CommRxMessageStruc;
typedef struct CommTxMessage{
    uint16_t messageId;
    uint16_t msgSize;
    char *Buff;
}CommTxMessageStruc;

int CommType = isUART;

struct serialBuffer {
  char *buffer;
  size_t used;
  size_t size;
} typedef SerialBuffer;

char Buffer[2000];
SerialBuffer inBuffer;
uint32_t initArray(size_t initialSize) {
  SerialBuffer *a = &inBuffer;
  if (initialSize >= 2000) return 0;
  a->buffer = Buffer;
  a->used = 0;
  a->size = initialSize;
  return initialSize;
}

void insertArray(char element) {
    SerialBuffer *a = &inBuffer;
  // a->used is the number of used entries, because a->array[a->used++] updates a->used only *after* the array has been accessed.
  // Therefore a->used can go up to a->size
  a->buffer[a->used++] = element;
}

void freeArray(void) {
    SerialBuffer *a = &inBuffer;
  a->used = a->size = 0;
}

Mailbox_Handle          CommunicationRxMsgQ;
uint32_t CommunicationTaskInit(void)
{
    USBCDCD_init();
    Init_U0();
    return OK;
}
uint32_t CommTxMsgCounter = 0;
uint32_t CommRxMsgCounter = 0;
uint32_t CommunicationTaskMessageReceived(uint16_t msgSize)
{
    CommRxMessageStruc Message;
    CommRxMsgCounter++;

    Message.messageId = 1;
    Message.msgSize = msgSize;
    if (CommunicationRxMsgQ != NULL)
        /*retcode =*/ Mailbox_post(CommunicationRxMsgQ , &Message, BIOS_NO_WAIT);

    return OK;

}
void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length))
{
    callback = callback_ptr;
}

/******************************************************************************
 *  ======== communicationTask ========
 *  Task for this function is created statically. See the project's .cfg file.
 *  this communication task is created statically in system initialization, in blocking mode
 *  over one of the chosen ommunication methods (USB or Blutooth).
 ******************************************************************************/
void communicationTask(UArg arg0, UArg arg1)
{

    //uint32_t ui32RxCount;
    CommRxMessageStruc Message;

    initArray(1);

    //ui32RxCount = 0;
    CommunicationRxMsgQ = Mailbox_create(sizeof(CommRxMessageStruc), 5, NULL,NULL);

    /* Block while the device is NOT connected to the USB */
//    Semaphore_pend(initConnectionSem, BIOS_WAIT_FOREVER);

    while(1)
    {
        Mailbox_pend(CommunicationRxMsgQ , &Message, BIOS_WAIT_FOREVER);
        switch (Message.messageId)
        {
            case 1:
                //ui32RxCount += Message.msgSize;
                if (callback != NULL)
                {
                    callback(inBuffer.buffer,inBuffer.used);
                }

                freeArray();
                initArray( 1);
                break;
            default:
                break;
        }
    }

}

uint32_t CommunicationTaskSendMessage(char* buffer,size_t length)
{
    CommTxMessageStruc Message;
    CommTxMsgCounter++;

    Message.messageId = 1;
    Message.msgSize = length;
    Message.Buff = buffer;
    if (CommunicationTxMsgQ != NULL)
        /*retcode =*/ Mailbox_post(CommunicationTxMsgQ , &Message, BIOS_NO_WAIT);

    return OK;
}
int32_t SetCommunicationPath(bool UARTorUSB)
{
    CommType = UARTorUSB;
    return OK;
}

/******************************************************************************
 *  ======== communicationTask ========
 *  Task for this function is created statically. See the project's .cfg file.
 *  this communication task is created statically in system initialization, in blocking mode
 *  over one of the chosen ommunication methods (USB or Blutooth).
 ******************************************************************************/
void communicationTxTask(UArg arg0, UArg arg1)
{

    //uint32_t ui32RxCount;
    CommTxMessageStruc Message;
/*    typedef struct CommRxMessage{
        uint16_t messageId;
        uint16_t msgSize;
        char *Buff;
    }CommTxMessageStruc;
*/
    initArray(1);

    #ifdef USE_USB
         SetCommunicationPath(isUSB);
    #else
         SetCommunicationPath(isUART);
    #endif
    //ui32RxCount = 0;
    CommunicationTxMsgQ = Mailbox_create(sizeof(CommTxMessageStruc), 10, NULL,NULL);

    /* Block while the device is NOT connected to the USB */
//    Semaphore_pend(initConnectionSem, BIOS_WAIT_FOREVER);

    while(1)
    {
        Mailbox_pend(CommunicationTxMsgQ , &Message, BIOS_WAIT_FOREVER);
        switch (Message.messageId)
        {
            case 1:
                if (CommType == isUSB)
                    USBCDCD_sendData(Message.Buff, Message.msgSize,10);
                else if (CommType == isUART)
                    Uart_Tx(Message.Buff, Message.msgSize);
                free (Message.Buff);
                break;
            default:
                break;
        }
    }

}