int SetDeviceFloatValue(char *name, float *value)
{
    int             command, j;
    int             ival, ucode, error;
    short           ecode;
    char            mess[ERRMSGLEN + 1];
    FORSTR messD = {ERRMSGLEN, 0, 0, mess};

    MONITOR_ENTER(serializeAccess, "thread");

    int iofunc = 1;

    if (SetActivCell(name) > - 1) {
        command = PIO_DEFINE + PIO_EXECUTE + PIO_DELETE;
        for (j = 0; j < 8; j++) if (ActivCells[0].name[j] < ' ') ActivCells[0].name[j] = ' ';
        for (j = 0; j < 4; j++) if (ActivCells[0].att[j]  < ' ') ActivCells[0].att[j] = ' ';

        ActivCells[0].io_func = iofunc;
        ActivCells[0].ub.value = *value;
        Host2VaxF(&ActivCells[0].ub.value, ActivCells[0].ub.value);
        error = medmSingleIO(command, value, &ival, &ecode, &ucode);
        if(ecode != 1) {
            getErrMsgStr(&ecode, &messD);
            mess[ERRMSGLEN] = '\0';
            C_postMsgEvent(messageWindow, 1, vaPrintf("device <%s> has io-error %d %s\n", name, ecode, mess));
        }
        MONITOR_EXIT(serializeAccess, "thread");
        return error;
    } else {
        C_postMsgEvent(messageWindow, 1, vaPrintf("device <%s> fec not found\n", name));
        MONITOR_EXIT(serializeAccess, "thread");
        return 0;
    }
}
int RemoveValueCell(int indx)
{
    MONITOR_ENTER(serializeAccess, "thread");
    int status = RemoveCell(ValueCells, indx);
    MONITOR_EXIT(serializeAccess, "thread");
    return status;
}
int AddValueCell(char *name, int indx, char *aux)
{
    MONITOR_ENTER(serializeAccess, "thread");
    int status = AddCell(name, ValueCells, indx, aux);
    MONITOR_EXIT(serializeAccess, "thread");
    return status;
}
static void *Thread()
{
    while (True) {
        //printf("execute thread with %d cells\n", NumCells);
        MONITOR_ENTER(serializeAccess, "thread");
        if (NumCells > 0) {
            ExecuteValueCells();
        }
        MONITOR_EXIT(serializeAccess, "thread");

        usleep(333000);
    }
}
Exemplo n.º 5
0
////////////////////////////////////////////////////////////////////////////////////////////////////
/// @author NIVIS LLC, Mihaela Goloman, Eduard Erdei
/// @brief  Adds an alert to the ARMO alert queue
/// @param  p_pAlert - pointer to an alert type structure
/// @param  p_pBuf   - pointer to a buffer that contains alert data (Alert data len is inside p_pAlert->m_unSize)
/// @return service feddback code
/// @remarks
///      Access level: user level
uint8 ARMO_AddAlertToQueue(const ALERT* p_pAlert, const uint8* p_pBuf)
{
  // reset custom alert timer
  g_unCustomAlarmCounter = CUSTOM_ALERT_PERIOD;
  
  uint16 unLen = DMAP_GetAlignedLength( sizeof(ALERT) + p_pAlert->m_unSize );
  
  if (unLen > sizeof(g_aucARMOQueue)) // alert too big; will not fit even if queue is empty 
      return SFC_INVALID_SIZE;                       
  
  if( !g_aARMO[p_pAlert->m_ucCategory].m_ucAlertsDisable && (unLen < sizeof(g_aucARMOQueue)) ) // valid alert
  {  
      MONITOR_ENTER();
      
      while( (g_pARMOQueueEnd + unLen) > (g_aucARMOQueue + sizeof(g_aucARMOQueue) ) ) // not enough space
      {
          // remove first alarm (oldest one); do not check that g_pARMOQueueEnd > g_aucARMOQueue
          ALERT* pAlert = (ALERT*)g_aucARMOQueue;
          uint16 unAlertLen = DMAP_GetAlignedLength( sizeof(ALERT) + pAlert->m_unSize );
          
          g_pARMOQueueEnd -= unAlertLen;
          memmove(g_aucARMOQueue, g_aucARMOQueue+unAlertLen, g_pARMOQueueEnd-g_aucARMOQueue); 
      }
    
      ALERT* pNext = (ALERT*)g_pARMOQueueEnd;
      
      // copy alert header
      memcpy(pNext, p_pAlert, sizeof(ALERT));      
      
      pNext->m_ucID = ARMO_getNextAlertId( p_pAlert->m_ucCategory );
      pNext->m_ulNextSendTAI = 0xFFFFFFFF;  
      
      // fill the detection time 
      MLSM_GetCrtTaiTime( &pNext->m_stDetectionTime.m_ulSeconds, &pNext->m_stDetectionTime.m_unFract );
      
      // copy alert data  
      memcpy(g_pARMOQueueEnd + sizeof(ALERT), p_pBuf, p_pAlert->m_unSize);
      
      g_pARMOQueueEnd += unLen;

      MONITOR_EXIT();
      
      return SFC_SUCCESS;
  }
  
  return SFC_OBJECT_STATE_CONFLICT; // alerts are disabled for this category
}
Exemplo n.º 6
0
void ARMO_ProcessAlertAck(uint8 p_ucID)
{
  uint8* pBuf = g_aucARMOQueue;

#if ( _UAP_TYPE == UAP_TYPE_ISA100_API )
  uint8  ucNeedsUapNotification = 0;
#endif
  
  g_unAlarmTimeout = 0; // clean alert timeout
  
  MONITOR_ENTER();
  
  while (  pBuf < g_pARMOQueueEnd )
  {
    ALERT* pAlert = (ALERT*)pBuf;
    uint16 unLen = DMAP_GetAlignedLength( sizeof(ALERT) + pAlert->m_unSize );
    if(pAlert->m_ucID == p_ucID) // alert found
    {
        #if ( _UAP_TYPE == UAP_TYPE_ISA100_API )
            if( pAlert->m_unDetObjTLPort != ISA100_DMAP_PORT )
            {
                ucNeedsUapNotification = 1;            
            }
        #endif // #if ( _UAP_TYPE == UAP_TYPE_ISA100_API )
            
        g_pARMOQueueEnd -= unLen;
        memmove(pBuf, pBuf+unLen, g_pARMOQueueEnd-pBuf);
        break;
    }
    
    pBuf += unLen;
  }
  
  MONITOR_EXIT();
  
#if ( _UAP_TYPE == UAP_TYPE_ISA100_API )

  if( ucNeedsUapNotification )
  {
      UAP_NotifyAlertAcknowledge( p_ucID );
  }     

#endif
}
Exemplo n.º 7
0
void disconnectTask(void)
{
#ifndef HCF_TEST_DEBUG // do not perform a reset upon Cmd42/Cmd771 (used while running HCF tests, to allow JTAG debugging)
  if( g_ucDoDeviceInitFromCmd )
  { // the device reset flag was set through command 42 or 771
    // check the delay that allow the cmd response to be transmitted   
    if( 
#if ( WIHARTDEV_TYPE_ACCPOINT != WIHARTDEV_TYPE )             
        ((g_ucDoDeviceInitFromCmd & APP_DEVRESET_MASK_WIRED) && g_sDllGlobals.m_MyTxIsDone) ||  
#endif      
        ((int32)(RTC_COUNT - g_ulDelayInitFromCmd) >= 0) )
    { // save the RestartReason and wait for a watchdog reset
      if(g_ucDoDeviceInitFromCmd & APP_DEVRESET_MASK_C771)
      {
        //          if(g_ucNetJoinState < NET_JOIN_LOOSELY_COUPLED)
        //            g_ucNetState = NET_STATE_IDLE; // just trying to avoid a watchdog reset -doesn't work!
        //          else
        PrepareForReset(RREASON_CMD771);  
      }
      else
        PrepareForReset(RREASON_CMD42);
    }
  }
#endif // HCF_TEST_DEBUG
  
  
  if( g_ucResetReason )
  {
    if(!g_ucDllDisconnect)
    {
      switch (g_ucResetReason)
      {
      case RREASON_CMD42:
      case RREASON_CMD771:
        if(g_ucNetJoinState < NET_JOIN_LOOSELY_COUPLED)
          g_ucDllDisconnect = DLL_DISCONNECT_RESET; // no need to tx packets in queue or send disconnect packets
        //          else
        //          { // DLL_DISCONNECT_INACTIVE == g_ucDllDisconnect
        //            // send packets from queue then disconnect packets
        //          }
        break;
        
      // for the following: just send disconnect packets without waiting for DLL queue empty
      case RREASON_TOUT_TIMESRC:
      case RREASON_TOUT_LOOSELY:
      case RREASON_TOUT_BBR:
      case RREASON_RESET_BBR:
      case RREASON_NO_ACK:
      case RREASON_LOOP_DETECTED:
        g_ulDiscStartRTC = RTC_COUNT;
        g_ucDllDisconnect = DLL_DISCONNECT_WAIT_FOR_DIS_PACKETS;
        g_ucDllAllQueueSize = 0;
        g_ucDllCrtQueueSize = 0;
        break;
        
//    for the following: no need to wait for DLL queue nor to send disconnect packets  
//    case RREASON_TOUT_RECEPTION:
//    case RREASON_NO_SUPERFRAME:
//    case RREASON_OLD_ADVERTISE:
//    case RREASON_JOIN_REQ_EXCEEDED:
//    case RREASON_STACK_CORRUPTION:
//    case RREASON_CMD960:  // all actions have been finished already
//    case RREASON_CMD972:  // all actions have been finished already
      default: 
        g_ucDllDisconnect = DLL_DISCONNECT_RESET; 
        break;
        
      }
    }
    if(!g_ucDllDisconnect) 
    {
      // for reset reasons which imply sending packets from queue then disconnect packets
      DLL_LM_Request(DLL_SERV_DISCONNECT, NULL);  // makes g_ucDllDisconnect = DLL_DISCONNECT_WAIT_FOR_QUEUE;
    }
    else if(DLL_DISCONNECT_RESET == g_ucDllDisconnect)  
    {
      MONITOR_ENTER();
      
      PHY_Disable_Request();        
      NVM_SaveBeforeRestart(g_ucResetReason);
      
      // reset equivalent     
      //SW_RST = 0x87651234;
      
      // wait for watchdog reset -just in case
      while(1)
        ;
    }
  }
  
  
  
  
  if(DLL_DISCONNECT_INACTIVE == g_ucDllDisconnect)
    return; // this is the normal case, so return to not spend more time here
  
  if(DLL_DISCONNECT_WAIT_FOR_QUEUE == g_ucDllDisconnect) 
  {
    if(g_ucDllAllQueueSize && ((RTC_COUNT - g_ulDiscStartRTC) < g_ulDllQueueDiscCntr))
      return;       
    g_ulDiscStartRTC = RTC_COUNT;
    g_ucDllDisconnect = DLL_DISCONNECT_WAIT_FOR_DIS_PACKETS;
    g_ucDllAllQueueSize = 0; //time for emptying the dll queue has expired!
    g_ucDllCrtQueueSize = 0; //time for emptying the dll queue has expired!
  }
  else if(DLL_DISCONNECT_WAIT_FOR_DIS_PACKETS == g_ucDllDisconnect)
  {
    if((RTC_COUNT - g_ulDiscStartRTC) < DISCONNECT_INTERVAL)
      return;       
    g_ucDllDisconnect = DLL_DISCONNECT_RESET;
  }
}
int SetDeviceStringValue(char *name, char *data)
{
    int             command, i, j;
    char            asc[80];
    int             ival, ucode, error;
    short           ecode;
    float           value;
    char            mess[ERRMSGLEN + 1];
    FORSTR messD = {ERRMSGLEN, 0, 0, mess};
    char            devS[9], attS[5];
    DSC             devD = {8, 0, 0, devS};
    DSC             attD = {4, 0, 0, attS};
    F_CMDT_RCRD     bitmapping[MAX_RECORDS];
    int             dim = 16, num;
    int             found = False;

    MONITOR_ENTER(serializeAccess, "thread");

    //printf("SendString %s %s\n", name, data);

    if (SetActivCell(name) > - 1) {
        command = PIO_DEFINE + PIO_EXECUTE + PIO_DELETE;
        for (j = 0; j < 8; j++) if (ActivCells[0].name[j] < ' ') ActivCells[0].name[j] = ' ';
        for (j = 0; j < 4; j++) if (ActivCells[0].att[j] < ' ') ActivCells[0].att[j] = ' ';

        memcpy(devS, ActivCells[0].name, 8);
        memcpy(attS, ActivCells[0].att, 4);
        num = getCmdNames(&devD, &attD, &dim, bitmapping);

        for(i = 0; i < num; i++) {
            char aux[9];
            strncpy(aux, bitmapping[i].bitName, 8);
            aux[8] = '\0';
            //printf("%s %s\n", aux, data);
            if(IsInside(aux, data)) {
                found = True;
                //printf("found number=%d bitmapping is %x %x\n", i, bitmapping[i].smask, bitmapping[i].cmask);

                ActivCells[0].conv = 1;
                ActivCells[0].io_func = CELL_DIGITAL;
                ActivCells[0].ub.int2val[0] = (unsigned short) bitmapping[i].smask;
                ActivCells[0].ub.int2val[1] = (unsigned short) bitmapping[i].cmask;
                sprintf(asc, "Digital Action on %.8s.%.4s;%d - Data %04x %04x", ActivCells[0].name,
                        ActivCells[0].att,
                        ActivCells[0].conv,
                        (unsigned short) ActivCells[0].ub.int2val[0],
                        (unsigned short) ActivCells[0].ub.int2val[1]);

                C_postMsgEvent(messageWindow, 1, asc);

                error = medmSingleIO(command, &value, &ival, &ecode, &ucode);
                if(ecode != 1) {
                    getErrMsgStr(&ecode, &messD);
                    mess[ERRMSGLEN] = '\0';
                    C_postMsgEvent(messageWindow, 1, vaPrintf("device <%.8s.%.4s;%d> has io-error %d %s\n", ActivCells[0].name, ActivCells[0].att, ActivCells[0].conv, ecode, mess));
                }
                MONITOR_EXIT(serializeAccess, "thread");
                return error;
            }
        }
        if(!found) {
            sprintf(asc, "device  <%.8s.%.4s;%d> no bitpattern found", ActivCells[0].name, ActivCells[0].att, ActivCells[0].conv);
            C_postMsgEvent(messageWindow, 1, asc);
            MONITOR_EXIT(serializeAccess, "thread");
            return 0;
        }
    } else {
        C_postMsgEvent(messageWindow, 1, vaPrintf("device <%s> fec not found\n", name));
        MONITOR_EXIT(serializeAccess, "thread");
        return 0;
    }

    MONITOR_EXIT(serializeAccess, "thread");
    return 0;
}