void main(void) { BSP_Init(); // Initialisation de la librairie BSP NWK_DELAY(500); SMPL_Init(&RxCallBack); // Initialisation de la librairie simpliciTI SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); // Activation de la radio pour permettre la réception des messages COM_Init(); // Initialisation du port COM while (1) { if(broadSem) { memset(msg, 0, sizeof(msg)); if ((SMPL_Receive(SMPL_LINKID_USER_UUD, msg, &msgLen)) == SMPL_SUCCESS) // Cette fonction permet de stocker les messages reçu par un périphérique en spécifiant son linkID { sigInfo.lid = SMPL_LINKID_USER_UUD; // Permet d'indiquer les informations de quel périphérique sont demandées SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, &sigInfo); // On récupère les informations sur la force de connexion dans la structure sigInfo msg[5] = 'S'; msg[6] = sigInfo.sigInfo.rssi+128; msg[7] = 'L'; msg[8] = sigInfo.sigInfo.lqi; msg[9] = 0xFF; broadSem--; TXString(msg, sizeof(msg)); } } } }
/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer if( CALBC1_1MHZ == 0xFF && CALDCO_1MHZ == 0xFF )// Do not run if cal values { while(1) { __delay_cycles(65000); } } BCSCTL1 = CALBC1_1MHZ; // Set DCO = 1MHz DCOCTL = CALDCO_1MHZ; Set_TimerB(); USCI_A_Init(); P1OUT = 0x00; P1DIR = 0xFF; while(1) { V_fibre = ReadFibreSensor(); TXString("\r\nFibre=",8); TXData(V_fibre); P1OUT ^= 0x01; delay(sec1); } }
/* prints the state of the queues' elements, * including the number of retries for OUTQ when slot in use */ void Qprint() { #ifdef PRINT_Q frameInfo_t *pFI; uint8_t i; char output_in_use[] = {" (X)IN_USE"}; /* print INQ */ pFI = sInFrameQ; print_debug("\r\nINQ: ",7); for (i=0; i<SIZE_Q; ++i, ++pFI) { if (pFI->fi_usage == FI_AVAILABLE) { print_debug(" AVAILABLE",10); } else { print_debug(" IN_USE",7); } } /* print OUTQ */ pFI = sOutFrameQ; print_debug("\r\nOUTQ:",7); for (i=0; i<SIZE_Q; ++i, ++pFI) { if (pFI->fi_usage == FI_AVAILABLE) { print_debug(" AVAILABLE",10); } else { output_in_use[2] = '0'+pFI->retries; TXString(output_in_use, sizeof output_in_use); } } #endif }
void print_counter(int8_t counter) { char output[] = {" "}; output[0] = '0'+((counter/10)%10); output[1] = '0'+ (counter%10); TXString(output, (sizeof output)-1); }
int main(void) { BSP_Init(); MRFI_Init(/*0x9D, 0x58, 0x5C*/); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); __bis_SR_register(GIE); while(1) { //NEED TO SET !!! uint8_t SubChannelsAmount = 13; // for(uint8_t SubChannelsCounter = 1; SubChannelsCounter <= SubChannelsAmount; SubChannelsCounter++) { SetBaseFrequencyRegisters(SubChannelsCounter); ReadChannelsAndSendRSSI(); } TXString("\n",1); } }
void print_rssi(int8_t rssi) { char output[] = {" 000 "}; if (rssi<0) {output[0]='-';rssi=-rssi;} output[1] = '0'+((rssi/100)%10); output[2] = '0'+((rssi/10)%10); output[3] = '0'+ (rssi%10); TXString(output, (sizeof output)-1); }
void TXData(unsigned int data) { char DataString[] = {"XXXX"}; // to hold integer from 0-9999 DataString[0] = '0' + (data/1000)%10; DataString[1] = '0' + (data/100)%10; DataString[2] = '0' + (data/10)%10; DataString[3] = '0' + data%10; TXString(DataString,sizeof(DataString)); }
void print_time() { uint16_t time = TAR/12; //as it's a 12kHz clock, these are ms char output[] = {"\r\ntime=XX.XXX s"}; output[7] = '0'+((time/10000)%10); output[8] = '0'+((time/1000)%10); output[10] = '0'+((time/100)%10); output[11] = '0'+((time/10)%10); output[12] = '0'+(time%10); TXString(output, sizeof output); }
int main(void) { //int8_t rssi; //uint8_t channel; BSP_Init(); MRFI_Init(/*0x9D, 0x58, 0x5C*/); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); __bis_SR_register(GIE); while(1) { //change to 1th range of base frq SetBaseFrequencyRegisters(1); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(2); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(3); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(4); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(5); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(6); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(7); ReadChannelsAndSendRSSI(); SetBaseFrequencyRegisters(8); ReadChannelsAndSendRSSI(); TXString("\n",1); } }
void transmitDataString(char data_mode, char addr[4],char rssi[3], char msg[MESSAGE_LENGTH] ) { char temp_string[] = {" XX.XC"}; int temp = msg[0] + (msg[1]<<8); if(!(data_mode & degCMode)) { temp = (int)(((float)temp)*1.8)+320; temp_string[5] = 'F'; } if( temp < 0 ) { temp_string[0] = '-'; temp = temp * -1; } else if( ((temp/1000)%10) != 0 ) { temp_string[0] = '0'+((temp/1000)%10); } temp_string[4] = '0'+(temp%10); temp_string[2] = '0'+((temp/10)%10); temp_string[1] = '0'+((temp/100)%10); if(data_mode & verboseMode) { char output_verbose[] = {"\r\nNode:XXXX,Temp:-XX.XC,Battery:X.XV,Strength:XXX%,RE:no "}; output_verbose[46] = rssi[2]; output_verbose[47] = rssi[1]; output_verbose[48] = rssi[0]; output_verbose[17] = temp_string[0]; output_verbose[18] = temp_string[1]; output_verbose[19] = temp_string[2]; output_verbose[20] = temp_string[3]; output_verbose[21] = temp_string[4]; output_verbose[22] = temp_string[5]; output_verbose[32] = '0'+(msg[2]/10)%10; output_verbose[34] = '0'+(msg[2]%10); output_verbose[7] = addr[0]; output_verbose[8] = addr[1]; output_verbose[9] = addr[2]; output_verbose[10] = addr[3]; TXString(output_verbose, sizeof output_verbose ); } else { char output_short[] = {"\r\n$ADDR,-XX.XC,V.C,RSI,N#"}; output_short[19] = rssi[2]; output_short[20] = rssi[1]; output_short[21] = rssi[0]; output_short[8] = temp_string[0]; output_short[9] = temp_string[1]; output_short[10] = temp_string[2]; output_short[11] = temp_string[3]; output_short[12] = temp_string[4]; output_short[13] = temp_string[5]; output_short[15] = '0'+(msg[2]/10)%10; output_short[17] = '0'+(msg[2]%10); output_short[3] = addr[0]; output_short[4] = addr[1]; output_short[5] = addr[2]; output_short[6] = addr[3]; TXString(output_short, sizeof output_short ); } }
void trace(char *string) { int s = strlen(string); TXString(string,s); }
int main(void) { Config32MHzClock(); // Setup the 32MHz Clock. Should really be using 2MHz... // Setup output and input ports. LEDPORT.DIRSET = 0xFF; LEDPORT.OUT = 0xFF; AD9835_PORT.DIRCLR = 0x40; PORTC.DIRSET = 0x04; // Start up the timer. init_timer(); sensors.begin(); sensors.requestTemperatures(); // Wait a bit before starting the AD9835. // It seems to take a few hundred ms to 'boot up' once power is applied. _delay_ms(500); // Configure the AD9835, and start in sleep mode. AD9835_Setup(); AD9835_Sleep(); // Setup the AD9835 for our chosen datamode. TX_Setup(); AD9835_Awake(); // Broadcast a bit of carrier. _delay_ms(1000); TXString("Booting up...\n"); // Kind of like debug lines. // Start up the GPS RX UART. init_gps(); // Turn Interrupts on. PMIC.CTRL = PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm; sei(); sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data. //TXString("GPS Active, Interrupts On.\n"); int found_sensors = sensors.getDeviceCount(); //sprintf(tx_buffer,"Found %u sensors.\n",found_sensors); // TXString(tx_buffer); unsigned int counter = 0; // Init out TX counter. while(1){ // Identify every few minutes if ((counter%30 == 0)&&(data_mode != FALLBACK)) TXString("DE VK5VZI Project Horus HAB Launch - projecthorus.org \n"); // Read ADC PortA pin 0, using differential, signed input mode. Negative input comes from pin 1, which is tied to ground. Use VCC/1.6 as ref. uint16_t temp = readADC(); float bat_voltage = (float)temp * 0.001007572056668* 8.5; floatToString(bat_voltage,1,voltString); // Collect GPS data gps.f_get_position(&lat, &lon); sats = gps.sats(); if(sats>2){LEDPORT.OUTCLR = 0x80;} speed = gps.f_speed_kmph(); altitude = (long)gps.f_altitude(); gps.crack_datetime(0, 0, 0, &time[0], &time[1], &time[2]); floatToString(lat, 5, latString); floatToString(lon, 5, longString); sensors.requestTemperatures(); _intTemp = sensors.getTempC(internal); _extTemp = sensors.getTempC(external); if (_intTemp!=85 && _intTemp!=127 && _intTemp!=-127 && _intTemp!=999) intTemp = _intTemp; if (_extTemp!=85 && _extTemp!=127 && _extTemp!=-127 && _extTemp!=999) extTemp = _extTemp; if(data_mode != FALLBACK){ // Construct our Data String sprintf(tx_buffer,"$$DARKSIDE,%u,%02d:%02d:%02d,%s,%s,%ld,%d,%d,%d,%d,%s",counter++,time[0], time[1], time[2],latString,longString,altitude,speed,sats,intTemp,extTemp,voltString); // Calculate the CRC-16 Checksum char checksum[10]; snprintf(checksum, sizeof(checksum), "*%04X\n", gps_CRC16_checksum(tx_buffer)); // And copy the checksum onto the end of the string. memcpy(tx_buffer + strlen(tx_buffer), checksum, strlen(checksum) + 1); }else{ // If our battery is really low, we don't want to transmit much data, so limit what we TX to just an identifier, battery voltage, and our position. sprintf(tx_buffer, "DE VK5VZI HORUS8 %s %s %s %ld", bat_voltage, latString, longString,altitude); } // Blinky blinky... LEDPORT.OUTTGL = 0x20; // Transmit! TXString(tx_buffer); sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data again. /* // Check the battery voltage. If low, switch to a more reliable mode. if((bat_voltage < BATT_THRESHOLD) && (data_mode != RELIABLE_MODE)){ new_mode = RELIABLE_MODE; // This string should be changed if the 'reliable' mode is changed. TXString("Battery Voltage Below 9V. Switching to DominoEX8.\n"); } */ // Perform a mode switch, if required. // Done here to allow for mode changes to occur elsewhere. if(new_mode != -1){ data_mode = new_mode; TX_Setup(); new_mode = -1; } // And wait a little while before sending the next string. // Don't delay for domino - synch stuffs up otherwise if(data_mode != DOMINOEX8){ _delay_ms(1000); } } }
void main (void) { addr_t lAddr; bspIState_t intState; char *Flash_Addr; // Initialize radio address location Flash_Addr = (char *)0x10F0; WDTCTL = WDTPW + WDTHOLD; // Stop WDT // delay loop to ensure proper startup before SimpliciTI increases DCO // This is typically tailored to the power supply used, and in this case // is overkill for safety due to wide distribution. __delay_cycles(65000); if( CALBC1_8MHZ == 0xFF && CALDCO_8MHZ == 0xFF )// Do not run if cal values { P1DIR |= 0x03; BSP_TURN_ON_LED1(); BSP_TURN_OFF_LED2(); while(1) { __delay_cycles(65000); BSP_TOGGLE_LED2(); BSP_TOGGLE_LED1(); } } BSP_Init(); if( Flash_Addr[0] == 0xFF && Flash_Addr[1] == 0xFF && Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF ) { createRandomAddress(); // Create Random device address at } // initial startup if missing lAddr.addr[0]=Flash_Addr[0]; lAddr.addr[1]=Flash_Addr[1]; lAddr.addr[2]=Flash_Addr[2]; lAddr.addr[3]=Flash_Addr[3]; //SMPL_Init(); SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); MCU_Init(); //Transmit splash screen and network init notification TXString( (char*)splash, sizeof splash); TXString( "\r\nInitializing Network....", 26 ); SMPL_Init(sCB); // network initialized TXString( "Done\r\n", 6); // main work loop while(1) { // Wait for the Join semaphore to be set by the receipt of a Join frame from a // device that supports and End Device. if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS)) { // listen for a new connection SMPL_LinkListen(&sLID[sNumCurrentPeers]); sNumCurrentPeers++; BSP_ENTER_CRITICAL_SECTION(intState); if (sJoinSem) { sJoinSem--; } BSP_EXIT_CRITICAL_SECTION(intState); } // if it is time to measure our own temperature... if(sSelfMeasureSem) { // TXString("\r\n...", 5); BSP_TOGGLE_LED1(); sSelfMeasureSem = 0; } // Have we received a frame on one of the ED connections? // No critical section -- it doesn't really matter much if we miss a poll if (sPeerFrameSem) { uint8_t msg[MESSAGE_LENGTH], len, i; // process all frames waiting for (i=0; i<sNumCurrentPeers; ++i) { if (SMPL_Receive(sLID[i], msg, &len) == SMPL_SUCCESS) { ioctlRadioSiginfo_t sigInfo; sigInfo.lid = sLID[i]; SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo); transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg ); BSP_TURN_ON_LED2(); // Toggle LED2 when received packet BSP_ENTER_CRITICAL_SECTION(intState); sPeerFrameSem--; BSP_EXIT_CRITICAL_SECTION(intState); __delay_cycles(10000); BSP_TURN_OFF_LED2(); } } } } }
void transmitDataString(char addr[4],char rssi[3], char msg[MESSAGE_LENGTH] ) { char output[] = {"ID=XXX.X,Vcc=X.XXX,T=XXX.XX,RH=XX.XX,Acc_x=XXXXX.XX,Acc_y=XXXXX.XX,Acc_z=XXXXX.XX,P=XXXX.XX,Vpd=XXXX.X,status=XXXXXXXX.X\r\n"}; // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 // 0 1 2 3 4 5 6 7 8 1 2 3 4 char id_string[] = {"YYY.0"}; // add '0' so that python can read it (for some reason only reads floats, not ints) char vcc_string[] = {"Y.YYY"}; char t_string[] = {"YYY.YY"}; char rh_string[] = {"YY.YY"}; char acc_x_string[] = {"YYYYY.00"}; char acc_y_string[] = {"YYYYY.00"}; char acc_z_string[] = {"YYYYY.00"}; char p_string[] = {"YYYY.YY"}; char status_string[] = {"bbbbbbbb.0"}; char vpd_string[] = {"XXXX.0"}; int i,j; i=0; int ID = msg[i++]; int Vcc = (msg[i++]<<8) + msg[i++]; int T = (msg[i++]<<8) + msg[i++]; int RH = (msg[i++]<<8) + msg[i++]; int A_x = (msg[i++]<<8) + msg[i++]; int A_y = (msg[i++]<<8) + msg[i++]; int A_z = (msg[i++]<<8) + msg[i++]; long P = ((msg[i++]<<8) + msg[i++])&0xFFFF; P = (P<<8)+msg[i++]; int Vpd = (msg[i++]<<8) + msg[i++]; char msg_status = msg[i++]; // ID if (ID<100) { id_string[0] = ' '; } else { id_string[0] = '0'+((ID/100)%10); } if (ID<10) { id_string[1] = ' '; } else { id_string[1] = '0'+((ID/10)%10); } id_string[2] = '0'+(ID%10); // Vcc vcc_string[0] = '0'+((Vcc/1000)%10); vcc_string[2] = '0'+((Vcc/100)%10); vcc_string[3] = '0'+((Vcc/10)%10); vcc_string[4] = '0'+(Vcc%10); // T if( T < 0 ) { t_string[0] = '-'; T = T * -1; } else { t_string[0] = '0'+((T/10000)%10); } t_string[1] = '0'+((T/1000)%10); t_string[2] = '0'+((T/100)%10); t_string[4] = '0'+((T/10)%10); t_string[5] = '0'+(T%10); // RH rh_string[0] = '0'+((RH/1000)%10); rh_string[1] = '0'+((RH/100)%10); rh_string[3] = '0'+((RH/10)%10); rh_string[4] = '0'+(RH%10); // A_x if( A_x < 0 ) { A_x = A_x * -1; if (A_x <1000) { acc_x_string[0] = ' '; if (A_x < 100) { acc_x_string[1] = ' '; if (A_x <10) { acc_x_string[2] = ' '; acc_x_string[3] = '-'; acc_x_string[4] = '0'+(A_x%10); } else // if >= 10 { acc_x_string[2] = '-'; acc_x_string[3] = '0'+((A_x/10)%10); acc_x_string[4] = '0'+(A_x%10); } } else // if >= 100 { acc_x_string[1] = '-'; acc_x_string[2] = '0'+((A_x/100)%10); acc_x_string[3] = '0'+((A_x/10)%10); acc_x_string[4] = '0'+(A_x%10); } } else // if >= 1000 { acc_x_string[0] = '-'; acc_x_string[1] = '0'+((A_x/1000)%10); acc_x_string[2] = '0'+((A_x/100)%10); acc_x_string[3] = '0'+((A_x/10)%10); acc_x_string[4] = '0'+(A_x%10); } } else // if >= 000 { acc_x_string[0] = ' '; acc_x_string[1] = '0'+((A_x/1000)%10); acc_x_string[2] = '0'+((A_x/100)%10); acc_x_string[3] = '0'+((A_x/10)%10); acc_x_string[4] = '0'+(A_x%10); } // A_y if( A_y < 0 ) { A_y = A_y * -1; if (A_y <1000) { acc_y_string[0] = ' '; if (A_y < 100) { acc_y_string[1] = ' '; if (A_y <10) { acc_y_string[2] = ' '; acc_y_string[3] = '-'; acc_y_string[4] = '0'+(A_y%10); } else // if >= 10 { acc_y_string[2] = '-'; acc_y_string[3] = '0'+((A_y/10)%10); acc_y_string[4] = '0'+(A_y%10); } } else // if >= 100 { acc_y_string[1] = '-'; acc_y_string[2] = '0'+((A_y/100)%10); acc_y_string[3] = '0'+((A_y/10)%10); acc_y_string[4] = '0'+(A_y%10); } } else // if >= 1000 { acc_y_string[0] = '-'; acc_y_string[1] = '0'+((A_y/1000)%10); acc_y_string[2] = '0'+((A_y/100)%10); acc_y_string[3] = '0'+((A_y/10)%10); acc_y_string[4] = '0'+(A_y%10); } } else // if >= 000 { acc_y_string[0] = ' '; acc_y_string[1] = '0'+((A_y/1000)%10); acc_y_string[2] = '0'+((A_y/100)%10); acc_y_string[3] = '0'+((A_y/10)%10); acc_y_string[4] = '0'+(A_y%10); } // A_z if( A_z < 0 ) { A_z = A_z * -1; if (A_z <1000) { acc_z_string[0] = ' '; if (A_z < 100) { acc_z_string[1] = ' '; if (A_z <10) { acc_z_string[2] = ' '; acc_z_string[3] = '-'; acc_z_string[4] = '0'+(A_z%10); } else // if >= 10 { acc_z_string[2] = '-'; acc_z_string[3] = '0'+((A_z/10)%10); acc_z_string[4] = '0'+(A_z%10); } } else // if >= 100 { acc_z_string[1] = '-'; acc_z_string[2] = '0'+((A_z/100)%10); acc_z_string[3] = '0'+((A_z/10)%10); acc_z_string[4] = '0'+(A_z%10); } } else // if >= 1000 { acc_z_string[0] = '-'; acc_z_string[1] = '0'+((A_z/1000)%10); acc_z_string[2] = '0'+((A_z/100)%10); acc_z_string[3] = '0'+((A_z/10)%10); acc_z_string[4] = '0'+(A_z%10); } } else // if >= 000 { acc_z_string[0] = ' '; acc_z_string[1] = '0'+((A_z/1000)%10); acc_z_string[2] = '0'+((A_z/100)%10); acc_z_string[3] = '0'+((A_z/10)%10); acc_z_string[4] = '0'+(A_z%10); } // P p_string[0] = '0'+((P/100000)%10); p_string[1] = '0'+((P/10000)%10); p_string[2] = '0'+((P/1000)%10); p_string[3] = '0'+((P/100)%10); p_string[5] = '0'+((P/10)%10); p_string[6] = '0'+(P%10); // Vpd vpd_string[0] = '0'+((Vpd/1000)%10); vpd_string[1] = '0'+((Vpd/100)%10); vpd_string[2] = '0'+((Vpd/10)%10); vpd_string[3] = '0'+(Vpd%10); // Status for (i=8; i>0; i--) { status_string[i-1] = '0' + msg_status%2; msg_status = msg_status/2; } // CREATE OUTPUT j=0; // ID j += 3; for (i = 0; i<sizeof(id_string)-1; i++) { output[i+j] = id_string[i]; } j += i; j += 1; // Vcc= j += 4; for (i = 0; i<sizeof(vcc_string)-1; i++) { output[i+j] = vcc_string[i]; } j += i; j += 1; // T= j += 2; for (i = 0; i<sizeof(t_string)-1; i++) { output[i+j] = t_string[i]; } j += i; j += 1; // RH= j += 3; for (i = 0; i<sizeof(rh_string)-1; i++) { output[i+j] = rh_string[i]; } j += i; j += 1; // Acc_x= j += 6; for (i = 0; i<sizeof(acc_x_string)-1; i++) { output[i+j] = acc_x_string[i]; } j += i; j += 1; // Acc_y= j += 6; for (i = 0; i<sizeof(acc_y_string)-1; i++) { output[i+j] = acc_y_string[i]; } j += i; j += 1; // Acc_z= j += 6; for (i = 0; i<sizeof(acc_z_string)-1; i++) { output[i+j] = acc_z_string[i]; } j += i; j += 1; // P= j += 2; for (i = 0; i<sizeof(p_string)-1; i++) { output[i+j] = p_string[i]; } j += i; j += 1; // Vpd j += 4; for (i = 0; i<sizeof(vpd_string)-1; i++) { output[i+j] = vpd_string[i]; } j += i; j += 1; // Status j += 7; for (i = 0; i<sizeof(status_string)-1; i++) { output[i+j] = status_string[i]; } j += i; j += 1; TXString(output, sizeof output); // TXString(msg, sizeof msg); }