static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { int16_t sensor_value = temperature_sensor.value(0); unsigned int accept = -1; REST.get_header_accept(request, &accept); if(accept == -1 || accept == REST.type.TEXT_PLAIN) { REST.set_header_content_type(response, REST.type.TEXT_PLAIN); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d.%d", sensor_value/10, ABS_VALUE(sensor_value)%10); REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); } else if(accept == REST.type.APPLICATION_XML) { REST.set_header_content_type(response, REST.type.APPLICATION_XML); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "<Temperature =\"%d.%d\" />", sensor_value/10, ABS_VALUE(sensor_value)%10); REST.set_response_payload(response, buffer, strlen((char *)buffer)); } else if(accept == REST.type.APPLICATION_JSON) { REST.set_header_content_type(response, REST.type.APPLICATION_JSON); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'st-temp':{'Temperature':%d.%d}}", sensor_value/10, ABS_VALUE(sensor_value)%10); REST.set_response_payload(response, buffer, strlen((char *)buffer)); } else { REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); const char *msg = "Supporting content-types text/plain, application/xml, and application/json"; REST.set_response_payload(response, msg, strlen(msg)); } }
/** * Return the 2-norm of the vector.(block version) * * @param self A vector object. * @param value The 2-norm returned. * * @return 0 on success. */ int parms_VecGetNorm2_b(FLOAT *self, REAL *value, parms_Map is) { if (is->isserial) { #ifdef HAS_BLAS int llsize = parms_MapGetLocallSize(is); int incr = 1; *value = GNRM2(llsize, self, incr); //printf("after GNRM2"); #else FLOAT dot; vec_LDotc_b(self, self, &dot, is); *value = ABS_VALUE(dot); *value = sqrt(*value); #endif } else { REAL dot; #if defined(DBL_CMPLX) parms_VecDOTC_b(self, self, &dot, is); #else parms_VecDOT_b(self, self, &dot, is); #endif *value = fabs(dot); *value = sqrt(*value); } return 0; }
int qsplitC(FLOAT *a, int *ind, int n, int ncut) { /*---------------------------------------------------------------------- | does a quick-sort split of a complex real array. | on input a[0 : (n-1)] is a real array | on output is permuted such that its elements satisfy: | | abs(a[i]) >= abs(a[ncut-1]) for i < ncut-1 and | abs(a[i]) <= abs(a[ncut-1]) for i > ncut-1 | | ind[0 : (n-1)] is an integer array permuted in the same way as a. |---------------------------------------------------------------------*/ FLOAT tmp; double abskey; int j, itmp, first, mid, last; first = 0; last = n-1; if (ncut<first || ncut>last) return 0; /* outer loop -- while mid != ncut */ label1: mid = first; abskey = ABS_VALUE(a[mid]); for (j=first+1; j<=last; j++) { if (ABS_VALUE(a[j]) > abskey) { tmp = a[++mid]; itmp = ind[mid]; a[mid] = a[j]; ind[mid] = ind[j]; a[j] = tmp; ind[j] = itmp; } } /*-------------------- interchange */ tmp = a[mid]; a[mid] = a[first]; a[first] = tmp; itmp = ind[mid]; ind[mid] = ind[first]; ind[first] = itmp; /*-------------------- test for while loop */ if (mid == ncut) return 0; if (mid > ncut) last = mid-1; else first = mid+1; goto label1; }
void qsort2C(int *ja, FLOAT *ma, int left, int right, int abval){ /*---------------------------------------------------------------------- | | qqsort: sort ma[left]...ma[right] into increasing order | from Kernighan & Ritchie | | ja holds the column indices | abval = 1: consider absolute values | 0: values | |---------------------------------------------------------------------*/ int i, last; if (left >= right) return; if (abval) { swapj(ja, left, (left+right)/2); swapm(ma, left, (left+right)/2); last = left; for (i=left+1; i<=right; i++) { if (ABS_VALUE(ma[i]) < ABS_VALUE(ma[left])) { swapj(ja, ++last, i); swapm(ma, last, i); } } swapj(ja, left, last); swapm(ma, left, last); qsort2C(ja, ma, left, last-1, abval); qsort2C(ja, ma, last+1, right, abval); } else { swapj(ja, left, (left+right)/2); swapm(ma, left, (left+right)/2); last = left; for (i=left+1; i<=right; i++) { if (ABS_VALUE(ma[i]) < ABS_VALUE(ma[left])) { swapj(ja, ++last, i); swapm(ma, last, i); } } swapj(ja, left, last); swapm(ma, left, last); qsort2C(ja, ma, left, last-1, abval); qsort2C(ja, ma, last+1, right, abval); } }
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { size_t len = 0; const char *p = NULL; uint8_t param = 0; int success = 1; volatile int sensor_value = 0; unsigned int accept = -1; REST.get_header_accept(request, &accept); if((len = REST.get_query_variable(request, "p", &p))) { if(strncmp(p, "lqi", len) == 0) { param = RADIO_SENSOR_LAST_VALUE; } else if(strncmp(p, "rssi", len) == 0) { param = RADIO_SENSOR_LAST_PACKET; } else { success = 0; } } else { success = 0; } if(success) { sensor_value = radio_sensor.value(param); if(accept == -1 || accept == REST.type.TEXT_PLAIN) { REST.set_header_content_type(response, REST.type.TEXT_PLAIN); if(param == RADIO_SENSOR_LAST_VALUE) { snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", sensor_value); } else if(param == RADIO_SENSOR_LAST_PACKET) { snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d.%d", sensor_value/10, ABS_VALUE(sensor_value)%10); } REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); } else if(accept == REST.type.APPLICATION_JSON) { REST.set_header_content_type(response, REST.type.APPLICATION_JSON); if(param == RADIO_SENSOR_LAST_VALUE) { snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'lqi':%d}", sensor_value); } else if(param == RADIO_SENSOR_LAST_PACKET) { snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d.%d}", sensor_value/10, ABS_VALUE(sensor_value)%10); } REST.set_response_payload(response, buffer, strlen((char *)buffer)); } else { REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); const char *msg = "Supporting content-types text/plain and application/json"; REST.set_response_payload(response, msg, strlen(msg)); } } else { REST.set_response_status(response, REST.status.BAD_REQUEST); } }
int roscalC(csptr mata, double *diag, int nrm) { /*--------------------------------------------------------------------- | | This routine scales each row of mata so that the norm is 1. | |---------------------------------------------------------------------- | on entry: | mata = the matrix (in SparRow form) | nrm = type of norm | 0 (\infty), 1 or 2 | | on return | diag = diag[j] = 1/norm(row[j]) | | 0 --> normal return | j --> row j is a zero row |--------------------------------------------------------------------*/ /* local variables */ int i, k; FLOAT *kr; double scal; for (i=0; i<mata->n; i++) { scal = 0.0; kr = mata->pa[i]; if (nrm == 0) { for (k=0; k<mata->nnzrow[i]; k++) if (ABS_VALUE(kr[k]) > fabs(scal)) scal = ABS_VALUE(kr[k]); } else if (nrm == 1) { for (k=0; k<mata->nnzrow[i]; k++) scal += ABS_VALUE(kr[k]); } else { /* nrm = 2 */ for (k=0; k<mata->nnzrow[i]; k++) scal += ABS_VALUE(kr[k]*kr[k]); } if (nrm == 2) scal = sqrt(scal); if(ABS_VALUE(scal-DBL_EPSILON) <= DBL_EPSILON*ABS_VALUE(scal)){ scal = 1.0; /* YS. return i+1; */ } else scal = 1.0 / scal; diag[i] = scal; for (k=0; k<mata->nnzrow[i]; k++) kr[k] = kr[k] * scal; } return 0; }
mlib_status __mlib_VectorSumAbsDiff_S16_Sat( mlib_d64 *z, const mlib_s16 *x, const mlib_s16 *y, mlib_s32 n) { if (n <= 0) return (MLIB_FAILURE); mlib_s32 i, nstep, ax, ay, n1, n2, n3, xval, sum = 0; mlib_s16 *px = (mlib_s16 *)x, *py = (mlib_s16 *)y; __m128i zero, xbuf, ybuf, zbuf32, zbuf64, xlo, xhi, mext; zero = _mm_setzero_si128(); zbuf64 = zero; nstep = 16 / sizeof (mlib_s16); ax = (mlib_addr)x & 15; ay = (mlib_addr)y & 15; n1 = ((16 - ax) & 15) / sizeof (mlib_s16); n2 = (n - n1) / nstep; n3 = n - n1 - n2 * nstep; if (n2 < 1) { for (i = 0; i < n; i++) { xval = (mlib_s32)(*px++) - (*py++); sum += ABS_VALUE(xval); } *z = sum; } else { for (i = 0; i < n1; i++) { xval = (mlib_s32)(*px++) - (*py++); sum += ABS_VALUE(xval); } mlib_s32 nblock = n2 >> 12; mlib_s32 tail = n2 & 4095; mlib_s32 k; if (ax == ay) { for (k = 0; k < nblock; k++) { zbuf32 = zero; for (i = 0; i < 4096; i++) { xbuf = _mm_load_si128((__m128i *)px); ybuf = _mm_load_si128((__m128i *)py); mext = _mm_cmpgt_epi16(ybuf, xbuf); xbuf = _mm_sub_epi16(xbuf, ybuf); xbuf = _mm_xor_si128(xbuf, mext); xbuf = _mm_sub_epi16(xbuf, mext); xlo = _mm_unpacklo_epi16(xbuf, zero); xhi = _mm_unpackhi_epi16(xbuf, zero); zbuf32 = _mm_add_epi32(zbuf32, xlo); zbuf32 = _mm_add_epi32(zbuf32, xhi); px += nstep; py += nstep; } xlo = _mm_unpacklo_epi32(zbuf32, zero); xhi = _mm_unpackhi_epi32(zbuf32, zero); zbuf64 = _mm_add_epi64(zbuf64, xlo); zbuf64 = _mm_add_epi64(zbuf64, xhi); } zbuf32 = zero; for (i = 0; i < tail; i++) { xbuf = _mm_load_si128((__m128i *)px); ybuf = _mm_load_si128((__m128i *)py); mext = _mm_cmpgt_epi16(ybuf, xbuf); xbuf = _mm_sub_epi16(xbuf, ybuf); xbuf = _mm_xor_si128(xbuf, mext); xbuf = _mm_sub_epi16(xbuf, mext); xlo = _mm_unpacklo_epi16(xbuf, zero); xhi = _mm_unpackhi_epi16(xbuf, zero); zbuf32 = _mm_add_epi32(zbuf32, xlo); zbuf32 = _mm_add_epi32(zbuf32, xhi); px += nstep; py += nstep; } xlo = _mm_unpacklo_epi32(zbuf32, zero); xhi = _mm_unpackhi_epi32(zbuf32, zero); zbuf64 = _mm_add_epi64(zbuf64, xlo); zbuf64 = _mm_add_epi64(zbuf64, xhi); } else { /* not aligned */ for (k = 0; k < nblock; k++) { zbuf32 = zero; for (i = 0; i < 4096; i++) { xbuf = _mm_load_si128((__m128i *)px); ybuf = _mm_loadu_si128((__m128i *)py); mext = _mm_cmpgt_epi16(ybuf, xbuf); xbuf = _mm_sub_epi16(xbuf, ybuf); xbuf = _mm_xor_si128(xbuf, mext); xbuf = _mm_sub_epi16(xbuf, mext); xlo = _mm_unpacklo_epi16(xbuf, zero); xhi = _mm_unpackhi_epi16(xbuf, zero); zbuf32 = _mm_add_epi32(zbuf32, xlo); zbuf32 = _mm_add_epi32(zbuf32, xhi); px += nstep; py += nstep; } xlo = _mm_unpacklo_epi32(zbuf32, zero); xhi = _mm_unpackhi_epi32(zbuf32, zero); zbuf64 = _mm_add_epi64(zbuf64, xlo); zbuf64 = _mm_add_epi64(zbuf64, xhi); } zbuf32 = zero; for (i = 0; i < tail; i++) { xbuf = _mm_load_si128((__m128i *)px); ybuf = _mm_loadu_si128((__m128i *)py); mext = _mm_cmpgt_epi16(ybuf, xbuf); xbuf = _mm_sub_epi16(xbuf, ybuf); xbuf = _mm_xor_si128(xbuf, mext); xbuf = _mm_sub_epi16(xbuf, mext); xlo = _mm_unpacklo_epi16(xbuf, zero); xhi = _mm_unpackhi_epi16(xbuf, zero); zbuf32 = _mm_add_epi32(zbuf32, xlo); zbuf32 = _mm_add_epi32(zbuf32, xhi); px += nstep; py += nstep; } xlo = _mm_unpacklo_epi32(zbuf32, zero); xhi = _mm_unpackhi_epi32(zbuf32, zero); zbuf64 = _mm_add_epi64(zbuf64, xlo); zbuf64 = _mm_add_epi64(zbuf64, xhi); } for (i = 0; i < n3; i++) { xval = (mlib_s32)(*px++) - (*py++); sum += ABS_VALUE(xval); } mlib_d64 dsum = sum; long long pz[2]; _mm_storeu_si128((__m128i *)pz, zbuf64); dsum += pz[0]; dsum += pz[1]; *z = dsum; } return (MLIB_SUCCESS); }
mlib_status __mlib_VectorSumAbsDiff_S8_Sat( mlib_d64 *z, const mlib_s8 *x, const mlib_s8 *y, mlib_s32 n) { if (n <= 0) return (MLIB_FAILURE); mlib_s32 i, nstep, ax, ay, n1, n2, n3, diff, sum = 0; mlib_s8 *px = (mlib_s8 *)x, *py = (mlib_s8 *)y; __m128i zero, xbuf, ybuf, zbuf, mext, mbuf; zero = _mm_setzero_si128(); zbuf = zero; nstep = 16 / sizeof (mlib_s8); ax = (mlib_addr)x & 15; ay = (mlib_addr)y & 15; n1 = ((16 - ax) & 15) / sizeof (mlib_s8); n2 = (n - n1) / nstep; n3 = n - n1 - n2 * nstep; if (n2 < 1) { for (i = 0; i < n; i++) { diff = (mlib_s32)(*px++) - (*py++); sum += ABS_VALUE(diff); } *z = sum; } else { for (i = 0; i < n1; i++) { diff = (mlib_s32)(*px++) - (*py++); sum += ABS_VALUE(diff); } if (ax == ay) { for (i = 0; i < n2; i++) { xbuf = _mm_load_si128((__m128i *)px); ybuf = _mm_load_si128((__m128i *)py); mext = _mm_cmpgt_epi8(ybuf, xbuf); mbuf = _mm_sub_epi8(xbuf, ybuf); mbuf = _mm_xor_si128(mbuf, mext); mbuf = _mm_sub_epi8(mbuf, mext); mbuf = _mm_sad_epu8(mbuf, zero); zbuf = _mm_add_epi64(zbuf, mbuf); px += nstep; py += nstep; } } else { for (i = 0; i < n2; i++) { xbuf = _mm_load_si128((__m128i *)px); ybuf = _mm_loadu_si128((__m128i *)py); mext = _mm_cmpgt_epi8(ybuf, xbuf); mbuf = _mm_sub_epi8(xbuf, ybuf); mbuf = _mm_xor_si128(mbuf, mext); mbuf = _mm_sub_epi8(mbuf, mext); mbuf = _mm_sad_epu8(mbuf, zero); zbuf = _mm_add_epi64(zbuf, mbuf); px += nstep; py += nstep; } } for (i = 0; i < n3; i++) { diff = (mlib_s32)(*px++) - (*py++); sum += ABS_VALUE(diff); } mlib_d64 dsum = sum; long long pz[2]; _mm_storeu_si128((__m128i *)pz, zbuf); dsum += pz[0]; dsum += pz[1]; *z = dsum; } return (MLIB_SUCCESS); }
/*---------------end of roscalC----------------------------------------- ----------------------------------------------------------------------*/ int coscalC(csptr mata, double *diag, int nrm) { /*--------------------------------------------------------------------- | | This routine scales each column of mata so that the norm is 1. | |---------------------------------------------------------------------- | on entry: | mata = the matrix (in SparRow form) | nrm = type of norm | 0 (\infty), 1 or 2 | | on return | diag = diag[j] = 1/norm(row[j]) | | 0 --> normal return | j --> column j is a zero column |--------------------------------------------------------------------*/ /* local variables */ int i, j, k; FLOAT *kr; int *ki; for (i=0; i<mata->n; i++) diag[i] = 0.0; /*--------------------------------------- | compute the norm of each column |--------------------------------------*/ for (i=0; i<mata->n; i++) { kr = mata->pa[i]; ki = mata->pj[i]; if (nrm == 0) { for (k=0; k<mata->nnzrow[i]; k++) { j = ki[k]; if (ABS_VALUE(kr[k]) > diag[j]) diag[j] = ABS_VALUE(kr[k]); } } else if (nrm == 1) { for (k=0; k<mata->nnzrow[i]; k++) diag[ki[k]] += ABS_VALUE(kr[k]); } else { /* nrm = 2 */ for (k=0; k<mata->nnzrow[i]; k++) diag[ki[k]] += ABS_VALUE(kr[k]*kr[k]); } } if (nrm == 2) { for (i=0; i<mata->n; i++) diag[i] = sqrt(diag[i]); } /*--------------------------------------- | invert |--------------------------------------*/ for (i=0; i<mata->n; i++) { if(ABS_VALUE(diag[i]-DBL_EPSILON) <= DBL_EPSILON*ABS_VALUE(diag[i])) /* return i+1;*/ diag[i] = 1.0; else diag[i] = 1.0 / diag[i]; } /*--------------------------------------- | C = A * D |--------------------------------------*/ for (i=0; i<mata->n; i++) { kr = mata->pa[i]; ki = mata->pj[i]; for (k=0; k<mata->nnzrow[i]; k++) kr[k] = kr[k] * diag[ki[k]]; } return 0; }
NTSTATUS CmiAddValueKey( IN PCMHIVE RegistryHive, IN PCM_KEY_NODE KeyCell, IN HCELL_INDEX KeyCellOffset, IN PCUNICODE_STRING ValueName, OUT PCM_KEY_VALUE *pValueCell, OUT HCELL_INDEX *pValueCellOffset) { PVALUE_LIST_CELL ValueListCell; PCM_KEY_VALUE NewValueCell; HCELL_INDEX ValueListCellOffset; HCELL_INDEX NewValueCellOffset; ULONG CellSize; HSTORAGE_TYPE Storage; NTSTATUS Status; Storage = (KeyCell->Flags & KEY_IS_VOLATILE) ? Volatile : Stable; if (KeyCell->ValueList.List == HCELL_NIL) { /* Allocate some room for the value list */ CellSize = sizeof(VALUE_LIST_CELL) + (3 * sizeof(HCELL_INDEX)); ValueListCellOffset = HvAllocateCell(&RegistryHive->Hive, CellSize, Storage, HCELL_NIL); if (ValueListCellOffset == HCELL_NIL) return STATUS_INSUFFICIENT_RESOURCES; ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, ValueListCellOffset); if (!ValueListCell) return STATUS_UNSUCCESSFUL; KeyCell->ValueList.List = ValueListCellOffset; HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); } else { ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, KeyCell->ValueList.List); if (!ValueListCell) return STATUS_UNSUCCESSFUL; CellSize = ABS_VALUE(HvGetCellSize(&RegistryHive->Hive, ValueListCell)); if (KeyCell->ValueList.Count >= CellSize / sizeof(HCELL_INDEX)) { CellSize *= 2; ValueListCellOffset = HvReallocateCell(&RegistryHive->Hive, KeyCell->ValueList.List, CellSize); if (ValueListCellOffset == HCELL_NIL) return STATUS_INSUFFICIENT_RESOURCES; ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, ValueListCellOffset); if (!ValueListCell) return STATUS_UNSUCCESSFUL; KeyCell->ValueList.List = ValueListCellOffset; HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); } } Status = CmiAllocateValueCell( RegistryHive, &NewValueCell, &NewValueCellOffset, ValueName, Storage); if (!NT_SUCCESS(Status)) return Status; ValueListCell->ValueOffset[KeyCell->ValueList.Count] = NewValueCellOffset; KeyCell->ValueList.Count++; if (NewValueCell->Flags & VALUE_COMP_NAME) { if (NewValueCell->NameLength*sizeof(WCHAR) > KeyCell->MaxValueNameLen) KeyCell->MaxValueNameLen = NewValueCell->NameLength*sizeof(WCHAR); } else { if (NewValueCell->NameLength > KeyCell->MaxValueNameLen) KeyCell->MaxValueNameLen = NewValueCell->NameLength; } HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); HvMarkCellDirty(&RegistryHive->Hive, KeyCell->ValueList.List, FALSE); HvMarkCellDirty(&RegistryHive->Hive, NewValueCellOffset, FALSE); *pValueCell = NewValueCell; *pValueCellOffset = NewValueCellOffset; return STATUS_SUCCESS; }
mlib_status mlib_ImageAbs_S32( mlib_s32 *dst, mlib_s32 *src, mlib_s32 dlb, mlib_s32 slb, mlib_s32 wid, mlib_s32 hgt) { /* 8-byte aligned src, dst ptrs */ mlib_d64 *sp, *dp; /* unaligned data */ mlib_d64 prev; mlib_d64 curr0; /* aligned data */ mlib_d64 adat0; /* absolute values of result */ mlib_d64 dabs; mlib_f32 ftwo = vis_to_float(0x2020202); mlib_d64 mask = vis_to_double_dup(0x80008000); /* pxl count of source line */ mlib_s32 slpxl = slb >> 2; /* pxl count of destination line */ mlib_s32 dlpxl = dlb >> 2; mlib_s32 row, block; mlib_s32 pxl0, pxl1; mlib_s64 ll; vis_write_gsr(7 << 3); for (row = 0; row < hgt; row++) { /* ROW SETUP */ block = 0; if ((mlib_addr)dst & 7) { dst[0] = ABS_VALUE(src[0]); block = 1; } /* aligned src ptr */ sp = (mlib_d64 *)vis_alignaddr(src, 4 * block); dp = (mlib_d64 *)(dst + block); /* DO MOST OF ROW IN BLOCKS OF N d64s */ if ((((mlib_addr)src ^ (mlib_addr)dst) & 7) == 0) { #pragma pipeloop(0) for (; block <= (wid - 4); block += 4) { READ_PXLS_ALIGN; ll = ((mlib_s64 *)sp)[0]; pxl0 = (mlib_s32)(ll >> 32); pxl1 = (mlib_s32)ll; sp++; CALC_ABS_S32; STORE_ABS_VALUES; ((mlib_s32 *)dp)[0] = (mlib_s32)ABS_VALUE(pxl0); ((mlib_s32 *)dp)[1] = (mlib_s32)ABS_VALUE(pxl1); dp++; } } else { #pragma pipeloop(0) for (; block <= (wid - 4); block += 4) { READ_PXLS_UNALIGN_S32; pxl0 = ((mlib_s32 *)sp)[1]; pxl1 = ((mlib_s32 *)sp)[2]; sp++; CALC_ABS_S32; STORE_ABS_VALUES; ((mlib_s32 *)dp)[0] = (mlib_s32)ABS_VALUE(pxl0); ((mlib_s32 *)dp)[1] = (mlib_s32)ABS_VALUE(pxl1); dp++; } } for (; block < wid; block++) { pxl0 = ((mlib_s32 *)src)[block]; ((mlib_s32 *)dst)[block] = (mlib_s32)ABS_VALUE(pxl0); } /* ptrs to next src row */ src += slpxl; /* ptrs to next dst row */ dst += dlpxl; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(unicast_sender_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; uip_ipaddr_t *addr; static int sensor_value = 0; PROCESS_BEGIN(); SENSORS_ACTIVATE(button_sensor); SENSORS_ACTIVATE(radio_sensor); #ifdef X_NUCLEO_IKS01A1 SENSORS_ACTIVATE(temperature_sensor); SENSORS_ACTIVATE(humidity_sensor); SENSORS_ACTIVATE(pressure_sensor); SENSORS_ACTIVATE(magneto_sensor); SENSORS_ACTIVATE(acceleration_sensor); SENSORS_ACTIVATE(gyroscope_sensor); #endif /*X_NUCLEO_IKS01A1*/ servreg_hack_init(); set_global_address(); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); etimer_set(&periodic_timer, SEND_INTERVAL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); etimer_reset(&periodic_timer); etimer_set(&send_timer, SEND_TIME); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer)); addr = servreg_hack_lookup(SERVICE_ID); if(addr != NULL) { static unsigned int message_number = 0; char buf[40]; printf("Sending unicast to "); uip_debug_ipaddr_print(addr); printf("\n"); #ifdef X_NUCLEO_IKS01A1 switch(message_number) { case 0: sensor_value = temperature_sensor.value(0); sprintf(buf, "Temperature:\t%d.%d C", sensor_value/10, ABS_VALUE(sensor_value)%10); break; case 1: sprintf(buf, "Humidity:\t%d.%d rH", humidity_sensor.value(0)/10, humidity_sensor.value(0)%10); break; case 2: sprintf(buf, "Pressure:\t%d.%d mbar", pressure_sensor.value(0)/10, pressure_sensor.value(0)%10); break; case 3: sprintf(buf, "Magneto:\t\t%d/%d/%d (X/Y/Z) mgauss", magneto_sensor.value(X_AXIS), magneto_sensor.value(Y_AXIS), magneto_sensor.value(Z_AXIS)); break; case 4: sprintf(buf, "Acceleration:\t%d/%d/%d (X/Y/Z) mg", acceleration_sensor.value(X_AXIS), acceleration_sensor.value(Y_AXIS), acceleration_sensor.value(Z_AXIS)); break; case 5: sprintf(buf, "Gyroscope:\t%d/%d/%d (X/Y/Z) mdps", gyroscope_sensor.value(X_AXIS), gyroscope_sensor.value(Y_AXIS), gyroscope_sensor.value(Z_AXIS)); break; case 6: sensor_value = radio_sensor.value(RADIO_SENSOR_LAST_PACKET); sprintf(buf, "Radio (RSSI):\t%d.%d dBm", sensor_value/10, ABS_VALUE(sensor_value)%10); break; case 7: sprintf(buf, "Radio (LQI):\t%d", radio_sensor.value(RADIO_SENSOR_LAST_VALUE)); break; default: break; } simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr); message_number++; if(message_number > 7) { message_number = 0; } #endif /*X_NUCLEO_IKS01A1*/ } else { printf("Service %d not found\n", SERVICE_ID); } } PROCESS_END(); }