示例#1
0
 uint8_t
 Sl868a::handleGpsRxData(uint8_t inChar)
 {
     if (rxMsg.idx < (SL868A_MAX_MSG_LEN-2)) {

         if ((inChar < 21) && !((inChar == '\n') || (inChar == '\r')))  {
             return SME_OK;
             }  else if (inChar == '$') {
             memset(&rxMsg, 0, sizeof(rxMsg));
         }

         rxMsg.data[rxMsg.idx++] = inChar;

         if (inChar == '\n')  {
             if (rxMsg.idx > 3) {
                 rxMsg.data[rxMsg.idx] = '\0';
                 if (crcCheck(rxMsg.data, rxMsg.idx)) {
                    parseGpsRxMsg();
                    processGpsRxMsg();
                 }
             }
         }
         } else {
         memset(&rxMsg, 0, sizeof(rxMsg));
     }

     return SME_OK;
 }
示例#2
0
byte SmeSFX::composeSfxDataAnswer(char data) {

    // by default consider the char is OK
    sfxError = SME_SFX_OK;

    switch (recFsm) {
        case headerRec:
        dataAck = SFX_DATA_ACK_PROCESSING;
        if (SFX_MSG_HEADER != data) {
            sfxError = SME_SFX_KO;
            return sfxError;
        }
        else
        recFsm = lenRec;
        break;

        case lenRec:
        answer.length = data;
        recFsm = typeRec;
        break;

        case typeRec:
        answer.type  = data;
        recFsm = sequenceRec;
        break;

        case sequenceRec:
        recFsm = checkSequenceConsistence(data);
        break;

        case payloadRec:
        answer.payload[answer.payloadPtr++]= data;
        if (answer.payloadPtr == answer.length) {
            recFsm = check_msg_error();
        }
        break;

        case crcRec:
        answer.crc[answerCrcCounter++] = data;
        if (answerCrcCounter == 2)
        recFsm = crcCheck();
        break;

        case tailerRec:
        recFsm = headerRec;
        dataAck = SFX_DATA_ACK_OK;
        if (SFX_MSG_TAILER == data){
            sfxError = SME_SFX_OK;
        } else
            sfxError = SME_SFX_KO;
        break;

        case nullState:
        // enter here in case of CRC error or sequence error
        dataAck = SFX_DATA_ACK_KO;
        break;
    }

    return sfxError;
}
示例#3
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       C-code main function.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  uint16 crc[2];

  // Prefer to run Image-B over Image-A so that Image-A does not have to invalidate itself.
  HalFlashRead(BIM_IMG_B_PAGE, BIM_CRC_OSET, (uint8 *)crc, 4);

  if ((crc[0] != 0xFFFF) && (crc[0] != 0x0000))
  {
    if (crc[0] == crc[1])
    {
      JumpToImageAorB = 1;
      // Simulate a reset for the Application code by an absolute jump to the expected INTVEC addr.
      asm("LJMP 0x4030");
      HAL_SYSTEM_RESET();  // Should not get here.
    }
    /* This check is disruptive when an OAD process to Image-A is interrupted - this check must
     * complete before the still good Image-A is run.
    else if (crc[1] == 0xFFFF)  // If first run of an image that was physically downloaded.*/
    {
      crcCheck(BIM_IMG_B_PAGE, crc);
    }
    /**/
  }

  HalFlashRead(BIM_IMG_A_PAGE, BIM_CRC_OSET, (uint8 *)crc, 4);

  if ((crc[0] != 0xFFFF) && (crc[0] != 0x0000))
  {
    if (crc[0] == crc[1])
    {
      JumpToImageAorB = 0;
      // Simulate a reset for the Application code by an absolute jump to the expected INTVEC addr.
      asm("LJMP 0x0830");
      HAL_SYSTEM_RESET();  // Should not get here.
    }
    else if (crc[1] == 0xFFFF)  // If first run of an image that was physically downloaded.
    {
      crcCheck(BIM_IMG_A_PAGE, crc);
    }
  }

  SLEEPCMD |= 0x03;  // PM3, All clock oscillators off, voltage regulator off.
  halSleepExec();
  HAL_SYSTEM_RESET();  // Should not get here.
}
示例#4
0
int ImagerDoc::check_copy(void * in )
{

   int block_status   = 0;
   int section_status = 0;
   //int sub_status = 0;

   block_status = (crcCheck(in, BLOCK0_BSZ) == MAGIC_CRC);
   // 0 is fail
   if (block_status == 0) {

     //std::cout << "block id = " << gvar.blockId() << ", count = " << gvar.blockCount();
     //std::cout << ": Crc Check failed (in imagerdoc copy subroutine)\n" << std::flush;

      section_status = parity_check(in); // try to recover
      
      // fail ==1, pass=0
      //for (int j=0; j<6; j++) {
      //  sub_status += ( (section_status & (2 << j)) ==  (2 << j));
      //}
      //std::cout << sub_status << "  sections of block 0 failed parity check\n";


      if ((section_status & 2) == 2) {
	//std::cout << "  section 1 of block 0, count = " << gvar.blockCount() << " failed parity check\n";
	 // check some key values
      } else {
        // for now, if section 1 passes parity assume it's values are ok
        // most of the code only uses values from section 1
	block_status = 1;
      }


   }

   return(block_status);
   
}
示例#5
0
void WH1080::process(void) {
  int newVal;
  for (int i = 0; i < 10; i++) {
    newVal += digitalRead(RXPIN) ? 1 : 0;
    delayMicroseconds(5);
  }
  newVal = (newVal + 5) / 10;

  /*
   * Handle situations where the clock has rolled over
   * between transitions (happens every ~70 mins).
   */
  this->now = micros();

  if (transition_t <= this->now)
    this->duration = this->now - transition_t;
  else
    this->duration = (~transition_t) + this->now;

  if (newVal != this->val) { // then transitioning state

    /*
     *We update the transition time for the pulse, and
     *change the current state of the input this->value.
     */
    transition_t = this->now;
    this->val = newVal;

    /*
     *If the pulse width (hi or low) is outside the
     *range of the Fine Offset signal, then ignore them.
     */
    if (this->duration < (SHORT_PULSE - SHORT_MARGIN) || this->duration > (LONG_PULSE + LONG_MARGIN)) {
      // Meaningless pulse
      return;
    }

    /*
     *If we reach here, then we have seen a potentially
     *this->valid pulse. Shift the bit into the register.
     */
    if (newVal == 1) {
      // rising edge of a pulse (0 -> 1)
    } else {
      // falling edge of a pulse (1 -> 0)
      if ( this->duration >= (SHORT_PULSE - SHORT_MARGIN) && this->duration <= (SHORT_PULSE + SHORT_MARGIN) ) {
        // short pulse is binary '1'
        this->shift_register = (this->shift_register << 1) | 0x01;
        this->bit_count++;

      } else if (this->duration >= (LONG_PULSE - LONG_MARGIN) && this->duration <= (LONG_PULSE + LONG_MARGIN)) {
        // long pulse is binary '0'
        this->shift_register = (this->shift_register << 1);
        this->bit_count++;

      }
    }

    // Look for signature of 0xfa (4 bits 0xf0 pre-amble + 0xa)
    if ((this->shift_register & 0xff) == 0xfa && this->buffer_idx == 0) {
      // Found signature - discard pre-amble and leave 0x0a.
      this->shift_register = 0x0a;
      this->bit_count = 4;
      this->sig_seen = 1;// Flag that the signature has been seen.


    } else if (this->bit_count == 8 && this->sig_seen) {
      // Got a byte, so store it if we have room.
      if (this->buffer_idx < BUFFER_SIZE) {
        _byte_buffer[this->buffer_idx++] = (byte)(this->shift_register & 0xff);
      } else {
#ifdef DEBUG
        Serial.println("Buffer Undersize");
#endif
      }

      this->shift_register = 0;
      this->bit_count = 0;
    }

  } else {

    /*
     *Have we reached timeout on this->duration? If so, process any
     *bytes present in the buffer and then reset the state
     *variables.
     */
    if (this->duration > 5000) {

      if (this->buffer_idx > 0) {
        /*
         *If we have enough bytes, then verify the checksum.
         */
        if (crcCheck()) {
          this->decode();
          Serial.print(rawData[0], HEX);
          for (int l = 1; l < BUFFER_SIZE; l++) {
              Serial.print(" ");
            Serial.print(rawData[l], HEX);
          };
          Serial.println();
        }

        this->buffer_idx = 0;
      }

      this->shift_register = 0;
      this->bit_count = 0;
      this->sig_seen = 0;
    }

  }
}