static int brl_construct (BrailleDisplay *brl, char **parameters, const char *device) { if (!isSerialDevice(&device)) { unsupportedDevice(device); return 0; } if ((serialDevice = serialOpenDevice(device))) { if (serialRestartDevice(serialDevice, serialBaud)) { static const unsigned char request[] = {BNO_DESCRIBE}; charactersPerSecond = serialBaud / 10; if (writePacket(brl, request, sizeof(request)) != -1) { while (serialAwaitInput(serialDevice, 100)) { ResponsePacket response; int size = getPacket(&response); if (size) { if (response.data.code == BNI_DESCRIBE) { statusCells = response.data.values.description.statusCells; brl->textColumns = response.data.values.description.textCells; brl->textRows = 1; brl->keyBindings = "keys"; if ((statusCells == 5) && (brl->textColumns == 30)) { statusCells -= 2; brl->textColumns += 2; } dataCells = brl->textColumns * brl->textRows; cellCount = statusCells + dataCells; makeOutputTable(dotsTable_ISO11548_1); makeInputTable(); if ((cellBuffer = malloc(cellCount))) { memset(cellBuffer, 0, cellCount); statusArea = cellBuffer; dataArea = statusArea + statusCells; refreshCells(brl); persistentKeyboardMode = KBM_NAVIGATE; temporaryKeyboardMode = persistentKeyboardMode; persistentRoutingOperation = BRL_BLK_ROUTE; temporaryRoutingOperation = persistentRoutingOperation; return 1; } else { logSystemError("cell buffer allocation"); } } else { logUnexpectedPacket(response.bytes, size); } } } } } serialCloseDevice(serialDevice); serialDevice = NULL; } return 0; }
void Driver::cleanComChannel() { try { writePacket(reinterpret_cast<uint8_t const*>("\r"), 1, 100); readConfigurationAck(); } catch (std::runtime_error e) {} }
bool SeaNet::isFullDuplex(int timeout) { std::vector<uint8_t> packet = SeaNetPacket::createPaket(device_type,mtSendBBUser); writePacket(&packet[0],packet.size()); waitForPacket(mtBBUserData,timeout); BBUserData settings; sea_net_packet.decodeBBUserData(settings); return settings.full_duplex; }
void DebugNet::writeBreakpointHit(uint32_t coreId, uint32_t userData) { auto pak = new DebugPacketBpHit(); pak->coreId = coreId; pak->userData = userData; populateDebugPauseInfo(pak->info); writePacket(pak); }
void SeaNet::getVersion(VersionData &version,int timeout) { std::vector<uint8_t> send_packet = SeaNetPacket::createPaket(device_type,mtSendVersion); writePacket(&send_packet[0],send_packet.size()); //wait until we received a mtVersionData package waitForPacket(mtVersionData,timeout); sea_net_packet.decodeVersionData(version); }
static void loopTruthTable(TruthTable truthset[]) { for(int i = 0; truthset[i].packet != NULL; i++) { writePacket(&truthset[i]); } }
void secPack(int fd, void *secpack) { LOG(LOGLEVEL_INFO, "Sending secpack...\n"); writePacket(fd, 0x204, secpack, 0x800); char buffer[PACKET_SIZE(SECPACK_REPLY_PACKET_SIZE)]; size_t rlength = readPacket(fd, WRITE_TIMEOUT, buffer, sizeof(buffer)); SecpackReplyPacket *reply = verifyPacket(buffer, rlength); LOG(LOGLEVEL_DEBUG, "Secpack returns: unknown1=%d unknown2=0x%x\n", reply ? reply->unknown1 : 0, reply ? reply->unknown2 : 0); }
void seekBaseband(int fd, unsigned int offset) { LOG(LOGLEVEL_INFO, "Seeking to 0x%08x...\n", offset); writePacket(fd, 0x802, &offset, sizeof(offset)); char buffer[PACKET_SIZE(SEEK_REPLY_PACKET_SIZE)]; size_t length = readPacket(fd, DEFAULT_TIMEOUT, buffer, sizeof(buffer)); LOG(LOGLEVEL_DEBUG, "Seek returns:\n"); LOGDO(LOGLEVEL_DEBUG, printBuffer(verifyPacket(buffer, length), SEEK_REPLY_PACKET_SIZE)); }
void resume() { assert(paused); paused = false; ZhttpResponsePacket p; p.type = ZhttpResponsePacket::KeepAlive; writePacket(p); }
// Send a Midi PROGRAM CHANGE message to given channel, with program ID 0-127 void USBMidi::sendProgramChange(unsigned int channel, unsigned int program) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_PROGRAM_CHANGE; outPacket.p.midi0=MIDIv1_PROGRAM_CHANGE |(channel & 0x0f); outPacket.p.midi1=program; writePacket(outPacket.i); }
// Returns a packet read from the serial connection ARCPOPacket& readPacket(ARCPOPacket& pPacket) { char vReadChar; boolean vStarterRead = false; mPacketRead = false; if (Serial.available() > 0) { //wait to make sure everything will be there //at 9600 bps, one need (1/9600) * 8 bits * 64 byte = 0.053 sec. We wait 0.1 sec to be sure. delay(100); while(Serial.available() > 0) { vReadChar = Serial.read(); //search the start if (vReadChar == '$') { vStarterRead = true; } else { //confirm the start if (vStarterRead && vReadChar == '*') { vStarterRead = false; pPacket = readPacketInternal(pPacket); mPacketRead = true; } else { //crap in the buffer, clean until next starter or empty vStarterRead = false; } } } } #ifdef ARCPO_Lib_DEBUGMODE else { Serial.print ("DBG: readPacket : no data => "); Serial.println ((int)Serial.available()); } #endif if (mPacketRead && pPacket.ExpectAcknowledge == 1) { #ifdef ARCPO_Lib_DEBUGMODE Serial.print ("Acknowledgement -->"); #endif //acknowledge packet ARCPOPacket vPacketAck; vPacketAck.ID = pPacket.ID; vPacketAck.Type = 255; vPacketAck.SubType = 255; vPacketAck.ExpectAcknowledge = 255; vPacketAck.Content[0] = 'A'; vPacketAck.Content[1] = 'C'; vPacketAck.Content[2] = 'K'; vPacketAck.Content[3] = 0; writePacket(vPacketAck); } return pPacket; }
// Send a Midi SONG SELECT message, with a song ID of 0-127 (always for all channels) void USBMidi::sendSongSelect(unsigned int song) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_2BYTE_SYS_COMMON; outPacket.p.midi0=MIDIv1_SONG_SELECT; outPacket.p.midi1= (uint8) song & 0x07F; writePacket(outPacket.i); }
void pause() { assert(!doReq); pausing = true; ZhttpResponsePacket p; p.type = ZhttpResponsePacket::HandoffStart; writePacket(p); }
// Send a Midi AFTER TOUCH message to given channel, with velocity 0-127 void USBMidi::sendAfterTouch(unsigned int channel, unsigned int velocity) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_CHANNEL_PRESSURE; outPacket.p.midi0=MIDIv1_CHANNEL_PRESSURE |(channel & 0x0f); outPacket.p.midi1=velocity; writePacket(outPacket.i); }
/* * Acknowledge a received packet */ static void ackPacket(uint8_t ack /* ack return value */ ) { gPacket.data[PACKET_DESTINATION] = gPacket.data[PACKET_SOURCE]; gPacket.data[PACKET_SOURCE] = gPacket.myAddr; gPacket.data[PACKET_COMMAND] = ack; gPacket.length = 6; writePacket(); }
static int writeLocation (BrailleDisplay *brl) { unsigned char packet[2]; unsigned char *byte = packet; *byte++ = statusCells[gscScreenCursorRow]; *byte++ = statusCells[gscScreenCursorColumn]; return writePacket(brl, packet, byte-packet); }
// Send a Midi VELOCITY CHANGE message to a given channel, with given note 0-127, // and new velocity 0-127 // Note velocity change == polyphonic aftertouch. // Note aftertouch == channel pressure. void USBMidi::sendVelocityChange(unsigned int channel, unsigned int note, unsigned int velocity) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_AFTER_TOUCH; outPacket.p.midi0=MIDIv1_AFTER_TOUCH |(channel & 0x0f); outPacket.p.midi1=note; outPacket.p.midi2=velocity; writePacket(outPacket.i); }
void SeaNet::reboot(int timeout) { LOG_DEBUG_S << "rebooting device" ; std::vector<uint8_t> packet = SeaNetPacket::createPaket(device_type,mtReBoot); writePacket(&packet[0],packet.size()); clear(); //now wait for an alive message waitForPacket(mtAlive,timeout); }
void respond() { state = Connected; ZhttpResponsePacket out; out.code = responseCode; out.reason = responseReason; out.headers = responseHeaders; writePacket(out); }
// Send a Midi SONG POSITION message, with a 14-bit position (always for all channels) void USBMidi::sendSongPosition(unsigned int position) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_3BYTE_SYS_COMMON; outPacket.p.midi0=MIDIv1_SONG_POSITION_PTR; outPacket.p.midi1= (uint8) position & 0x07F; outPacket.p.midi2= (uint8) (position<<7) & 0x7f; writePacket(outPacket.i); }
// Send a Midi PITCH CHANGE message, with a 14-bit pitch (always for all channels) void USBMidi::sendPitchChange(unsigned int pitch) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_PITCH_WHEEL; outPacket.p.midi0=MIDIv1_PITCH_WHEEL; outPacket.p.midi1= (uint8) pitch & 0x07F; outPacket.p.midi2= (uint8) (pitch<<7) & 0x7f; writePacket(outPacket.i); }
void endSecPack(int fd) { LOG(LOGLEVEL_INFO, "Ending secpack...\n"); unsigned short unknown = 0; writePacket(fd, 0x205, &unknown, sizeof(unknown)); char buffer[PACKET_SIZE(sizeof(unsigned short))]; size_t rlength = readPacket(fd, DEFAULT_TIMEOUT, buffer, sizeof(buffer)); unsigned short *ret = verifyPacket(buffer, rlength); LOG(LOGLEVEL_DEBUG, "End secpack returns: %d\n", ret ? *ret : 0); }
bool PcapFileWriterDevice::writePackets(const RawPacketVector& packets) { for (RawPacketVector::ConstVectorIterator iter = packets.begin(); iter != packets.end(); iter++) { if (!writePacket(**iter)) return false; } return true; }
// Send a Midi CC message to a given channel, as a given controller 0-127, with given // value 0-127 void USBMidi::sendControlChange(unsigned int channel, unsigned int controller, unsigned int value) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_CONTROL_CHANGE; outPacket.p.midi0=MIDIv1_CONTROL_CHANGE |(channel & 0x0f); outPacket.p.midi1=controller; outPacket.p.midi2=value; writePacket(outPacket.i); }
// Send Midi NOTE ON message to a given channel, with note 0-127 and velocity 0-127 void USBMidi::sendNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) { outPacket.p.cable=DEFAULT_MIDI_CABLE; outPacket.p.cin=CIN_NOTE_ON; outPacket.p.midi0=MIDIv1_NOTE_ON|(channel & 0x0f); outPacket.p.midi1=note; outPacket.p.midi2=velocity; writePacket(outPacket.i); }
static int refreshCells (BrailleDisplay *brl) { unsigned char buffer[1 + cellCount]; unsigned char *byte = buffer; *byte++ = BN_REQ_WRITE; byte = translateOutputCells(byte, cellBuffer, cellCount); return writePacket(brl, buffer, byte-buffer); }
int ModbusClientV1::SetNumberOfBalls(int numOfBalls) { RSPacket::PacketStruct p = { 0 }; fillTheCommonPacketHeader(p, RS_CMD_SET_NUM_OF_BALLS); p.data[0] = numOfBalls; if (writePacket(&p, RS_PACKET_HEADER_SIZE + 2) == (RS_PACKET_HEADER_SIZE + 2)) return 0; return -1; }
void writeBaseband(int fd, void *data, size_t length) { LOG(LOGLEVEL_STATUS, "Writing %lu bytes to flash...\n", length); writePacket(fd, 0x804, data, length); char buffer[PACKET_SIZE(sizeof(unsigned short))]; size_t rlength = readPacket(fd, WRITE_TIMEOUT, buffer, sizeof(buffer)); unsigned short *ret = verifyPacket(buffer, rlength); if (ret && *ret) { LOG(LOGLEVEL_ERROR, "Write returns error: %d\n", *ret); } }
int clientVerifyFile(BIO *conn, char *filename) { //check our records FILERECORD *record = getRecord(filename); if(record == NULL) { fprintf(stderr, "No records stored for %s\n", filename); return -1; } //see if we have an "unused" salt and digest on record int index = record->hashIndex[0]; if(index == NUM_HASHES) { fprintf(stderr, "All stored digests for this file have been consumed.\n"); fprintf(stderr, "Type \"refresh %s\" to download the file and generate new digests.\n", filename); return -1; } unsigned char *hash = record->hashData[index]; unsigned char *salt = hash + HASH_LENGTH; //send the code which triggers the server to call serverVerifyFile() if(writeInt(conn, VERIFY_FILE_CODE) == -1) return -1; //send the filename if(writeString(conn, filename) < 1) return -1; //send the salt if(writePacket(conn, (char *)salt, SALT_LENGTH) < 1) return -1; //wait for the server to indicate if a digest is coming or not int status = readInt(conn); //if the file does not exist if(status == 5) return 5; //if server failed to calculate digest if(status == -1) return -1; //receive the digest char serverHash[MD5_DIGEST_LENGTH]; status = readPacket(conn, serverHash, sizeof(serverHash)); if(status < 1) return -1; //check it against our stored digest if(memcmp(serverHash, hash, sizeof(serverHash)) != 0) { printf("The file digest does not match our records.\n"); } else printf("The file digest matches our records.\n"); ++index; printf("You have consumed %d of %d stored digests.\n", index, NUM_HASHES); //update the hashIndex for this file updateHashIndex(filename, index); return 0; }
static int writeVisualText (BrailleDisplay *brl) { unsigned char bytes[brl->textColumns]; int i; for (i=0; i<brl->textColumns; ++i) { wchar_t character = visualText[i]; bytes[i] = iswLatin1(character)? character: '?'; } return writePacket(brl, 2, bytes, brl->textColumns); }