U8 logic_radioMeterAddr(U8* meterAddr, flow_err_string_ptr pError) { db_mFrame_str dbFrameStr = { 0 }; meter_frame_info_str protoStr = { 0 }; flow_error_str flowErrFloatStr = { 0 }; U32 infoIdx = 0; U8 buf[FRAME_MAX_LEN] = { 0 }; U16 bufSize = 0; printBuf(NULL, 0, FILE_LINE); db_getCongfig(config_meter_type, (U8*)&infoIdx); if (db_getFrameInfo(infoIdx, &dbFrameStr) == ERROR) { printBuf(NULL, 0, FILE_LINE); return ERROR; } printBuf(NULL, 0, FILE_LINE); dbFrameToProto(&dbFrameStr, &protoStr); protoR_radioMAddr(buf, &bufSize, &protoStr); printBuf(buf, bufSize, FILE_LINE); if (logic_sendAndRead(buf, &bufSize, UART_WAIT_SHORT) == ERROR) { Lib_printf("no response from device\n"); return ERROR; } printBuf(buf, bufSize, FILE_LINE); if (protoA_meterAddr(buf, bufSize, &protoStr, &gOldCoe) == ERROR) { return ERROR; } binAddrToStr(protoStr.meterAddr, meterAddr); coeToErr(&gOldCoe, &flowErrFloatStr); binErrToStr(&flowErrFloatStr, pError); return NO_ERR; }
int main(int argc, char** argv) { tempControl_messure_hisdata_str hisDataStr[30] = { {0} }; hisdata_head_str BodyHeadStr; U8 lu8data = 0; U8 buf[2048] = { 0 }; U16 bufSize = 0, i = 0; U16 hisDataCnt = sizeof(hisDataStr) / sizeof(tempControl_messure_hisdata_str); U8 lu8gatewayId[] = { 0x17, 0x90, 0x00, 0x00, 0x00, 0x00 }; U8 readBuf[] = { 0xFB, 0xFB, 0x7B, 0x03, 0x17, 0x90, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x07, 0x15, 0x29, 0x17, 0x25, 0x07, 0x16, 0x63, 0x04, 0x00, 0x20, 0x62, 0x49, 0x16, 0x21, 0x00, 0x11, 0x11, 0x04, 0x02, 0x50, 0x04, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x35, 0x61, 0x00, 0x00, 0x00, 0x2C, 0x73, 0x25, 0x00, 0x27, 0x26, 0x00, 0x61, 0x66, 0x01, 0x17, 0x10, 0x18, 0x23, 0x07, 0x16, 0x20, 0x00, 0x00, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0x7A, 0xFD, 0xFD }; U16 readBufSize = sizeof(readBuf); U16 MeterId = 4; protoX_readOneMeter(buf, &bufSize, lu8gatewayId, &MeterId); printBuf(buf, bufSize, FILE_LINE); lu8data = protoA_readOneMeter(readBuf, readBufSize, &(hisDataStr[0])); printf("lu8data: %d\n", lu8data); printBuf((U8*)&(hisDataStr[0]), sizeof(tempControl_messure_hisdata_str), FILE_LINE); printf("AA: %02X\n", strtol("AA", NULL, 16)); return 0; }
dn_error_t cli_ccm1CmdHandler(const char* arg, INT32U len) { dn_error_t dnErr; dn_sec_ccmopt_t dn_sec_ccmopt; INT8U aBuf[sizeof(ccm1_a)]; dnm_ucli_printf("Test vector from \"C.2.1 MAC beacon frame\"\r\n"); // Size of CCM authentication field (MIC); range: 4-16. dn_sec_ccmopt.M = 8; // Size of CCM length field; range: 2-8. dn_sec_ccmopt.L = 2; // buffer to authenticate only memcpy(aBuf, &ccm1_a, sizeof(ccm1_a)); // key memcpy(security_app_vars.key, &security_key, sizeof(security_key)); // nonce/initialization vector memcpy(security_app_vars.iv, &ccm1_nonce, sizeof(ccm1_nonce)); // print dnm_ucli_printf("params:\r\n"); dnm_ucli_printf(" - M: %d\r\n",dn_sec_ccmopt.M); dnm_ucli_printf(" - L: %d\r\n",dn_sec_ccmopt.L); dnm_ucli_printf(" - key: "); printBuf(security_app_vars.key, sizeof(security_app_vars.key)); dnm_ucli_printf(" - nonce: "); printBuf(security_app_vars.iv, sizeof(security_app_vars.iv)); // print dnm_ucli_printf("input:\r\n"); dnm_ucli_printf(" - aBuf: "); printBuf(aBuf, sizeof(aBuf)); // encrypt and authenticate dnErr = dn_sec_aesCcmEncrypt( &dn_sec_ccmopt, // opt aBuf, // aBuf sizeof(aBuf), // aLen NULL, // mBuf 0, // mLen security_app_vars.key, // key security_app_vars.iv, // nonce security_app_vars.mic // mic ); ASSERT(dnErr==DN_ERR_NONE); // print dnm_ucli_printf("output:\r\n"); dnm_ucli_printf(" - aBuf: "); printBuf(aBuf, sizeof(aBuf)); dnm_ucli_printf(" - mic: "); printBuf(security_app_vars.mic, 8); return DN_ERR_NONE; }
dn_error_t cli_ctrCmdHandler(const char* arg, INT32U len) { dn_error_t dnErr; // prepare paramaters memcpy(security_app_vars.inBuf, &security_inBuf, 16); memcpy(security_app_vars.key, &security_key, 16); memset(security_app_vars.iv, 0, 16); // print dnm_ucli_printf("params:\r\n"); dnm_ucli_printf(" - key: "); printBuf(security_app_vars.key, sizeof(security_app_vars.key)); dnm_ucli_printf(" - iv: "); printBuf(security_app_vars.iv, sizeof(security_app_vars.iv)); // print dnm_ucli_printf("input:\r\n"); dnm_ucli_printf(" - plaintext: "); printBuf(security_app_vars.inBuf, sizeof(security_app_vars.inBuf)); // encrypt dnErr = dn_sec_aesCtr( security_app_vars.inBuf, // inBuf security_app_vars.outBuf, // outBuf sizeof(security_app_vars.inBuf), // len security_app_vars.key, // key security_app_vars.iv // iv ); ASSERT(dnErr==DN_ERR_NONE); // print dnm_ucli_printf("output:\r\n"); dnm_ucli_printf(" - ciphertext: "); printBuf(security_app_vars.outBuf, sizeof(security_app_vars.outBuf)); security_app_vars.outBuf[5] ^= 0x01; // decrypt (same operation as encrypt, inBuf and outBuf inverted) dnErr = dn_sec_aesCtr( security_app_vars.outBuf, // inBuf security_app_vars.inBuf, // outBuf sizeof(security_app_vars.inBuf), // len security_app_vars.key, // key security_app_vars.iv // iv ); ASSERT(dnErr==DN_ERR_NONE); // print dnm_ucli_printf("output:\r\n"); dnm_ucli_printf(" - decrypted: "); printBuf(security_app_vars.inBuf, sizeof(security_app_vars.inBuf)); return DN_ERR_NONE; }
int differ(char* d,char*s,size_t sz) { int i; for (i=0;i<sz;++i) if (d[i]!=s[i]) { printf("d[%p]:%x!=s[%p]:%x idx:%i\n",d+i,d[i],s+i,s[i],i); printBuf(d,sz); printf("\n"); printBuf(s,sz); return 1; } return 0; }
U8 logic_modifyCoe(U8* meterAddr, flow_err_string_ptr pError) { db_mFrame_str dbFrameStr = { 0 }; meter_frame_info_str protoStr = { 0 }; flow_error_str flowErrFloatStr = { 0 }; flow_coe_str flowCoeStr = { 0 }; U32 infoIdx = 0; U8 buf[FRAME_MAX_LEN] = { 0 }; U16 bufSize = 0; U8 lu8meterAddr[METER_ADDR_LEN] = { 0 }; db_getCongfig(config_meter_type, (U8*)&infoIdx); if (db_getFrameInfo(infoIdx, &dbFrameStr) == ERROR) { return ERROR; } dbFrameToProto(&dbFrameStr, &protoStr); inverseStrToBCD(meterAddr, 2 * METER_ADDR_LEN, lu8meterAddr, METER_ADDR_LEN); stringErrToBin(pError, &flowErrFloatStr); ErrTocoe(&gOldCoe, &flowErrFloatStr, &flowCoeStr); protoW_ModifyCoe(buf, &bufSize, lu8meterAddr, &protoStr, &flowCoeStr); printBuf(buf, bufSize, FILE_LINE); logic_sendAndRead(buf, &bufSize, UART_WAIT_SHORT); return NO_ERR; }
int main() { char c; char buf[MIN_PRINTABLE_LEN + 1]; buf[0] = '\0'; int i = 0; while ((c = getchar()) != EOF) { // New line - reset the counter and buffer. if (c == '\n') { if (i > MIN_PRINTABLE_LEN) putchar('\n'); i = 0; buf[0] = '\0'; continue; } // Not clear if this is a long line or not - save to buffer. if (i < MIN_PRINTABLE_LEN) { buf[i++] = c; buf[i] = '\0'; continue; } // This character is part of a long line, so we'll be printing. // Print the buffer up to this point. if (i == MIN_PRINTABLE_LEN) printBuf(buf); putchar(c); buf[0] = '\0'; i++; } }
void advertise(int udp , int senderId, int numLinks, int numFiles){ node* curr = routing.head; char* ptr; while( curr != NULL ){ routingEntry* re = (routingEntry*)curr->data; if (re->isNeighbor){ struct sockaddr_in cli_addr; struct hostent *h; if((h = gethostbyname(re->hostName))==NULL) { printf("error resolving host\n"); return; } memset(&cli_addr, '\0', sizeof(cli_addr)); cli_addr.sin_family = AF_INET; cli_addr.sin_addr.s_addr = *(in_addr_t *)h->h_addr; cli_addr.sin_port = htons(re->routingPort); char* sendBuf = createPacket(numLinks, numFiles); ptr = addHeader(sendBuf, '1', senderId, re->seqNumSend, numLinks, numFiles); printBuf(sendBuf, ptr-sendBuf+1); //printf("Header length is %ld\n", ptr-sendBuf+1); ptr = addNodeIds(ptr, senderId); printBuf(sendBuf, ptr-sendBuf+1); //printf("header + Nodes length is %ld\n", ptr-sendBuf+1); ptr = addFiles(ptr); int packetSize = ptr-sendBuf+1; printf("The packet length is %d\n",packetSize ); printBuf(sendBuf, packetSize); char* tmp = "ssdsds"; ssize_t sen; sen = sendto(udp, sendBuf,packetSize, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr)); //printf("Send to node %d on port %d\n", re->nodeId, re->routingPort); if(sen <= 0 ){ printf("This is really bad\n"); } } curr = curr->next; } }
static int insertRecord(NvDatabaseConnection* pxDatabaseConnection, SecureRecord* pxRecord) { ALOGV("insertRecord - Entry"); int ret = 0; if (pxRecord) { ALOGV("Record to insert: name = '%s'", pxRecord->_key); // Check if record is valid if (checkRecordCrypto(pxRecord)) { ALOGV("*** Record integrity & authenticity is valid !"); if (pxDatabaseConnection) { if (SQLITE_OK == openNvDatabase(pxDatabaseConnection)) { ret = (insertSecureRecord(pxDatabaseConnection->_pDatabase, pxRecord) == SQLITE_OK); ALOGV( "insertRecord - saved record to db with:"); ALOGV( "insertRecord - _key = %s", pxRecord->_key); printBuf("insertRecord - _keyId ", pxRecord->_keyId, AES_BLOCK_SIZE); printBuf("insertRecord - _contentKey ", pxRecord->_contentKey, pxRecord->_contentKeySize); ALOGV( "insertRecord - _contentKeySize = %d", pxRecord->_contentKeySize); printBuf("insertRecord - _tag ", pxRecord->_tag, pxRecord->_tagSize); ALOGV( "insertRecord - _tagSize = %d", pxRecord->_tagSize); closeNvDatabase(pxDatabaseConnection); } else { ALOGE("insertRecord - Couldn't open database"); } } } else { ALOGV("*** Record integrity & authenticity is NOT valid !"); } } ALOGV("insertRecord - Exit (%d)", ret); return ret; }
// return plus value if non critical error occur // return minus value if critical error occur // return -11 if socket closed static int controlSocketHandler(int efd) { ssize_t recv_len; struct msg_t msg_head; struct msg_t *msg; int res = 0; if (manager.connect_timeout_timerfd >= 0) { LOGI("release connect timeout timer\n"); close(manager.connect_timeout_timerfd); manager.connect_timeout_timerfd = -1; } // Receive header recv_len = recv(manager.host.control_socket, &msg_head, MSG_CMD_HDR_LEN, 0); // error or close request from host if (recv_len == -1 || recv_len == 0) { LOGW("error or close request from host. " "MSG_ID = 0x%08X; recv_len = %d\n", msg_head.id, recv_len); return -11; } else { if (msg_head.len > HOST_CTL_MSG_MAX_LEN) { LOGE("Too long message. size = %u\n", msg_head.len); recv_msg_tail(manager.host.control_socket, msg_head.len); sendACKToHost(msg_head.id, ERR_WRONG_MESSAGE_FORMAT, 0, 0); return -1; } msg = malloc(MSG_CMD_HDR_LEN + msg_head.len); if (!msg) { LOGE("Cannot alloc msg\n"); recv_msg_tail(manager.host.control_socket, msg_head.len); sendACKToHost(msg_head.id, ERR_WRONG_MESSAGE_FORMAT, 0, 0); return -1; } msg->id = msg_head.id; msg->len = msg_head.len; if (msg->len > 0) { // Receive payload (if exists) recv_len = recv(manager.host.control_socket, msg->payload, msg->len, MSG_WAITALL); if (recv_len == -1) { LOGE("error or close request from host. recv_len = %d\n", recv_len); free(msg); return -11; } } printBuf((char *)msg, MSG_CMD_HDR_LEN + msg->len); res = host_message_handler(msg); free(msg); } return res; }
void print_split_msg(struct split_ip_msg *msg) { int i; printf("src_addr: "); for (i = 0; i < 16; i++) printf("0x%x ", msg->hdr.ip6_src.s6_addr[i]); printf("\ndst_addr: "); for (i = 0; i < 16; i++) printf("0x%x ", msg->hdr.ip6_dst.s6_addr[i]); printf("\nplen: %i hlim: %i\n", ntohs(msg->hdr.plen), msg->hdr.hlim); printBuf(msg->data, msg->data_len); }
int printBuf_ln(void) { if((print_buf_size == 0) || (print_buf == NULL)) return; if(print_buf_size <= print_buf_len) { *(print_buf + print_buf_size - 1) = NULL; print_buf_len--; } return printBuf("\n"); }
static int getRecord(NvDatabaseConnection* pxDatabaseConnection, const char* pxKey, const uint8_t *pxKeyId, SecureRecord* pxRecord) { ALOGV("getRecord - Entry"); int ret = 0; if (pxDatabaseConnection && pxRecord) { if (SQLITE_OK == openNvDatabase(pxDatabaseConnection)) { selectSecureRecord(pxDatabaseConnection->_pDatabase, pxKey, pxKeyId, pxRecord); ALOGV( "getRecord - got record from db with:"); ALOGV( "getRecord - pxKey = %s", pxKey); printBuf("getRecord - pxKeyId", pxKeyId, AES_BLOCK_SIZE); ALOGV( "getRecord - result set is:"); ALOGV( "getRecord - _key = %s", pxRecord->_key); printBuf("getRecord - _keyId ", pxRecord->_keyId, AES_BLOCK_SIZE); printBuf("getRecord - _contentKey ", pxRecord->_contentKey, pxRecord->_contentKeySize); ALOGV( "getRecord - _contentKeySize = %d", pxRecord->_contentKeySize); printBuf("getRecord - _tag ", pxRecord->_tag, pxRecord->_tagSize); ALOGV( "getRecord - _tagSize = %d", pxRecord->_tagSize); ret = pxRecord->_tagSize + pxRecord->_contentKeySize; } else { ALOGV("getRecord - cannot open this connection (%p)", pxDatabaseConnection ); } closeNvDatabase(pxDatabaseConnection); } else { ALOGV("getRecord - bad db connection (%p) secure rec (%p)",pxDatabaseConnection, pxRecord ); } ALOGV("getRecord - Exit (%d)", ret); return ret; }
U8 logic_operValve(U8* valeAddr, U8 openClose) { U8 lu8valveAddr[METER_ADDR_LEN] = { 0 }; U8 buf[FRAME_MAX_LEN] = { 0 }; U16 bufSize = 0; supplementAddr(valeAddr); inverseStrToBCD(valeAddr, STRLEN(valeAddr), lu8valveAddr, METER_ADDR_LEN); if (vprotoX_operValue(buf, &bufSize, lu8valveAddr, openClose) == ERROR) { return ERROR; } printBuf(buf, bufSize, FILE_LINE); if (logic_sendAndRead(buf, &bufSize, UART_WAIT_SHORT) == ERROR) { return ERROR; } printBuf(buf, bufSize, FILE_LINE); if (vprotoA_operValue(buf, bufSize, openClose) == ERROR) { return ERROR; } return NO_ERR; }
U8 logic_readValve(U8* valeAddr, U8* roomTemp, U8* openTime) { U8 lu8valveAddr[METER_ADDR_LEN] = { 0 }; U8 buf[FRAME_MAX_LEN] = { 0 }; U16 bufSize = 0; vElsonic_asw_frame_str vFrameStr = { 0 }; vElsonic_vopen_frame_str vOpenTimeStr = { 0 }; supplementAddr(valeAddr); inverseStrToBCD(valeAddr, STRLEN(valeAddr), lu8valveAddr, METER_ADDR_LEN); //读取房间温度 if (vprotoR_readValue(buf, &bufSize, lu8valveAddr) == ERROR) { return ERROR; } printBuf(buf, bufSize, FILE_LINE); if (logic_sendAndRead(buf, &bufSize, UART_WAIT_SHORT) == ERROR) { return ERROR; } printBuf(buf, bufSize, FILE_LINE); vprotoA_readValue(buf, bufSize, &vFrameStr); Lib_sprintf((S8*)roomTemp, "%d C", vFrameStr.roomTemp); //读取开阀时间 if (vprotoR_readOpenTime(buf, &bufSize, lu8valveAddr) == ERROR) { return ERROR; } printBuf(buf, bufSize, FILE_LINE); if (logic_sendAndRead(buf, &bufSize, UART_WAIT_SHORT) == ERROR) { return ERROR; } printBuf(buf, bufSize, FILE_LINE); vprotoA_readOpenTime(buf, bufSize, &vOpenTimeStr); printBuf((U8*)&vOpenTimeStr, sizeof(vElsonic_vopen_frame_str), FILE_LINE); openTimeToStr(&vOpenTimeStr, openTime); return NO_ERR; }
U8 logic_modifyAddr(U8* oldMeterAddr, U8* newMeterAddr) { U8 buf[FRAME_MAX_LEN] = { 0 }; U16 bufSize = 0; U8 lu8oldMeterAddr[METER_ADDR_LEN] = { 0 }; U8 lu8newMeterAddr[METER_ADDR_LEN] = { 0 }; inverseStrToBCD(oldMeterAddr, 2 * METER_ADDR_LEN, lu8oldMeterAddr, METER_ADDR_LEN); inverseStrToBCD(newMeterAddr, 2 * METER_ADDR_LEN, lu8newMeterAddr, METER_ADDR_LEN); protoW_ModifyAddr(buf, &bufSize, lu8oldMeterAddr, lu8newMeterAddr); printBuf(buf, bufSize, FILE_LINE); logic_sendAndRead(buf, &bufSize, UART_WAIT_SHORT); return NO_ERR; }
dn_error_t cli_cbcCmdHandler(const char* arg, INT32U len) { dn_error_t dnErr; // prepare paramaters memcpy(security_app_vars.inBuf, &security_inBuf, 16); memcpy(security_app_vars.key, &security_key, 16); memset(security_app_vars.iv, 0, 16); // print dnm_ucli_printf("params:\r\n"); dnm_ucli_printf(" - key: "); printBuf(security_app_vars.key, sizeof(security_app_vars.key)); dnm_ucli_printf(" - iv: "); printBuf(security_app_vars.iv, sizeof(security_app_vars.iv)); // print dnm_ucli_printf("input:\r\n"); dnm_ucli_printf(" - inBuf: "); printBuf(security_app_vars.inBuf, sizeof(security_app_vars.inBuf)); // create MIC dnErr = dn_sec_aesCbcMac( security_app_vars.inBuf, // inBuf sizeof(security_app_vars.inBuf), // len security_app_vars.key, // key security_app_vars.iv, // iv security_app_vars.mic // mic ); ASSERT(dnErr==DN_ERR_NONE); // print dnm_ucli_printf("output:\r\n"); dnm_ucli_printf(" - mic: "); printBuf(security_app_vars.mic, sizeof(security_app_vars.mic)); return DN_ERR_NONE; }
void mmapInterface(int fd, OPERATION opera, int phyAddr, int count) { char *mappedPtr; int pageSize; int *ptr; pageSize = getpagesize(); // Check if Page aligned if (phyAddr & (pageSize - 1)) { printf("phyAddr should be page aligned\n"); return; } mappedPtr = (char*)mmap(NULL, count, PROT_READ | PROT_WRITE, MAP_SHARED, fd, phyAddr); if (*mappedPtr == -1) { lasterror = errno; printf("map /dev/mem failed (%d) - %s\n", lasterror, strerror(lasterror)); } if (opera == R) { printf("PhyAddr %x | mappedAddr %x : ", phyAddr, *mappedPtr); printBuf(mappedPtr, count); } else if (opera == W) { // all set 0x12 int i; char *ptr; ptr = mappedPtr; for (i = 0; i < count; i++) { *ptr++ = 0x12; } } else { printf("Invalid operation\n"); } if (munmap(mappedPtr, count) == -1) { lasterror = errno; printf("unmap mmappedAddr %x of /dev/mem failed (%d) - %s\n", *mappedPtr, lasterror, strerror(lasterror)); } }
void sendbytes(int s, void *buf, ssize_t count) { int stilltosend; for(stilltosend = count; stilltosend > 0; ) { ssize_t sentsize = send(s, (void *)(((unsigned char *)buf) + count - stilltosend), stilltosend, MSG_NOSIGNAL); if(sentsize < 0) { perror("send"); exit(1); } #ifdef _DEBUG_1_ printf("sendbytes():\n"); printBuf((char *)buf + count - stilltosend, sentsize); fflush(stdout); #endif stilltosend -= sentsize; } }
void fileInterface(int fd, OPERATION opera, int phyAddr, int count) { char* buf; ssize_t retSize; buf = (char*)malloc(count); memset(buf, 0, count); lseek(fd, phyAddr, SEEK_SET); if (opera == R) { retSize = read(fd, buf, count); if (retSize < 0) { lasterror = errno; printf("read /dev/mem failed (%d) - %s\n", lasterror, strerror(lasterror)); } else { printBuf(buf, count); } } else if (opera == W) { int i; char *ptr; ptr = buf; for (i = 0; i < count; i++) { *ptr++ = 0x12; } retSize = write(fd, buf, count); if (retSize < 0) { lasterror = errno; printf("write /dev/mem failed (%d) - %s\n", lasterror, strerror(lasterror)); } } else { printf("Invalid operation\n"); } free(buf); }
void onSongMessageCallback() { printBuf(); if (!song.fromSysex(MidiSysex.data, MidiSysex.recordLen)) { fprintf(stderr, "error parsing song\n"); } else { printf("parsed song!\n"); } printf("\n"); if (!inCallback) { inCallback = true; uint16_t len = song.toSysex(sysexBuf, sizeof(sysexBuf)); hexDump(sysexBuf, len); parseSysex(sysexBuf, len); } inCallback = false; }
void onGlobalMessageCallback() { printBuf(); if (!global.fromSysex(MidiSysex.data, MidiSysex.recordLen)) { fprintf(stderr, "error parsing global\n"); } else { printf("parsed global!\n"); } printf("\n"); if (!inCallback) { inCallback = true; uint16_t len = global.toSysex(sysexBuf, sizeof(sysexBuf)); // hexDump(sysexBuf, len); parseSysex(sysexBuf, len); } inCallback = false; }
void recvbytes(int s, void *buf, ssize_t count) { /* Recv until we hit count bytes */ int stillToRecv; for(stillToRecv = count; stillToRecv > 0; ) { ssize_t recvSize = recv(s, (void *)(((unsigned char *)buf) + count - stillToRecv), stillToRecv, 0); if(recvSize <= 0) { perror("recv"); exit(1); } #ifdef _DEBUG_1_ printf("recvbytes():\n"); printBuf((char *)buf + count - stillToRecv, recvSize); fflush(stdout); #endif stillToRecv -= recvSize; } }
void onPatternMessageCallback() { // hexDump(MidiSysex.data, MidiSysex.recordLen); printBuf(); if (!pattern.fromSysex(MidiSysex.data, MidiSysex.recordLen)) { fprintf(stderr, "error parsing pattern\n"); } else { printf("parsed pattern!\n"); pattern.print(); } printf("\n"); if (!inCallback) { inCallback = true; uint16_t len = pattern.toSysex(sysexBuf, sizeof(sysexBuf)); // hexDump(sysexBuf, len); parseSysex(sysexBuf, len); } inCallback = false; }
void PrintKey(PK11SymKey *symKey) { char *name = PK11_GetSymKeyNickname(symKey); int len = PK11_GetKeyLength(symKey); int strength = PK11_GetKeyStrength(symKey, NULL); SECItem *value = NULL; CK_KEY_TYPE type = PK11_GetSymKeyType(symKey); (void) PK11_ExtractKeyValue(symKey); value = PK11_GetKeyData(symKey); printf("%-20s %3d %4d %10s ", name ? name: " ", len, strength, GetStringFromKeyType(type)); if (value && value->data) { printBuf(value->data, value->len); } else { printf("<restricted>"); } printf("\n"); }
int main(int argc, char **argv) { char filename[20]; // device to open int uInput; // user input int pageRWS; // num of pages to read, write char inp[64]; // input from user char *buf; // or set //create the file name according to adapter num snprintf(filename, 19, "/dev/i2c-%d", ADAPT_NUMB); //first we open the device and verify that it was //opened correctly fd = open(filename, O_RDWR); if (fd < 0) { printf("\n%s could not be opened, or was not found\n", filename); exit(1); } //set slave address, check for errors if (ioctl(fd, I2C_SLAVE, SLAVE_ADDR) < 0) { printf("\n%d address not found.\n"); exit(1); } //do some reading or writing do { printf("\n1.Read\n2.Write\n3.Set\n4.Quit\n"); scanf("%d", &uInput); switch(uInput) { case 1 : printf("\nRead Statement\n"); printf("\nHow many pages to read?\n"); scanf("%d", &pageRWS); buf = malloc(sizeof(char) * PAGE_BYTES * pageRWS); memset(buf, 0, sizeof(char) * 64 * pageRWS); read_EEPROM(buf, pageRWS); printBuf(buf, PAGE_BYTES * pageRWS, PAGE_BYTES); free(buf); break; case 2 : printf("\nWrite Statement\n"); printf("\nHow many pages to write?\n"); scanf("%d", &pageRWS); buf = malloc((sizeof(char) * PAGE_BYTES * pageRWS)); memset(buf, 0, sizeof(char) * 64 * pageRWS); printf("\nData to write:\n"); scanf("%s", buf); write_EEPROM(buf, pageRWS); free(buf); break; case 3 : printf("\nSet Statement\n"); printf("\nNew device offset?\n"); scanf("%d", &pageRWS); seek_EEPROM(pageRWS); break; case 4 : printf("\nQuit\n"); break; default: printf("\nUnknown Command\n"); break; } } while (uInput != 4); close(fd); return 0; }
int printBuf_l(long data, unsigned char base) { char buf[33]; printNumber(buf,data,base); return printBuf(buf); }
bool trpgPrintArchive(trpgr_Archive *archive,trpgPrintBuffer &pBuf,int flags) { char ls[1024]; if (!archive->isValid()) return false; pBuf.prnLine("====Header Structures===="); // Print out the header portion archive->GetHeader()->Print(pBuf); archive->GetMaterialTable()->Print(pBuf); archive->GetTexTable()->Print(pBuf); archive->GetModelTable()->Print(pBuf); archive->GetTileTable()->Print(pBuf); archive->GetLightTable()->Print(pBuf); archive->GetRangeTable()->Print(pBuf); archive->GetTextStyleTable()->Print(pBuf); archive->GetSupportStyleTable()->Print(pBuf); archive->GetLabelPropertyTable()->Print(pBuf); pBuf.prnLine(); // Read the local images and do the math for the templates // Now do the tiles if (!archive->isValid()) return false; int majorVersion, minorVersion; archive->GetHeader()->GetVersion(majorVersion, minorVersion); // Parser that prints out a tile scene graph trpgrImageHelper* imageHelp=archive->GetNewRImageHelper(archive->GetEndian(),archive->getDir(), *archive->GetMaterialTable(),*archive->GetTexTable()); trpgPrintGraphParser parser(archive,imageHelp,&pBuf); pBuf.prnLine("====Tile Data===="); int nl,x,y; trpgMemReadBuffer buf(archive->GetEndian()); // Iterate over the terrain lods int numLod; archive->GetHeader()->GetNumLods(numLod); trpg2iPoint tileSize; if(majorVersion == 2 && minorVersion >= 1) { // Version 2.1 // Because of variable lod support in version 2.1 and over, we can // no longer suppose that all lod level are all populated with tiles // in all of the gaming area. We have to parse the parent to know that. // Also the tile table only contains lod 0 tiles so we can no longer access // the tile directly from its grid location. So we have to traverse. trpg2iPoint blockTileSize; if(archive->GetHeader()->GetLodSize(0,blockTileSize)) { for(x = 0; x < blockTileSize.x; x++) for( y = 0; y < blockTileSize.y; y++) if (archive->ReadTile(x,y,0,buf)) printBuf(0, x, y, archive, parser, buf, pBuf); } } else { for (nl=0;nl<numLod;nl++) { archive->GetHeader()->GetLodSize(nl,tileSize); // Iterate over the tiles for (x=tileSize.x-1;x>=0;x--) for (y=0;y<tileSize.y;y++) { sprintf(ls,"Tile (lod) (x,y) = (%d) (%d,%d)",nl,x,y); pBuf.prnLine(ls); if (archive->ReadTile(x,y,nl,buf)) { if (flags & TRPGPRN_BODY) { pBuf.IncreaseIndent(); // Parse it (also prints it if (!parser.Parse(buf)) { char errString[80]; sprintf(errString, "**** Warning: tile anomaly detected: (%d) (%d,%d) ****",nl,x,y); // send it both ways so it's easier to spot pBuf.prnLine(errString); fprintf(stderr,"%s\n",errString); } pBuf.DecreaseIndent(); } } else pBuf.prnLine(" Couldn't read tile."); } } } return true; }
int printBuf_d(double data, unsigned char digit) { char buf[33]; printFloat(buf,data,digit); return printBuf(buf); }
int printBuf_f(float data, unsigned char digit) { char buf[33]; printFloat(buf,(double)data,digit); return printBuf(buf); }